Changeset 3678:d79481c7766c in orange


Ignore:
Timestamp:
05/21/07 15:05:00 (7 years ago)
Author:
martinm <martinm@…>
Branch:
default
Convert:
80f216204c3eb444cf04984fe37c9720494861fe
Message:

Repaired EVC evaluation - single attribute significance

Location:
source/orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/orange/rulelearner.cpp

    r3578 r3678  
    4343  coveredExamples(NULL), 
    4444  coveredExamplesLength(-1), 
    45   parentRule(NULL) 
     45  parentRule(NULL), 
     46  chi(0.0) 
    4647{} 
    4748 
     
    5758  coveredExamples(NULL), 
    5859  coveredExamplesLength(-1), 
    59   parentRule(NULL) 
     60  parentRule(NULL), 
     61  chi(0.0) 
    6062{} 
    6163 
     
    7274  coveredExamples(copyData && other.coveredExamples && (other.coveredExamplesLength >= 0) ? (int *)memcpy(new int[other.coveredExamplesLength], other.coveredExamples, other.coveredExamplesLength) : NULL), 
    7375  coveredExamplesLength(copyData ? other.coveredExamplesLength : -1), 
    74   parentRule(other.parentRule) 
     76  parentRule(other.parentRule), 
     77  chi(other.chi) 
    7578{} 
    7679 
     
    668671} 
    669672 
     673bool TRuleEvaluator_mEVC::ruleAttSignificant(PRule rule, PExampleTable examples, const int & weightID, const int &targetClass, PDistribution apriori, float & aprioriProb) 
     674{ 
     675  // Should classical LRS be use, or EVC corrected? 
     676  TFilter_values *filter = rule->filter.AS(TFilter_values); 
     677  int rLength = filter->conditions->size(); 
     678  PEVCDist full_evc = evcDistGetter->call(rule, rLength); 
     679  PEVCDist short_evc = evcDistGetter->call(rule, rLength-1); 
     680   
     681  bool useClassicLRS = false; 
     682  if (full_evc->mu - short_evc->mu < 1.0) 
     683    useClassicLRS = true; 
     684 
     685  // Loop through all attributes - remove each and check significance 
     686  bool rasig = true; 
     687  int i,j; 
     688  float quality; 
     689  TFilter_values *newfilter; 
     690 
     691  for (i=0; i<filter->conditions->size(); i++) 
     692  { 
     693      TRule *newRule = new TRule(); 
     694      PRule wnewRule = newRule; 
     695      wnewRule->filter = new TFilter_values(); 
     696      wnewRule->filter->domain = examples->domain; 
     697      wnewRule->complexity = rule->complexity - 1; 
     698      newfilter = newRule->filter.AS(TFilter_values); 
     699      for (j=0; j<filter->conditions->size(); j++) 
     700        if (j!=i) 
     701          newfilter->conditions->push_back(filter->conditions->at(j)); 
     702      wnewRule->filterAndStore(examples, weightID, targetClass); 
     703      if (!useClassicLRS) { 
     704        quality = evaluateRule(wnewRule, examples, weightID, targetClass, apriori, newfilter->conditions->size(), aprioriProb); 
     705        rasig = rasig & (((rule->chi- wnewRule->chi) > 0.0) && (chisqprob(rule->chi- wnewRule->chi, 1.0f) <= attributeAlpha)); 
     706      } 
     707      else  
     708      { 
     709        float nonOptimistic_Chi; 
     710        wnewRule->chi = chiFunction->call(rule, examples, weightID, targetClass, wnewRule->classDistribution, nonOptimistic_Chi); 
     711        wnewRule->chi += nonOptimistic_Chi; 
     712        rasig = rasig & ((wnewRule->chi > 0.0) && (chisqprob(wnewRule->chi, 1.0f) <= attributeAlpha)); 
     713      } 
     714  } 
     715  return rasig; 
     716} 
     717 
    670718float TRuleEvaluator_mEVC::evaluateRule(PRule rule, PExampleTable examples, const int & weightID, const int &targetClass, PDistribution apriori, const int & rLength, const float & aprioriProb) const 
    671719{ 
     
    749797  else { 
    750798    PDistribution oldRuleDist = rule->classDistribution; 
     799    float rulesTrueChi = rule->chi; 
    751800    rule->classDistribution = mlnew TDiscDistribution(examples->domain->classVar); 
    752801    rule->classDistribution->setint(targetClass, oldRuleDist->atint(targetClass)); 
     
    754803    float bestQuality = evaluateRule(rule,examples,weightID,targetClass,apriori,rLength+1,aprioriProb); 
    755804    rule->classDistribution = oldRuleDist; 
     805    rule->chi = rulesTrueChi; 
    756806    if (bestQuality < rule->quality) 
    757807      futureQuality = -1; 
     
    764814  // store best rule and return result 
    765815  if (improved >= min_improved && improved/rule->classDistribution->atint(targetClass) > min_improved_perc && 
    766       rule->quality > aprioriProb && 
     816      rule->quality > aprioriProb &&  
    767817      (!bestRule || (rule->quality>bestRule->quality)) && 
    768818      (!validator || validator->call(rule, examples, weightID, targetClass, apriori))) { 
    769819      TRule *pbestRule = new TRule(rule.getReference(), true); 
    770       bestRule = pbestRule; 
     820      PRule wpbestRule = pbestRule; 
     821 
     822      bool ruleGoodEnough = true; 
     823      // check if rule is significant enough 
     824      if (ruleAlpha < 1.0) 
     825        ruleGoodEnough = ruleGoodEnough & ((rule->chi > 0.0) && (chisqprob(rule->chi, 1.0f) <= ruleAlpha)); 
     826      if (attributeAlpha < 1.0)  
     827        ruleGoodEnough = ruleGoodEnough & ruleAttSignificant(rule, examples, weightID, targetClass, apriori, aprioriProb); 
     828      if (ruleGoodEnough) 
     829        bestRule = wpbestRule; 
    771830  } 
    772831  return futureQuality; 
  • source/orange/rulelearner.hpp

    r3576 r3678  
    227227  float min_improved_perc; //P minimal percentage of improved examples 
    228228  PRule bestRule; //P best rule found and evaluated given conditions (min_improved, validator) 
     229  float ruleAlpha; //P minimal 'true' rule significance 
     230  float attributeAlpha; //P minimal attribute significance 
    229231 
    230232  TRuleEvaluator_mEVC(); 
    231233  TRuleEvaluator_mEVC(const int & m, PChiFunction, PEVCDistGetter, PVariable, PRuleValidator, const int & min_improved, const float & min_improved_perc); 
    232234  void reset(); 
     235  bool ruleAttSignificant(PRule, PExampleTable, const int &, const int &targetClass, PDistribution, float &); 
    233236  float chiAsimetryCorrector(const float &); 
    234237  float evaluateRule(PRule rule, PExampleTable examples, const int & weightID, const int &targetClass, PDistribution apriori, const int & rLength, const float & aprioriProb) const; 
Note: See TracChangeset for help on using the changeset viewer.