Thanks for your reply! Unfortunately something is still wrong. After the transpose, dvec and Amat are still incompatible.> d <- -hsmooth > dvec <- t(d) > c <- dvec*AmatError in dvec * Amat : non-conformable arrays Moreover, I don't understand the following:> If dvec is of length *J*, then b will be of length J too.I believe the length of dvec comes from the number of variables and the length of b from the number of constraints. In this case they are not equal. 2018-06-26 15:01 GMT+03:00 Berwin A Turlach <berwin.turlach at gmail.com>:> G'day all, > > On Tue, 26 Jun 2018 11:16:55 +0300 > Maija Sirkj?rvi <maija.sirkjarvi at gmail.com> wrote: > > > It seems that my Amat and dvec are incompatible. Amat is a matrix of > > zeros size: *2*J-3,J* and dvec is a vector of length *J*. There > > should be no problem, but apparently there is. [...] > > solve.QP solves the quadratic program: > min(-d^T b + 1/2 b^T D b) > where A^T b >= b_0. > > Note the transpose. :) > If dvec is of length *J*, then b will be of length J too, and Amat > should be Jx(2J-3) so that its transpose is (2j-3)xJ, making it > compatible for matrix multiplication with b. > > Cheers, > > Berwin > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > >[[alternative HTML version deleted]]
G'day Maija, On Wed, 27 Jun 2018 08:48:08 +0300 Maija Sirkj?rvi <maija.sirkjarvi at gmail.com> wrote:> Thanks for your reply! Unfortunately something is still wrong. > > After the transpose, dvec and Amat are still incompatible. > > > d <- -hsmooth > > dvec <- t(d) > > c <- dvec*Amat > Error in dvec * Amat : non-conformable arrays'*' in R is element-wise multiplication and '%*%' implements matrix/matrix (matrix/vector) multiplication as defined in matrix algebra. I presume you want to use the latter operator here.> Moreover, I don't understand the following: > > > If dvec is of length *J*, then b will be of length J too. > > I believe the length of dvec comes from the number of variables and > the length of b from the number of constraints. In this case they are > not equal.As I said:> > solve.QP solves the quadratic program: > > min(-d^T b + 1/2 b^T D b) > > where A^T b >= b_0.The minimisation is with respect to b. Note that the objective function contains the inner product of d (passed to dvec) and b, so d and b must have the same dimension/length. b contains the parameters/variables over which you want to minimise. b_0 (passed to bvec) depends on the number of constraints. Cheers, Berwin
Thanks a lot! I got the main part working (after a relaxing holiday). However I still have some problems with the conditions. The looping is not working properly, but this is not really an QP problem anymore. It's more about that R runs the loop differently than c++, I guess. Thanks a lot for help! Maija pe 29. kes?k. 2018 klo 13.29 Berwin A Turlach (berwin.turlach at gmail.com) kirjoitti:> G'day Maija, > > On Wed, 27 Jun 2018 08:48:08 +0300 > Maija Sirkj?rvi <maija.sirkjarvi at gmail.com> wrote: > > > Thanks for your reply! Unfortunately something is still wrong. > > > > After the transpose, dvec and Amat are still incompatible. > > > > > d <- -hsmooth > > > dvec <- t(d) > > > c <- dvec*Amat > > Error in dvec * Amat : non-conformable arrays > > '*' in R is element-wise multiplication and '%*%' implements > matrix/matrix (matrix/vector) multiplication as defined in matrix > algebra. I presume you want to use the latter operator here. > > > Moreover, I don't understand the following: > > > > > If dvec is of length *J*, then b will be of length J too. > > > > I believe the length of dvec comes from the number of variables and > > the length of b from the number of constraints. In this case they are > > not equal. > > As I said: > > > > solve.QP solves the quadratic program: > > > min(-d^T b + 1/2 b^T D b) > > > where A^T b >= b_0. > > The minimisation is with respect to b. > > Note that the objective function contains the inner product of d > (passed to dvec) and b, so d and b must have the same > dimension/length. b contains the parameters/variables over which you > want to minimise. b_0 (passed to bvec) depends on the number of > constraints. > > Cheers, > > Berwin >[[alternative HTML version deleted]]