Package quadprogxt. February 4, 2018

Similar documents
Package datasets.load

Package ECctmc. May 1, 2018

Package stapler. November 27, 2017

Package fastdummies. January 8, 2018

Package spark. July 21, 2017

Package CatEncoders. March 8, 2017

Package mixsqp. November 14, 2018

Package SEMrushR. November 3, 2018

Package SAENET. June 4, 2015

Package Rcplex. February 15, 2013

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package sfc. August 29, 2016

Package ECOSolveR. February 18, 2018

Package ADMM. May 29, 2018

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package mmpa. March 22, 2017

Package Rcplex. June 12, 2016

Package wrswor. R topics documented: February 2, Type Package

Package DRaWR. February 5, 2016

Package qap. February 27, Index 5. Solve Quadratic Assignment Problems (QAP)

Package validara. October 19, 2017

Package messaging. May 27, 2018

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package apastyle. March 29, 2017

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package subplex. April 5, 2018

Package mgc. April 13, 2018

Package tropicalsparse

Package fusionclust. September 19, 2017

Package available. November 17, 2017

Package deductive. June 2, 2017

Package comparedf. February 11, 2019

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package inca. February 13, 2018

Package GenSA. R topics documented: January 17, Type Package Title Generalized Simulated Annealing Version 1.1.

Package ompr. November 18, 2017

Package hyphenatr. August 29, 2016

Package estprod. May 2, 2018

Package bisect. April 16, 2018

Package repec. August 31, 2018

Package ecoseries. R topics documented: September 27, 2017

Package ASICS. January 23, 2018

Package robustreg. R topics documented: April 27, Version Date Title Robust Regression Functions

Package exporkit. R topics documented: May 5, Type Package Title Expokit in R Version Date

Package canvasxpress

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package RSpectra. May 23, 2018

Package DCD. September 12, 2017

Package pkgbuild. October 16, 2018

Package nngeo. September 29, 2018

Package kirby21.base

Package weco. May 4, 2018

Package TVsMiss. April 5, 2018

Package geogrid. August 19, 2018

Package mdftracks. February 6, 2017

Package flsa. February 19, 2015

Package nsprcomp. August 29, 2016

Package raker. October 10, 2017

Package WordR. September 7, 2017

Package crossword.r. January 19, 2018

Package zoomgrid. January 3, 2019

Package sessioninfo. June 21, 2017

Package ether. September 22, 2018

Package regexselect. R topics documented: September 22, Version Date Title Regular Expressions in 'shiny' Select Lists

Package shinyfeedback

Package rprojroot. January 3, Title Finding Files in Project Subdirectories Version 1.3-2

Package RCA. R topics documented: February 29, 2016

Package dbx. July 5, 2018

Package birtr. October 4, 2017

Package strat. November 23, 2016

Package clipr. June 23, 2018

Package rhor. July 9, 2018

Package coga. May 8, 2018

Package readobj. November 2, 2017

Package projector. February 27, 2018

Package jdx. R topics documented: January 9, Type Package Title 'Java' Data Exchange for 'R' and 'rjava'

Package coda.base. August 6, 2018

Package slickr. March 6, 2018

Package hsiccca. February 20, 2015

Package diffusr. May 17, 2018

Package rmatio. July 28, 2017

Package crochet. January 8, 2018

Package hiernet. March 18, 2018

Package waver. January 29, 2018

Package rmi. R topics documented: August 2, Title Mutual Information Estimators Version Author Isaac Michaud [cre, aut]

Package widyr. August 14, 2017

Package EvolutionaryGames

Package graphframes. June 21, 2018

Package librarian. R topics documented:

Package elmnnrcpp. July 21, 2018

Package libstabler. June 1, 2017

Package gtrendsr. October 19, 2017

Package splithalf. March 17, 2018

Package IATScore. January 10, 2018

Package knitrprogressbar

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package QCAtools. January 3, 2017

