

Hi!
I have a quadratic optimization problem and I have some difficulties coding
it with R. The math version of the problem looks like this:
min sum(mj mj^)^2 which goes from 1 to J
st.
mj1 <= mj  delta1
1/(Qj1 Qj2)(mj2 mj1) <= 1/(Qj Qj1 ) (mj1  mj) delta2
And I'm coding it like this:
Dmat < matrix(0, J,J)
diag(Dmat) < 1
dvec < hsmooth
Aeq < 0
beq < 0
Amat < matrix(0,2*J3,J)
bvec < rep(0,2*J3)
for(j in 1:J)
{
Amat[j1,j1] = 1
Amat[j1,j] = 1
bvec[j1] = Delta1
}
for(j in 2:J)
{
Amat[J1+j2,j] = 1/ (Q[j]  Q[j1])
Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
Amat[J1+j2,j2]= 1/(Q[j1]  Q[j2])
bvec[J1+j1]= Delta2
}
solution < solve.QP(Dmat, dvec, Amat, bvec)
I get errors:
Error in Amat[J  1 + j  2, j  1] < 1/(Q[j]  Q[j  1]) + 1/(Q[j  :
replacement has length zero
And
Error in solve.QP(Dmat, dvec, Amat, bvec) :
Amat and dvec are incompatible!
I'm not sure what I'm doing wrong here, and I really could use some help
with this. Thanks in advance!
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Keep replies on list please.
You are not accessing a value from vector Q if you access the zero'th element!
R > Q < c(3, 5, 8)
R > Q[0]
numeric(0)
R > Q[1]
[1] 3
R > Q[2]
[1] 5
In the first iteration of the loop j is 2 thus j2 is 0 and that's the reason for the error message: you are trying to replace a matrix element with a zerolength (i.e. unassigned) numeric value. Perhaps, in your mind, you are mixing up the index of a vector element and its value? If you need two zeros to start your vector, do something like
R > Q < c(0, 0, Q)
R > Q
[1] 0 0 3 5 8
Clear now?
B.
> On 20180614, at 01:22, Maija Sirkjärvi < [hidden email]> wrote:
>
> Many thanks for your message!
>
> The thing is that I need Q[j2] to be zero for the first two iterations because I don't have those values (J starts from 1). Do you have any idea how to do it?
>
> Thanks again!
>
> Maija
>
> 20180613 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
> Q[j2] gives you Q[0] in your first inner loop iteration.
> R arrays start at one.
>
> B.
>
>
> > On 20180613, at 07:21, Maija Sirkjärvi < [hidden email]> wrote:
> >
> > Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
>
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks for the reply! I got that figured out, but still have some problems
with the quadratic programming.
It seems that my Amat and dvec are incompatible. Amat is a matrix of zeros
size: *2*J3,J* and dvec is a vector of length *J*. There should be no
problem, but apparently there is. The piece of code looks like this:
Dmat < matrix(0,nrow= J, ncol=J)
diag(Dmat) < 1
dvec < rep(0,J)
dvec
dvec < hsmooth
Aeq < 0
beq < 0
Amat < matrix(0,2*J3,J)
bvec < rep(0,2*J3)
for(j in 2:J)
{
Amat[j1,j1] = 1
Amat[j1,j] = 1
bvec[j1] = Delta1
}
for(j in 3:J)
{
Amat[J1+j2,j] = 1/(Q[j]  Q[j1])
Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
Amat[J1+j2,j2]= 1/(Q[j1]  Q[j2])
bvec[J1+j2]= Delta2
}
solution < solve.QP(Dmat, dvec, Amat, bvec)
20180614 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
> Keep replies on list please.
>
> You are not accessing a value from vector Q if you access the zero'th
> element!
> R > Q < c(3, 5, 8)
> R > Q[0]
> numeric(0)
> R > Q[1]
> [1] 3
> R > Q[2]
> [1] 5
>
> In the first iteration of the loop j is 2 thus j2 is 0 and that's the
> reason for the error message: you are trying to replace a matrix element
> with a zerolength (i.e. unassigned) numeric value. Perhaps, in your mind,
> you are mixing up the index of a vector element and its value? If you need
> two zeros to start your vector, do something like
>
> R > Q < c(0, 0, Q)
> R > Q
> [1] 0 0 3 5 8
>
>
> Clear now?
> B.
>
>
>
> > On 20180614, at 01:22, Maija Sirkjärvi < [hidden email]>
> wrote:
> >
> > Many thanks for your message!
> >
> > The thing is that I need Q[j2] to be zero for the first two iterations
> because I don't have those values (J starts from 1). Do you have any idea
> how to do it?
> >
> > Thanks again!
> >
> > Maija
> >
> > 20180613 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
> > Q[j2] gives you Q[0] in your first inner loop iteration.
> > R arrays start at one.
> >
> > B.
> >
> >
> > > On 20180613, at 07:21, Maija Sirkjärvi < [hidden email]>
> wrote:
> > >
> > > Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
> >
> >
>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


The statement
dvec < hsmooth
looks like it might be the source of the problem, depending on what hsmooth
is.
On Tue, Jun 26, 2018 at 11:16 AM, Maija Sirkjärvi < [hidden email]
> wrote:
> Thanks for the reply! I got that figured out, but still have some problems
> with the quadratic programming.
>
> It seems that my Amat and dvec are incompatible. Amat is a matrix of zeros
> size: *2*J3,J* and dvec is a vector of length *J*. There should be no
> problem, but apparently there is. The piece of code looks like this:
>
> Dmat < matrix(0,nrow= J, ncol=J)
> diag(Dmat) < 1
> dvec < rep(0,J)
> dvec
> dvec < hsmooth
> Aeq < 0
> beq < 0
> Amat < matrix(0,2*J3,J)
> bvec < rep(0,2*J3)
>
> for(j in 2:J)
> {
> Amat[j1,j1] = 1
> Amat[j1,j] = 1
> bvec[j1] = Delta1
> }
>
> for(j in 3:J)
> {
> Amat[J1+j2,j] = 1/(Q[j]  Q[j1])
> Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
> Amat[J1+j2,j2]= 1/(Q[j1]  Q[j2])
> bvec[J1+j2]= Delta2
> }
>
> solution < solve.QP(Dmat, dvec, Amat, bvec)
>
>
> 20180614 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
>
> > Keep replies on list please.
> >
> > You are not accessing a value from vector Q if you access the zero'th
> > element!
> > R > Q < c(3, 5, 8)
> > R > Q[0]
> > numeric(0)
> > R > Q[1]
> > [1] 3
> > R > Q[2]
> > [1] 5
> >
> > In the first iteration of the loop j is 2 thus j2 is 0 and that's the
> > reason for the error message: you are trying to replace a matrix element
> > with a zerolength (i.e. unassigned) numeric value. Perhaps, in your
> mind,
> > you are mixing up the index of a vector element and its value? If you
> need
> > two zeros to start your vector, do something like
> >
> > R > Q < c(0, 0, Q)
> > R > Q
> > [1] 0 0 3 5 8
> >
> >
> > Clear now?
> > B.
> >
> >
> >
> > > On 20180614, at 01:22, Maija Sirkjärvi < [hidden email]>
> > wrote:
> > >
> > > Many thanks for your message!
> > >
> > > The thing is that I need Q[j2] to be zero for the first two
> iterations
> > because I don't have those values (J starts from 1). Do you have any idea
> > how to do it?
> > >
> > > Thanks again!
> > >
> > > Maija
> > >
> > > 20180613 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
> > > Q[j2] gives you Q[0] in your first inner loop iteration.
> > > R arrays start at one.
> > >
> > > B.
> > >
> > >
> > > > On 20180613, at 07:21, Maija Sirkjärvi < [hidden email]>
> > wrote:
> > > >
> > > > Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
> > >
> > >
> >
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/> postingguide.html
> and provide commented, minimal, selfcontained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks for the reply!
dvec, thus hsmooth, has the same length J. It shouldn't be the problem.
20180626 11:24 GMT+03:00 Eric Berger < [hidden email]>:
> The statement
>
> dvec < hsmooth
>
> looks like it might be the source of the problem, depending on what
> hsmooth is.
>
>
> On Tue, Jun 26, 2018 at 11:16 AM, Maija Sirkjärvi <
> [hidden email]> wrote:
>
>> Thanks for the reply! I got that figured out, but still have some problems
>> with the quadratic programming.
>>
>> It seems that my Amat and dvec are incompatible. Amat is a matrix of zeros
>> size: *2*J3,J* and dvec is a vector of length *J*. There should be no
>>
>> problem, but apparently there is. The piece of code looks like this:
>>
>> Dmat < matrix(0,nrow= J, ncol=J)
>> diag(Dmat) < 1
>> dvec < rep(0,J)
>> dvec
>> dvec < hsmooth
>> Aeq < 0
>> beq < 0
>> Amat < matrix(0,2*J3,J)
>> bvec < rep(0,2*J3)
>>
>> for(j in 2:J)
>> {
>> Amat[j1,j1] = 1
>> Amat[j1,j] = 1
>> bvec[j1] = Delta1
>> }
>>
>> for(j in 3:J)
>> {
>> Amat[J1+j2,j] = 1/(Q[j]  Q[j1])
>> Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
>> Amat[J1+j2,j2]= 1/(Q[j1]  Q[j2])
>> bvec[J1+j2]= Delta2
>> }
>>
>> solution < solve.QP(Dmat, dvec, Amat, bvec)
>>
>>
>> 20180614 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
>>
>> > Keep replies on list please.
>> >
>> > You are not accessing a value from vector Q if you access the zero'th
>> > element!
>> > R > Q < c(3, 5, 8)
>> > R > Q[0]
>> > numeric(0)
>> > R > Q[1]
>> > [1] 3
>> > R > Q[2]
>> > [1] 5
>> >
>> > In the first iteration of the loop j is 2 thus j2 is 0 and that's the
>> > reason for the error message: you are trying to replace a matrix element
>> > with a zerolength (i.e. unassigned) numeric value. Perhaps, in your
>> mind,
>> > you are mixing up the index of a vector element and its value? If you
>> need
>> > two zeros to start your vector, do something like
>> >
>> > R > Q < c(0, 0, Q)
>> > R > Q
>> > [1] 0 0 3 5 8
>> >
>> >
>> > Clear now?
>> > B.
>> >
>> >
>> >
>> > > On 20180614, at 01:22, Maija Sirkjärvi < [hidden email]>
>> > wrote:
>> > >
>> > > Many thanks for your message!
>> > >
>> > > The thing is that I need Q[j2] to be zero for the first two
>> iterations
>> > because I don't have those values (J starts from 1). Do you have any
>> idea
>> > how to do it?
>> > >
>> > > Thanks again!
>> > >
>> > > Maija
>> > >
>> > > 20180613 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
>> > > Q[j2] gives you Q[0] in your first inner loop iteration.
>> > > R arrays start at one.
>> > >
>> > > B.
>> > >
>> > >
>> > > > On 20180613, at 07:21, Maija Sirkjärvi < [hidden email]
>> >
>> > wrote:
>> > > >
>> > > > Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
>> > >
>> > >
>> >
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/posti>> ngguide.html
>> and provide commented, minimal, selfcontained, reproducible code.
>>
>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


G'day all,
On Tue, 26 Jun 2018 11:16:55 +0300
Maija Sirkjärvi < [hidden email]> wrote:
> It seems that my Amat and dvec are incompatible. Amat is a matrix of
> zeros size: *2*J3,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(2J3) so that its transpose is (2j3)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______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


The recommended (see the Posting Guide) way to resolve questions like this is to post a reproducible example so we can see the problem occur in our R session. There are a number of Internet resources that can help you get this right such as [1][2][3].
Note that one key to success is to learn how to configure your email program send plain text formatted email, since the mailing list will strip the HTML formatting anyway but this often leaves extraneous characters that make no sense to R. Most email attachments are removed, so keep including the code in the email body as you have been.
[1] http://stackoverflow.com/questions/5963269/howtomakeagreatrreproducibleexample[2] http://advr.had.co.nz/Reproducibility.html[3] https://cran.rproject.org/web/packages/reprex/index.html (read the vignette)
On June 26, 2018 1:34:31 AM PDT, "Maija Sirkjärvi" < [hidden email]> wrote:
>Thanks for the reply!
>
>dvec, thus hsmooth, has the same length J. It shouldn't be the problem.
>
>20180626 11:24 GMT+03:00 Eric Berger < [hidden email]>:
>
>> The statement
>>
>> dvec < hsmooth
>>
>> looks like it might be the source of the problem, depending on what
>> hsmooth is.
>>
>>
>> On Tue, Jun 26, 2018 at 11:16 AM, Maija Sirkjärvi <
>> [hidden email]> wrote:
>>
>>> Thanks for the reply! I got that figured out, but still have some
>problems
>>> with the quadratic programming.
>>>
>>> It seems that my Amat and dvec are incompatible. Amat is a matrix of
>zeros
>>> size: *2*J3,J* and dvec is a vector of length *J*. There should be
>no
>>>
>>> problem, but apparently there is. The piece of code looks like this:
>>>
>>> Dmat < matrix(0,nrow= J, ncol=J)
>>> diag(Dmat) < 1
>>> dvec < rep(0,J)
>>> dvec
>>> dvec < hsmooth
>>> Aeq < 0
>>> beq < 0
>>> Amat < matrix(0,2*J3,J)
>>> bvec < rep(0,2*J3)
>>>
>>> for(j in 2:J)
>>> {
>>> Amat[j1,j1] = 1
>>> Amat[j1,j] = 1
>>> bvec[j1] = Delta1
>>> }
>>>
>>> for(j in 3:J)
>>> {
>>> Amat[J1+j2,j] = 1/(Q[j]  Q[j1])
>>> Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
>>> Amat[J1+j2,j2]= 1/(Q[j1]  Q[j2])
>>> bvec[J1+j2]= Delta2
>>> }
>>>
>>> solution < solve.QP(Dmat, dvec, Amat, bvec)
>>>
>>>
>>> 20180614 15:52 GMT+03:00 Boris Steipe < [hidden email]>:
>>>
>>> > Keep replies on list please.
>>> >
>>> > You are not accessing a value from vector Q if you access the
>zero'th
>>> > element!
>>> > R > Q < c(3, 5, 8)
>>> > R > Q[0]
>>> > numeric(0)
>>> > R > Q[1]
>>> > [1] 3
>>> > R > Q[2]
>>> > [1] 5
>>> >
>>> > In the first iteration of the loop j is 2 thus j2 is 0 and that's
>the
>>> > reason for the error message: you are trying to replace a matrix
>element
>>> > with a zerolength (i.e. unassigned) numeric value. Perhaps, in
>your
>>> mind,
>>> > you are mixing up the index of a vector element and its value? If
>you
>>> need
>>> > two zeros to start your vector, do something like
>>> >
>>> > R > Q < c(0, 0, Q)
>>> > R > Q
>>> > [1] 0 0 3 5 8
>>> >
>>> >
>>> > Clear now?
>>> > B.
>>> >
>>> >
>>> >
>>> > > On 20180614, at 01:22, Maija Sirkjärvi
>< [hidden email]>
>>> > wrote:
>>> > >
>>> > > Many thanks for your message!
>>> > >
>>> > > The thing is that I need Q[j2] to be zero for the first two
>>> iterations
>>> > because I don't have those values (J starts from 1). Do you have
>any
>>> idea
>>> > how to do it?
>>> > >
>>> > > Thanks again!
>>> > >
>>> > > Maija
>>> > >
>>> > > 20180613 15:52 GMT+03:00 Boris Steipe
>< [hidden email]>:
>>> > > Q[j2] gives you Q[0] in your first inner loop iteration.
>>> > > R arrays start at one.
>>> > >
>>> > > B.
>>> > >
>>> > >
>>> > > > On 20180613, at 07:21, Maija Sirkjärvi
>< [hidden email]
>>> >
>>> > wrote:
>>> > > >
>>> > > > Amat[J1+j2,j1]= 1/(Q[j]  Q[j1]) + 1/(Q[j1]  Q[j2])
>>> > >
>>> > >
>>> >
>>> >
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/rhelp>>> PLEASE do read the posting guide http://www.Rproject.org/posti>>> ngguide.html
>>> and provide commented, minimal, selfcontained, reproducible code.
>>>
>>
>>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp>PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html>and provide commented, minimal, selfcontained, reproducible code.

Sent from my phone. Please excuse my brevity.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


sos::findFn('{quadratic programming}') just identified 156 help
pages in 68 packages containing the term "quadratic programming". The
function mentioned by Berwin Turlach, "solve.QP", is in package
"quadprog", which has not been updated since 20161220. I've used
qudprod successfully, but you might wish to consider some of the other
options in package(s) more actively maintained.
The "print" method for sos::findFn('{quadratic programming}')
produced two sheets in my default browser. The first of these contained
156 rows for the 156 help pages in 68 packages, sorted by default by
c('Count', 'MaxScore', 'TotalScore', 'Package', 'Score', 'Function').
The second sheet listed only the 68 packages sorted by c('Count',
'MaxScore', 'TotalScore', 'Package'). You can click on the column
headers to get them sorted in different orders, if you want.
"sos::findFn" is for me the fastest literature search for
anything statistical. I often write the list of help pages and the
package summary to an Excel file using the "writeFindFn2xls" function,
then annotate the package summary with other information to help me
decide which package(s) and function(s) to try.
Hope this helps.
Spencer Graves, lead author of "sos"
On 20180626 07:01, Berwin A Turlach wrote:
> G'day all,
>
> On Tue, 26 Jun 2018 11:16:55 +0300
> Maija Sirkjärvi < [hidden email]> wrote:
>
>> It seems that my Amat and dvec are incompatible. Amat is a matrix of
>> zeros size: *2*J3,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(2J3) so that its transpose is (2j3)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>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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 : nonconformable 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.
20180626 15:01 GMT+03:00 Berwin A Turlach < [hidden email]>:
> G'day all,
>
> On Tue, 26 Jun 2018 11:16:55 +0300
> Maija Sirkjärvi < [hidden email]> wrote:
>
> > It seems that my Amat and dvec are incompatible. Amat is a matrix of
> > zeros size: *2*J3,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(2J3) so that its transpose is (2j3)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]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


G'day Maija,
On Wed, 27 Jun 2018 08:48:08 +0300
Maija Sirkjärvi < [hidden email]> 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 : nonconformable arrays
'*' in R is elementwise 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
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


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 ( [hidden email])
kirjoitti:
> G'day Maija,
>
> On Wed, 27 Jun 2018 08:48:08 +0300
> Maija Sirkjärvi < [hidden email]> 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 : nonconformable arrays
>
> '*' in R is elementwise 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]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

