1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| public List<PrismRule> CR2 = new ArrayList<PrismRule>();
private PrismRule Add2(PrismRule r, Instances data) throws Exception {
PrismRule CR_rules = addRule(null , new PrismRule(data, 0));
int cl=r.m_classification; // possible value of theClass
Instances E, ruleE;
Test test = null, oldTest = null;
int bestCorrect, bestCovers, attUsed;
Enumeration enumAtt;
getCapabilities().testWithFail(data); // can classifier handle the data?
data = new Instances(data);
data.deleteWithMissingClass();// remove instances with missing class
E = data; // initialize E to the instance set
ruleE = E; // examples covered by this rule
test = new Test();
CR_rules.m_test=test;
// for every attribute not mentioned in the rule
enumAtt = ruleE.enumerateAttributes();
//----------------------------------------------------------------------------
while (enumAtt.hasMoreElements())
{
Attribute attr = (Attribute) enumAtt.nextElement();
if (isMentionedIn(attr, r.m_test)) {continue;}
int M = attr.numValues();
//------------------------- For numbeer 1---------------------------
for (int val = 0; val < M; val ++) // ... for each value of this attribute
{
//PrismRule cr = addRule(null , new PrismRule(data, 0));
Test Tst =new Test() ;
Tst.m_attr = attr.index();
Tst.m_val = val;
//---------------------------Second while------------------------------------
Enumeration enumAtt2 = ruleE.enumerateAttributes();
//----------------------------------------------------------------------------
while (enumAtt2.hasMoreElements())
{
Attribute attr2 = (Attribute) enumAtt2.nextElement();
if (isMentionedIn(attr2, r.m_test)||(attr==attr2)) {continue;}
int M2= attr2.numValues();
//-----------------begin inner for
for (int val2 = 0; val2 < M2; val2 ++) // ... for each value of this attribute
{
PrismRule cr = addRule(null , new PrismRule(data, 0));
Test Tst2 =new Test() ;
Tst2.m_attr = attr2.index();
Tst2.m_val = val2;
System.out.println("tst"+Tst.m_attr +", test2"+Tst2.m_val);
// Tst = cr.m_test;
Tst.m_next= Tst2;
Tst=Tst.m_next;
Test Tst3 =new Test() ;
Tst3=Tst;
cr.m_test=Tst3;
CR.add(cr);
}/////////////////end inner for
} //---------------end inner While------------
}//-------------------end Fisrt for
}//-----------------------------------First end of While----------------
System.out.println("********************End build***************************");
if ( CR.size()>1 ) { // il faut au moins 2 règles pour qu'il y ait un lien entre règles
PrismRule previous = CR_rules;
for(int i=0; i<CR.size(); i++) { // on commence à la 2ème règle dans la liste (la première c'est previous);
//System.out.println("CR = "+CR.get(i).toString());
previous.m_next = CR.get(i); // la suivante de previous, c'est la règle courante de l'itération
previous=previous.m_next; // la nouvelle règle qu'on va traiter l'itération suivante, est la suivante de celle qu'on vient de traiter.
}
}
return CR_rules ;
} |
Partager