Package jstree. October 24, 2017

Package crossrun. October 8, 2018

Transcription:

Package quadprogxt February 4, 2018 Title Quadratic Programming with Absolute Value Constraints Version 0.0.2 Description Extends the quadprog package to solve quadratic programs with absolute value constraints and absolute values in the objective function. Imports quadprog License GPL (>= 2) Encoding UTF-8 LazyData true Suggests testthat RoxygenNote 6.0.1 NeedsCompilation no Author Bob Harlow [aut, cre] Maintainer Bob Harlow <rharlow86@gmail.com> Repository CRAN Date/Publication 2018-02-04 15:34:24 UTC R topics documented: converttocompact..................................... 2 normalizeconstraints.................................... 2 solveqpxt......................................... 3 Index 6 1

2 normalizeconstraints converttocompact Sparsify constraint matrix Description Sparsify constraint matrix Usage converttocompact(amat) Arguments Amat a constraint matrix as defined in solve.qp Value a list with two elements: Amat and Aind as necessary to be passed to solve.qp.compact See Also quadprog::solve.qp quadprog::solve.qp.compact normalizeconstraints Normalize constraint matrix Description Usage it is not uncommon for quadprog to fail when there are large differences in 2-norm between the columns of the constraint matrix (Amat). It is possible to alleviate this issue in some cases by normalizing the constraints (and their boundaries, defined by bvec). normalizeconstraints(amat, bvec) Arguments Amat bvec constraint matrix as defined by solve.qp constraints as defined by solve.qp Value a list with two elements: Amat and bvec that contain the normalized constraints.

solveqpxt 3 See Also quadprog::solve.qp quadprog::solve.qp.compact solveqpxt Solve a quadratic program with absolute values in constraints & objective Description solveqpxt allows for absolute value constraints and absolute values in the objective. buildqp builds a parameter list that can then be passed to quadprog::solve.qp.compact or quadprog::solve.qp directly if desired by the user. solveqpxt by default implicitly takes advantage of sparsity in the constraint matrix and can improve numerical stability by normalizing the constraint matrix. For the rest of the documentation, assume that Dmat is n x n. The solver solves the following problem (each * corresponds to matrix multiplication): min: -t(dvec) * b + 1/2 t(b) * Dmat * b + -t(dvecposneg) * c(b_positive, b_negative) + -t(dvecposnegdelta) * c(deltab_positive, deltab_negative) s.t. t(amat) * b >= bvec t(amatposneg) * c(b_positive, b_negative) >= bvecposneg t(amatposnegdelta) * c(deltab_positive, deltab_negative) >= bvecposnegdelta b_positive, b_negative >= 0, b = b_positive - b_negative deltab_positive, deltab_negative >= 0, b - b0 = deltab_positive - deltab_negative Usage solveqpxt(...) buildqp(dmat, dvec, Amat, bvec, meq = 0, factorized = FALSE, AmatPosNeg = NULL, bvecposneg = NULL, dvecposneg = NULL, b0 = NULL, AmatPosNegDelta = NULL, bvecposnegdelta = NULL, dvecposnegdelta = NULL, tol = 1e-08, compact = TRUE, normalize = TRUE) Arguments... parameters to pass to buildqp when calling solveqpxt Dmat matrix appearing in the quadratic function to be minimized.

