Changeset 4654:92fedd8a871e in orange


Ignore:
Timestamp:
05/16/08 22:08:36 (6 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
5eb8396cd6df7906588d7592250e5181b86dbf4d
Message:
  • fixed a division by zero in MeasureAttribute_cost
File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/orange/measures.cpp

    r4629 r4654  
    899899      TDiscDistribution dist2 = dist; 
    900900      dist2 += probabilities->innerDistributionUnknown; 
    901       N += dist2.cases; 
    902       continueCost += dist2.cases * majorityCost(dist2); 
     901      if (dist2.cases && dist2.abs) { 
     902        N += dist2.cases; 
     903        continueCost += dist2.cases * majorityCost(dist2); 
     904      } 
    903905    } 
    904906    else { 
    905       N += dist.cases; 
    906       continueCost += dist.cases * majorityCost(dist.distribution); 
     907      if (dist.cases && dist.abs) { 
     908        N += dist.cases; 
     909        continueCost += dist.cases * majorityCost(dist.distribution); 
     910      } 
    907911    } 
    908912  } 
     
    910914  if (unknownsTreatment == UnknownsAsValue) { 
    911915    const float &cases = probabilities->innerDistributionUnknown->cases; 
    912     N += cases; 
    913     continueCost += cases * majorityCost(CAST_TO_DISCDISTRIBUTION(probabilities->innerDistributionUnknown)); 
    914   } 
    915  
    916   continueCost /= N; 
     916    if (cases) { 
     917      N += cases; 
     918      continueCost += cases * majorityCost(CAST_TO_DISCDISTRIBUTION(probabilities->innerDistributionUnknown)); 
     919    } 
     920  } 
     921 
     922  if (N) 
     923    continueCost /= N; 
    917924 
    918925  float cost = stopCost - continueCost; 
    919   if (unknownsTreatment == ReduceByUnknowns) 
     926  if ((unknownsTreatment == ReduceByUnknowns) && outer.unknowns) // to avoid div by zero if !cases, too 
    920927    cost *= (outer.cases / (outer.unknowns + outer.cases)); 
    921928 
Note: See TracChangeset for help on using the changeset viewer.