Cost matrix example prex_cost.m doesnt work out of the box? 
Posted: 12 May 2009 11:34 PM   [ Ignore ]  
Newbie
Rank
Total Posts:  20
Joined  2008-07-11

Hi again PRtools team and addicts! Now I trying to use the cost matrix facilities and when trying to run the basic example in prex_cost.m it throws an error:

... (more previous output)

The black decision boundary shows the standard ldc classifier
for this data. When the misclassification cost of a pear to an
apple is increased, we obtain the blue classifier. When on top
of that a rejection class is introduced, we get the blue dashed
classifier. In that case, all objects between the dashed lines
are rejected.

Cost of basic classifier = 0.51
Cost of cost classifier = 0.24
PR_Warning: setfeatlab: The label list should have at least 4 elements.
PR_Warning: setfeatlab: Empty feature labels inserted.
??? Error using ==> testcost at 98
The classifier outputs a label which are not defined in C!

Error in ==> map at 161
d = feval(mapp,a,pars{:}); % Damn! sequential mappings are split! Solve there!

Error in ==> D:\Mariano\papers\ECG Classification\scripts\common\prtools\@mapping\mtimes.p>mtimes at 15

Error in ==> prex_cost at 58
fprintf(’ Cost of reject classifier = %4.2f\n’,…

Is the cost matrix implementation stable or should I wait for future versions ?

Tanks in advance,
Mariano.

Profile
 
 
Posted: 13 May 2009 06:49 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  107
Joined  2008-04-26

Hi Mariano,

I’m getting the same error in this example. I’m not familiar with cost optimization using PRTools costm and cannot see a simple solution in map.m myself.

In the meantime, you could be interested to check out alternative cost-based optimization implemented in PRSD Studio:
http://doc.prsysdesign.net/latest/guide/ROC_analysis.html#cost

In the prex_cost problem, you would do:

>> wd=w*sddecide(w) % will produce decisions at default operating point
2 to 1 trained  mapping   
--> sequential
>> sdconfmat(getlab(a),a*wd,'norm')

ans =

 
True      Decisions
 Labels    
apple  banana pear    Totals
--------------------------------------------
 
apple     0.767  0.067  0.167   1.00
 banana    
0.000  1.000  0.000   1.00
 pear      
0.133  0.100  0.767   1.00
--------------------------------------------

Cost-based ROC optimization:

>> out=a*soft classifier output (here on the training set)
Banana Set90 by 3 dataset with 3 classes[30  30  30]
>> m=ones(3); m(3,1)=cost matrix (the same class order as the dataset lablist and the confusion matrix)

=

     
1     1     1
     1     1     1
     9     1     1

>> r=sdroc(out,'cost',m) % optimize the operating point minimizing system loss
PR_Warning
getpriorsdrocNo priors found in dataset, class frequencies are used instead
..........
ROC (100 w-based op.points4 measures), curop1
est
1:err(apple)=0.302:err(banana)=0.003:err(pear)=0.074:mean-error [0.33,0.33,...]=0.12

>> wd2=sdmap([sdconvert(wr])  % returns decision at current operating point of the ROC r
pipeline
2 to 1 trained  mapping   --> sdmap

>> sdconfmat(getlab(a),a*wd2,'norm')

ans =

 
True      Decisions
 Labels    
apple  banana pear    Totals
--------------------------------------------
 
apple     0.700  0.067  0.233   1.00
 banana    
0.000  1.000  0.000   1.00
 pear      
0.033  0.033  0.933   1.00
--------------------------------------------

We have decreased the pear/apple error.

Hope it helps,

Pavel

[ Edited: 13 May 2009 07:02 AM by pavel]
Profile
 
 
Posted: 13 May 2009 08:27 AM   [ Ignore ]   [ # 2 ]  
Newbie
Rank
Total Posts:  20
Joined  2008-07-11

Thanks a lot Pavel as always. I am not familiar with PRSDstudio, but going to try what you suggested.

Would you think that this bug is going to be fixed soon ?

Regards,
Mariano.

Profile
 
 
Posted: 13 May 2009 09:32 AM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  107
Joined  2008-04-26

Dear Mariano,

please download the prtools again. The problem was fixed in the recent update but made it to the website only now.

prex_cost should work for you now.

Best Regards,

Pavel

Profile
 
 
Posted: 13 May 2009 03:48 PM   [ Ignore ]   [ # 4 ]  
Newbie
Rank
Total Posts:  20
Joined  2008-07-11

Pavel, when using testcost.m throws an error and I think that in line 92 could be a bug:

it says,

lablist2 = getfeatlab(x);

and I think should say

lablist2 = getlablist(x);

as the following line compares the lablists

I2 = matchlablist(lablist2,lablist);

I made this small modification and seems to work, but not sure if there is other problem out of my limited scope ...

Mariano.

Profile
 
 
Posted: 13 May 2009 04:11 PM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  107
Joined  2008-04-26

Hi Mariano,

have you downloaded the newest PRTools version (4.1.4. 28-Apr-2009) ? For me, the example works fine.

The author of the cost framework in PRTools is David Tax. So I can only comment here based on a quick look: I think that x is the classifier output which means that the columns represent the classes. The feature labels should be therefore identical to the lablist of the training dataset (and the labels stored in the mapping object).
When I run the example on the latest PRTools version, the dataset with outputs (a*w) does have feature labels identical to the lablist.

Pavel

Profile
 
 
Posted: 13 May 2009 04:20 PM   [ Ignore ]   [ # 6 ]  
Newbie
Rank
Total Posts:  20
Joined  2008-07-11

Sorry Pavel, but I forgot to mention that I am not using the prex_cost.m anymore. This error arrises when using my datasets. I guess that these lines try to match the labels in the cost matrix and in the result dataset with respect to the given lablist.

Well I wait for David comments in case he read this topic.

Thanks again,
Mariano.

Profile
 
 
Posted: 13 May 2009 11:06 PM   [ Ignore ]   [ # 7 ]  
Moderator
RankRankRankRank
Total Posts:  108
Joined  2008-11-08

Dear Mariano,

I have put a new version of PRTools on the website. Please use it and if there is still an error let me know. I think that the getfeatlab statement in testcost is correct.

Best regards,

Bob Duin

Profile