Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/09/09 14:34:56 (15 years ago)
Author:
gkronber
Message:

Implemented a first version of an operator to calculate variable impacts of models (generated by GP or SVM). #644 (Variable impact of CEDMA models should be calculated and stored in the result DB)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/TreeEvaluatorBase.cs

    r1891 r2034  
    3535  public abstract class TreeEvaluatorBase : ItemBase, ITreeEvaluator {
    3636    protected const double EPSILON = 1.0e-7;
    37     protected double estimatedValueMax;
    38     protected double estimatedValueMin;
     37    protected double maxValue;
     38    protected double minValue;
    3939
    4040    protected class Instr {
     
    5252    protected int sampleIndex;
    5353
    54     public void ResetEvaluator(Dataset dataset, int targetVariable, int start, int end, double punishmentFactor) {
     54    public void PrepareForEvaluation(Dataset dataset, int targetVariable, int start, int end, double punishmentFactor, IFunctionTree functionTree) {
    5555      this.dataset = dataset;
    56       double maximumPunishment = punishmentFactor * dataset.GetRange(targetVariable, start, end);
     56      // calculate upper and lower bounds for the estimated value (mean +/- punishmentFactor * range)
     57      double mean = dataset.GetMean(targetVariable, start, end);
     58      double range = dataset.GetRange(targetVariable, start, end);
     59      maxValue = mean + punishmentFactor * range;
     60      minValue = mean - punishmentFactor * range;
    5761
    58       // get the mean of the values of the target variable to determine the max and min bounds of the estimated value
    59       double targetMean = dataset.GetMean(targetVariable, start, end);
    60       estimatedValueMin = targetMean - maximumPunishment;
    61       estimatedValueMax = targetMean + maximumPunishment;
    62     }
    63 
    64     public void PrepareForEvaluation(IFunctionTree functionTree) {
    6562      BakedFunctionTree bakedTree = functionTree as BakedFunctionTree;
    6663      if (bakedTree == null) throw new ArgumentException("TreeEvaluators can only evaluate BakedFunctionTrees");
     
    103100
    104101      double estimated = EvaluateBakedCode();
    105       if (double.IsNaN(estimated) || double.IsInfinity(estimated)) {
    106         estimated = estimatedValueMax;
    107       } else if (estimated > estimatedValueMax) {
    108         estimated = estimatedValueMax;
    109       } else if (estimated < estimatedValueMin) {
    110         estimated = estimatedValueMin;
    111       }
     102      if (double.IsNaN(estimated) || double.IsInfinity(estimated)) estimated = maxValue;
     103      else if (estimated < minValue) estimated = minValue;
     104      else if (estimated > maxValue) estimated = maxValue;
    112105      return estimated;
    113106    }
     
    123116
    124117    protected abstract double EvaluateBakedCode();
    125 
    126     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    127       TreeEvaluatorBase clone = (TreeEvaluatorBase)base.Clone(clonedObjects);
    128       if (!clonedObjects.ContainsKey(dataset.Guid)) {
    129         clone.dataset = (Dataset)dataset.Clone(clonedObjects);
    130       } else {
    131         clone.dataset = (Dataset)clonedObjects[dataset.Guid];
    132       }
    133       clone.estimatedValueMax = estimatedValueMax;
    134       clone.estimatedValueMin = estimatedValueMin;
    135       return clone;
    136     }
    137 
    138     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    139       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    140       XmlAttribute minEstimatedValueAttr = document.CreateAttribute("MinEstimatedValue");
    141       minEstimatedValueAttr.Value = XmlConvert.ToString(estimatedValueMin);
    142       node.Attributes.Append(minEstimatedValueAttr);
    143 
    144       XmlAttribute maxEstimatedValueAttr = document.CreateAttribute("MaxEstimatedValue");
    145       maxEstimatedValueAttr.Value = XmlConvert.ToString(estimatedValueMax);
    146       node.Attributes.Append(maxEstimatedValueAttr);
    147 
    148       node.AppendChild(PersistenceManager.Persist("Dataset", dataset, document, persistedObjects));
    149       return node;
    150     }
    151 
    152     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    153       base.Populate(node, restoredObjects);
    154       estimatedValueMax = XmlConvert.ToDouble(node.Attributes["MaxEstimatedValue"].Value);
    155       estimatedValueMin = XmlConvert.ToDouble(node.Attributes["MinEstimatedValue"].Value);
    156 
    157       dataset = (Dataset)PersistenceManager.Restore(node.SelectSingleNode("Dataset"), restoredObjects);
    158     }
    159118  }
    160119}
Note: See TracChangeset for help on using the changeset viewer.