Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/testthat/test-rlim.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ test_that("rlim() works as expected for LIM object", {
# Check type is correct
expect_type(samp, "double")

# Check if every point lies within the polytope i.e satistifies both equalities and inequalities

## Check if every point satisfies all the equalities
eq_lin_combs <- BOWF$A %*% t(samp)
apply(eq_lin_combs, 2, function(col) {
expect_equal(col, BOWF$B)
})

## Check if every point satisfies all the inequalities
ineq_lin_combs <- BOWF$G %*% t(samp)
apply(ineq_lin_combs, 2, function(col) {
expect_true(all(col >= BOWF$H))
})

# Check if every points are within the ranges
ranges <- lim.ranges(BOWF)
result <- apply(samp, 1, is_within_range, ranges=ranges)
Expand Down
40 changes: 20 additions & 20 deletions vignettes/high_dimensional_polytope_sampling_with_samplelim.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ For the mere aim of illustration, we will consider in the following the minimal

$$\begin{cases}
1x_1 + 1x_2 + 1x_3 = 1 \\
0x_1 + 0x_2 + 1x_3 \geq 0.7 \\
0x_1 + 0x_2 - 1x_3 \geq 0 \\
0x_1 + 1x_2 + 0x_3 \geq 0.8 \\
0x_1 - 1x_2 + 0x_3 \geq 0 \\
1x_1 + 0x_2 + 0x_3 \geq 0.8 \\
-1x_1 + 0x_2 + 0x_3 \geq 0 \\
0x_1 + 0x_2 - 1x_3 \geq -0.7 \\
0x_1 + 0x_2 + 1x_3 \geq 0 \\
0x_1 - 1x_2 + 0x_3 \geq -0.8 \\
0x_1 + 1x_2 + 0x_3 \geq 0 \\
- 1x_1 + 0x_2 + 0x_3 \geq -0.8 \\
1x_1 + 0x_2 + 0x_3 \geq 0 \\
\end{cases}$$

with associated matrices $$
Expand All @@ -87,19 +87,19 @@ with associated matrices $$
1
\end{pmatrix}, \quad
\mathbf{G} = \begin{pmatrix}
0 & 0 & 1 \\
0 & 0 & -1 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
0 & -1 & 0 \\
1 & 0 & 0 \\
-1 & 0 &0
0 & 1 & 0 \\
-1 & 0 & 0 \\
1 & 0 &0
\end{pmatrix},\quad
\mathbf{H} = \begin{pmatrix}
0.7 \\
-0.7 \\
0 \\
0.8 \\
-0.8 \\
0 \\
0.8 \\
-0.8 \\
0
\end{pmatrix}$$.

Expand All @@ -110,15 +110,15 @@ library("samplelim")
# Define equality and inequality constraints through matrices A, B, G, H
A <- matrix(c(1, 1, 1), nrow = 1, ncol = 3)
B <- 1
G <- -matrix(c(0, 0, 1,
0, 0, -1,
0, 1, 0,
0, -1, 0,
1, 0, 0,
-1, 0, 0),
G <- matrix(c(0, 0, -1,
0, 0, 1,
0, -1, 0,
0, 1, 0,
-1, 0, 0,
1, 0, 0),
byrow = TRUE,
nrow = 6, ncol = 3)
H <- -matrix(c(0.7, 0, 0.8, 0, 0.8, 0), nrow = 6)
H <- matrix(c(-0.7, 0, -0.8, 0, -0.8, 0), nrow = 6)
# Store into a list
lim_exm <- list(A = A, B = B,G = G,H = H)
# Sampling into the polytope defined by these constraints
Expand Down