Quantcast

glpk problem,please check code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

glpk problem,please check code

saiko7
function [alpha]=mclp(B,c,d);

a=B(:,1:29);
r=size(a,1);
c=size(a,2);
Q=gallery("lehmer",r);Q2=[Q zeros(r,r);zeros(r,r) zeros(r,r)];
alpha=zeros(r,1);
e=ones(r,1);e2=[e;zeros(r,1)];
u=zeros(r,1);u2=[u;zeros(r,1)];
v=zeros(r,1);v2=[v;zeros(r,1)];
y=B(:,30);
p=sum(y==0);q=sum(y==1);

E=[eye(q,q) zeros(q,p);zeros(p,q) -eye(p,p)];E2=[E zeros(r,r);zeros(r,r) zeros(r,r)];
alpha=zeros(r,1);
b=a*a'+e*e';
H=[b zeros(r,r);zeros(r,r) Q];
alpha2=[alpha;u];alpha2(1,1)=0.000000001;

[alpha2 obj inf]=qp(alpha2,H,zeros(2*r,1),[],[],[],[],(-Q2*u2)-(d*e2),E2,-c*e2);



ihave checked the dimensions of the matrices invoved ,but keep getting the message
mclp(a,3,1)
error: glpk: A must be a real valued 8 by 12 matrix
error: called from
    glpk at line 506 column 5
    qp at line 370 column 29
    mclp at line 20 column 16

where a is a 4*30 matrix
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

bpabbott
Administrator
> On Feb 12, 2017, at 10:54 AM, saiko7 <[hidden email]> wrote:
>
> function [alpha]=mclp(B,c,d);
>
> a=B(:,1:29);
> r=size(a,1);
> c=size(a,2);
> Q=gallery("lehmer",r);Q2=[Q zeros(r,r);zeros(r,r) zeros(r,r)];
> alpha=zeros(r,1);
> e=ones(r,1);e2=[e;zeros(r,1)];
> u=zeros(r,1);u2=[u;zeros(r,1)];
> v=zeros(r,1);v2=[v;zeros(r,1)];
> y=B(:,30);
> p=sum(y==0);q=sum(y==1);
>
> E=[eye(q,q) zeros(q,p);zeros(p,q) -eye(p,p)];E2=[E zeros(r,r);zeros(r,r)
> zeros(r,r)];
> alpha=zeros(r,1);
> b=a*a'+e*e';
> H=[b zeros(r,r);zeros(r,r) Q];
> alpha2=[alpha;u];alpha2(1,1)=0.000000001;
>
> [alpha2 obj
> inf]=qp(alpha2,H,zeros(2*r,1),[],[],[],[],(-Q2*u2)-(d*e2),E2,-c*e2);
>
> ihave checked the dimensions of the matrices invoved ,but keep getting the
> message
> mclp(a,3,1)
> error: glpk: A must be a real valued 8 by 12 matrix
> error: called from
>    glpk at line 506 column 5
>    qp at line 370 column 29
>    mclp at line 20 column 16
>
> where a is a 4*30 matrix

I’m seeing a possible problem with glpk as well. What version of Octave are you using and what is the value for “a” when you call mclp(a,3,1)?

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

saiko7
i am posting the transpose of matrix 'a' ,since it will be easier to view

a'=                                                                                                            
    -1.35981     1.19186    -1.35835    -0.96627
    -0.07278     0.26615    -1.34016    -0.18523
     2.53635     0.16648     1.77321     1.79299
     1.37816     0.44815     0.37978    -0.86329
    -0.33832     0.06002    -0.50320    -0.01031
     0.46239    -0.08236     1.80050     1.24720
     0.23960    -0.07880     0.79146     0.23761
     0.09870     0.08510     0.24768     0.37744
     0.36379    -0.25543    -1.51465    -1.38702
     0.09079    -0.16697     0.20764    -0.05495
    -0.55160     1.61273     0.62450    -0.22649
    -0.61780     1.06524     0.06608     0.17823
    -0.99139     0.48910     0.71729     0.50776
    -0.31117    -0.14377    -0.16595    -0.28792
     1.46818     0.63556     2.34586    -0.63142
    -0.47040     0.46392    -2.89008    -1.05965
     0.20797    -0.11480     1.10997    -0.68409
     0.02579    -0.18336    -0.12136     1.96578
     0.40399    -0.14578    -2.26186    -1.23262
     0.25141    -0.06908     0.52498    -0.20804
    -0.01831    -0.22578     0.24800    -0.10830
     0.27784    -0.63867     0.77168     0.00527
    -0.11047     0.10129     0.90941    -0.19032
     0.06693    -0.33985    -0.68928    -1.17558
     0.12854     0.16717    -0.32764     0.64738
    -0.18911     0.12589    -0.13910    -0.22193
     0.13356    -0.00898    -0.05535     0.06272
    -0.02105     0.01472    -0.05975     0.06146
   149.62000     2.69000   378.66000   123.50000
     0.00000     0.00000     0.00000     0.00000
As you can see a is a 4*30 matrix(hence the data i posted is 30*4)
I am using octave 4.0.2 on windows 7
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

