View source: R/transformSimplex.R
solution.basis | R Documentation |
Given a set of linear equality constraints, determine a translation and a basis for its solution space.
solution.basis(constr)
constr |
Linear equality constraints |
For a system of linear equations, Ax = b, the solution space is given by
x = A'b + (I - A' A)
where A' is the Moore-Penrose pseudoinverse of A. The QR decomposition of I - A'A enables us to determine the dimension of the solution space and derive a basis for that space.
A list, consisting of
translate |
A point in the solution space |
basis |
A basis rooted in that point |
Gert van Valkenhoef
createTransform
# A 3-dimensional original space n <- 3 # x_1 + x_2 + x_3 = 1 eq.constr <- list(constr = t(rep(1, n)), dir = '=', rhs = 1) basis <- solution.basis(eq.constr) stopifnot(ncol(basis$basis) == 2) # Dimension reduced to 2 y <- rbind(rnorm(100, 0, 100), rnorm(100, 0, 100)) x <- basis$basis %*% y + basis$translate stopifnot(all.equal(apply(x, 2, sum), rep(1, 100))) # 2 x_2 = x_1; 2 x_3 = x_2 eq.constr <- mergeConstraints( eq.constr, list(constr = c(-1, 2, 0), dir = '=', rhs = 0), list(constr = c(0, -1, 2), dir = '=', rhs = 0)) basis <- solution.basis(eq.constr) stopifnot(ncol(basis$basis) == 0) # Dimension reduced to 0 stopifnot(all.equal(basis$translate, c(4/7, 2/7, 1/7)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.