| harConstraints | R Documentation |
These utility functions generate linear constraints
simplexConstraints(n) lowerBoundConstraint(n, i, x) upperBoundConstraint(n, i, x) lowerRatioConstraint(n, i, j, x) upperRatioConstraint(n, i, j, x) exactRatioConstraint(n, i, j, x) ordinalConstraint(n, i, j) mergeConstraints(...)
n |
Number of dimensions (vector components) |
i |
Index of first component |
j |
Index of second component |
x |
Scalar bound |
... |
Constraint definitions, or a single list of constraint definitions |
See har for a description of the constraint format.
simplexConstraints encodes the n-simplex: all k: w_k >= 0 and sum_k(w_k) = 1
lowerBoundConstraint encodes w_i >= x
upperBoundConstraint encodes w_i <= x
lowerRatioConstraint encodes w_i / w_j >= x
upperRatioConstraint encodes w_i / w_j <= x
exactRatioConstraint encodes w_i / w_j = x
ordinalConstraint encodes w_i >= w_j
mergeConstraints merges the constraints it is given. Alternatively, the function takes a single list of constraint definitions which are to be merged.
A constraint definition (concatenation of the given constraint definitions).
Gert van Valkenhoef
eliminateRedundant
hitandrun
har
# create an ordinal constraint
c1 <- ordinalConstraint(2, 1, 2)
stopifnot(c1$constr == c(-1, 1))
stopifnot(c1$rhs == c(0))
stopifnot(c1$dir == c("<="))
# create our own constraints
c2 <- list(constr=t(c(-1, 0)), rhs=c(0), dir=c("<="))
c3 <- list(constr=t(c(1, 1)), rhs=c(1), dir=c("<="))
# merge the constraints into a single definition
c <- mergeConstraints(c1, c2, c3)
stopifnot(c$constr == rbind(c(-1, 1), c(-1, 0), c(1, 1)))
stopifnot(c$rhs == c(0, 0, 1))
stopifnot(c$dir == c("<=", "<=", "<="))
# test the alternative (list) method
l <- mergeConstraints(list(c1, c2, c3))
stopifnot(c$constr == l$constr)
stopifnot(c$rhs == l$rhs)
stopifnot(c$dir == l$dir)
# test iteratively merging
l <- mergeConstraints(mergeConstraints(c1, c2), c3)
stopifnot(c$constr == l$constr)
stopifnot(c$rhs == l$rhs)
stopifnot(c$dir == l$dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.