bpabbott
Administrator
> On Feb 12, 2017, at 12:46 PM, saiko7 <[hidden email]> wrote:
>
> i am posting the transpose of matrix 'a' ,since it will be easier to view
>
> a'=                                                                                                            
>    -1.35981     1.19186    -1.35835    -0.96627
>    -0.07278     0.26615    -1.34016    -0.18523
>     2.53635     0.16648     1.77321     1.79299
>     1.37816     0.44815     0.37978    -0.86329
>    -0.33832     0.06002    -0.50320    -0.01031
>     0.46239    -0.08236     1.80050     1.24720
>     0.23960    -0.07880     0.79146     0.23761
>     0.09870     0.08510     0.24768     0.37744
>     0.36379    -0.25543    -1.51465    -1.38702
>     0.09079    -0.16697     0.20764    -0.05495
>    -0.55160     1.61273     0.62450    -0.22649
>    -0.61780     1.06524     0.06608     0.17823
>    -0.99139     0.48910     0.71729     0.50776
>    -0.31117    -0.14377    -0.16595    -0.28792
>     1.46818     0.63556     2.34586    -0.63142
>    -0.47040     0.46392    -2.89008    -1.05965
>     0.20797    -0.11480     1.10997    -0.68409
>     0.02579    -0.18336    -0.12136     1.96578
>     0.40399    -0.14578    -2.26186    -1.23262
>     0.25141    -0.06908     0.52498    -0.20804
>    -0.01831    -0.22578     0.24800    -0.10830
>     0.27784    -0.63867     0.77168     0.00527
>    -0.11047     0.10129     0.90941    -0.19032
>     0.06693    -0.33985    -0.68928    -1.17558
>     0.12854     0.16717    -0.32764     0.64738
>    -0.18911     0.12589    -0.13910    -0.22193
>     0.13356    -0.00898    -0.05535     0.06272
>    -0.02105     0.01472    -0.05975     0.06146
>   149.62000     2.69000   378.66000   123.50000
>     0.00000     0.00000     0.00000     0.00000
> As you can see a is a 4*30 matrix(hence the data i posted is 30*4)
> I am using octave 4.0.2 on windows 7

I can confirm your scirpt gives the error, but don’t know if the syntax is correct. The problem I’m looking at is unrelated.

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

saiko7
SO are you saying there is a problem with the dimensions I have used? Or is it a glpk error?
Can you give me some idea about how I should proceed here ,to test my code?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

bpabbott
Administrator
On Feb 12, 2017, at 3:46 PM, saiko7 <[hidden email]> wrote:

SO are you saying there is a problem with the dimensions I have used? Or is
it a glpk error?
Can you give me some idea about how I should proceed here ,to test my code?

I’m not familiar with using A_LB, A_IN, and A_UB. Perhaps someone who is will reply.

Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

siko1056
bpabbott wrote
> On Feb 12, 2017, at 3:46 PM, saiko7 <[hidden email]> wrote:
>
> SO are you saying there is a problem with the dimensions I have used? Or is
> it a glpk error?
> Can you give me some idea about how I should proceed here ,to test my code?


I’m not familiar with using A_LB, A_IN, and A_UB. Perhaps someone who is will reply.

Ben
If you provide a short complete test script (no undefined variables, maybe as attachment) I can debug into the code to see what is wrong. I occasionally use GLPK myself. A first question mark is why do you overwrite your function input argument c in the third line of the function body?

Kai.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

bpabbott
Administrator
> On Feb 13, 2017, at 5:18 PM, siko1056 <[hidden email]> wrote:
>
> bpabbott wrote
>>> On Feb 12, 2017, at 3:46 PM, saiko7 &lt;
>
>> saital7@
>
>> &gt; wrote:
>>>
>>> SO are you saying there is a problem with the dimensions I have used? Or
>>> is
>>> it a glpk error?
>>> Can you give me some idea about how I should proceed here ,to test my
>>> code?
>>
>>
>> I’m not familiar with using A_LB, A_IN, and A_UB. Perhaps someone who is
>> will reply.
>>
>> Ben
>
> If you provide a short complete test script (no undefined variables, maybe
> as attachment) I can debug into the code to see what is wrong. I
> occasionally use GLPK myself. A first question mark is why do you overwrite
> your function input argument c in the third line of the function body?
>
> Kai.

Good catch Kai. There remains some typos, but his script now works for me.

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: glpk problem,please check code

saiko7
In reply to this post by siko1056
hey thanks for the reply
The c variable was indeed an oversight for on my part ,and i had changed that in my original code soon after ,however that wasnt what was causing the problem for me .

It was a problem with my A_in matrix .I think glpk (atleast my version)has some problems in taking non semi positive definite matrices (or perhaps det|A|=0 matrices ) as the value of A_in.

 once i changed my A_in matrix and made the necessary changes in my objective function ,it ran fine .

I am psting my code here ,just for future reference and for any helpful inputs .

//function [alpha2,obj,inf]=mclp(B,c,d);

a=B(:,1:29);
r=size(a,1);

Q=gallery('lehmer',r);Q2=[Q zeros(r,r);zeros(r,r) eye(r,r)];
alpha=zeros(r,1);

u=zeros(r,1);u2=[u;zeros(r,1)];

y=B(:,30);
p=sum(y==0);q=r-p;
e=ones(r,1);e2=[e;u];
E=[eye(q,q) zeros(q,p);zeros(p,q) -eye(p,p)];E2=[E zeros(r,r);zeros(r,r) eye(r,r)];
alpha=zeros(r,1);
b=a*a'+e*e';
H=[b zeros(r,r);zeros(r,r) Q];
alpha2=[alpha;u];

[alpha2 obj inf]=qp([alpha;u],H,zeros(2*r,1),[],[],[],[],(-Q2*[u;zeros(r,1)])-(d*[e;u/d]),E2,-c*[e;u/c]);//

P:S this is a code for a regularized multi criteria linear programming model for anomaly detection.
Loading...