4 solveqpxt dvec Amat bvec meq factorized AmatPosNeg bvecposneg dvecposneg b0 vector appearing in the quadratic function to be minimized. matrix defining the constraints under which we want to minimize the quadratic function. vector holding the values of b 0 (defaults to zero). the first meq constraints are treated as equality constraints, all further as inequality constraints (defaults to 0). logical flag: if TRUE, then we are passing R 1 (where D = R T R) instead of the matrix D in the argument Dmat. k x 2n matrix of constraints on the positive and negative part of b k length vector of thresholds to the constraints in AmatPosNeg k x 2n vector of loadings on the positive and negative part of b, respectively a starting point that describes the current state of the problem such that constraints and penalty on absolute changes in the decision variable from a starting point can be incorporated. b0 is an n x 1 vector. Note that b0 is NOT a starting point for the optimization - that is handled implicitly by quadprog. AmatPosNegDelta l x 2n matrix of constraints on the positive and negative part of a change in b from a starting point, b0. bvecposnegdelta l length vector of thresholds to the constraints in AmatPosNegDelta dvecposnegdelta l x 2n vector of loadings in the objective function on the positive and negative part of changes in b from a starting point of b0. tol compact normalize tolerance along the diagonal of the expanded Dmat for slack variables logical: if TRUE, it is assumed that we want to use solve.qp.compact to solve the problem, which handles sparsity. logical: should constraint matrix be normalized Details In order to handle constraints on b_positive and b_negative, slack variables are introduced. The total number of parameters in the problem increases by the following amounts: If all the new parameters (those not already used by quadprog) remain NULL, the problem size does not increase and quadprog::solve.qp (.compact) is called after normalizing the constraint matrix and converting to a sparse matrix representation by default. If AmatPosNeg, bvecposneg or dvecposneg are not null, the problem size increases by n If AmatPosNegDelta or devecposnegdelta are not null, the problem size increases by n. This results in a potential problem size of up to 3 * n. Despite the potential large increases in problem size, the underlying solver is written in Fortran and converges quickly for problems involving even hundreds of parameters. Additionally, it has been the author s experience that solutions solved via the convex quadprog are much more stable than those solved by other methods (e.g. a non-linear solver). Note that due to the fact that the constraints are by default normalized, the original constraint values the user passed will may not be returned by buildqp.

solveqpxt 5 Examples ##quadprog example" Dmat <- matrix(0,3,3) diag(dmat) <- 1 dvec <- c(0,5,0) Amat <- matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3) bvec <- c(-8,2,0) qp <- quadprog::solve.qp(dmat,dvec,amat,bvec=bvec) qpxt <- solveqpxt(dmat,dvec,amat,bvec=bvec) range(qp$solution - qpxt$solution) N <- 10 set.seed(2) cr <- matrix(runif(n * N, 0,.05), N, N) diag(cr) <- 1 cr <- (cr + t(cr)) / 2 set.seed(3) sigs <- runif(n, min =.02, max =.25) set.seed(5) dvec <- runif(n, -.1,.1) Dmat <- sigs %o% sigs * cr Amat <- cbind(diag(n), diag(n) * -1) bvec <- c(rep(-1, N), rep(-1, N)) resbase <- solveqpxt(dmat, dvec, Amat, bvec) ##absolute value constraint on decision variable: res <- solveqpxt(dmat, dvec, Amat, bvec, AmatPosNeg = matrix(rep(-1, 2 * N)), bvecposneg = -1) sum(abs(res$solution[1:n])) ## penalty of L1 norm resl1penalty <- solveqpxt(dmat, dvec, Amat, bvec, dvecposneg = -.005 * rep(1, 2 * N)) sum(abs(resl1penalty$solution[1:n])) ## constraint on amount decision variable can vary from a starting point b0 <- rep(.15, N) thresh <-.25 res <- solveqpxt(dmat, dvec, Amat, bvec, b0 = b0, AmatPosNegDelta = matrix(rep(-1, 2 * N)), bvecposnegdelta = -thresh) sum(abs(res$solution[1:n] - b0)) ##use buildqp, then call solve.qp.compact directly qp <- buildqp(dmat, dvec, Amat, bvec, b0 = b0, AmatPosNegDelta = matrix(rep(-1, 2 * N)), bvecposnegdelta = -thresh) res2 <- do.call(quadprog::solve.qp.compact, qp) range(res$solution - res2$solution)

Index buildqp (solveqpxt), 3 converttocompact, 2 normalizeconstraints, 2 solveqpxt, 3 6