Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2034


Ignore:
Timestamp:
06/09/09 14:34:56 (16 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)

Location:
trunk/sources
Files:
1 added
2 deleted
12 edited

Legend:

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

    r1891 r2034  
    8585
    8686        BakedTreeEvaluator evaluator = new BakedTreeEvaluator();
    87         evaluator.ResetEvaluator(dataset, targetVariable, trainingSamplesStart, trainingSamplesEnd, 1.0);
    88         evaluator.PrepareForEvaluation(functionTree);
     87        evaluator.PrepareForEvaluation(dataset, targetVariable, trainingSamplesStart, trainingSamplesEnd, 1.0, functionTree);
    8988        for(int i = 0; i < (samplesEnd - samplesStart); i++) {
    9089          double est = evaluator.Evaluate(i + samplesStart);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/AlgorithmBase.cs

    r1922 r2034  
    147147      IOperator initialization = CreateInitialization();
    148148      IOperator funLibInjector = CreateFunctionLibraryInjector();
    149       IOperator treeEvaluatorInjector = new HL2TreeEvaluatorInjector();
    150149
    151150      IOperator mainLoop = CreateMainLoop();
     
    170169      seq.AddSubOperator(globalInjector);
    171170      seq.AddSubOperator(funLibInjector);
    172       seq.AddSubOperator(treeEvaluatorInjector);
    173171      seq.AddSubOperator(initialization);
    174172      seq.AddSubOperator(mainLoop);
     
    215213      injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData()));
    216214      injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData()));
     215      injector.AddVariable(new HeuristicLab.Core.Variable("TreeEvaluator", new HL2TreeEvaluator()));
    217216      return injector;
    218217    }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/EarlyStoppingMeanSquaredErrorEvaluator.cs

    r1891 r2034  
    4545    // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE
    4646    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    47       double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
     47      double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, true).Data;
    4848      DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
    4949      if (mse == null) {
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/GPEvaluatorBase.cs

    r1891 r2034  
    4040      AddVariableInfo(new VariableInfo("PunishmentFactor", "Punishment factor for invalid estimations", typeof(DoubleData), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("TotalEvaluatedNodes", "Number of evaluated nodes", typeof(DoubleData), VariableKind.In | VariableKind.Out));
     42      AddVariableInfo(new VariableInfo("TrainingSamplesStart", "Start index of training samples in dataset", typeof(IntData), VariableKind.In));
     43      AddVariableInfo(new VariableInfo("TrainingSamplesEnd", "End index of training samples in dataset", typeof(IntData), VariableKind.In));
    4244      AddVariableInfo(new VariableInfo("SamplesStart", "Start index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
    4345      AddVariableInfo(new VariableInfo("SamplesEnd", "End index of samples in dataset to evaluate", typeof(IntData), VariableKind.In));
     
    5153      IFunctionTree functionTree = GetVariableValue<IFunctionTree>("FunctionTree", scope, true);
    5254      double punishmentFactor = GetVariableValue<DoubleData>("PunishmentFactor", scope, true).Data;
    53       int treeSize = scope.GetVariableValue<IntData>("TreeSize", false).Data;
     55      int treeSize = scope.GetVariableValue<IntData>("TreeSize", true).Data;
    5456      double totalEvaluatedNodes = scope.GetVariableValue<DoubleData>("TotalEvaluatedNodes", true).Data;
     57      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
     58      int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
    5559      int start = GetVariableValue<IntData>("SamplesStart", scope, true).Data;
    5660      int end = GetVariableValue<IntData>("SamplesEnd", scope, true).Data;
    5761      bool useEstimatedValues = GetVariableValue<BoolData>("UseEstimatedTargetValue", scope, true).Data;
    5862      ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>("TreeEvaluator", scope, true);
    59       evaluator.PrepareForEvaluation(functionTree);
     63      evaluator.PrepareForEvaluation(dataset, targetVariable, trainingStart, trainingEnd, punishmentFactor, functionTree);
    6064
    6165      double[] backupValues = null;
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/UncertainMeanSquaredErrorEvaluator.cs

    r1891 r2034  
    5151    // evaluates the function-tree for the given target-variable and the whole dataset and returns the MSE
    5252    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
    53       double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, false).Data;
     53      double qualityLimit = GetVariableValue<DoubleData>("QualityLimit", scope, true).Data;
    5454      int minSamples = GetVariableValue<IntData>("MinEvaluatedSamples", scope, true).Data;
    5555      MersenneTwister mt = GetVariableValue<MersenneTwister>("Random", scope, true);
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj

    r1908 r2034  
    9191    <Compile Include="TreeEvaluatorBase.cs" />
    9292    <Compile Include="HL2TreeEvaluator.cs" />
    93     <Compile Include="HL2TreeEvaluatorInjector.cs" />
    94     <Compile Include="TreeEvaluatorInjector.cs" />
    9593    <Compile Include="ITreeEvaluator.cs" />
    9694    <Compile Include="Evaluators\MeanAbsolutePercentageOfRangeErrorEvaluator.cs" />
  • trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/ITreeEvaluator.cs

    r1891 r2034  
    3131namespace HeuristicLab.GP.StructureIdentification {
    3232  public interface ITreeEvaluator : IItem {
    33     void ResetEvaluator(Dataset dataset, int targetVariable, int start, int end, double punishmentFactor);
    34     void PrepareForEvaluation(IFunctionTree functionTree);
     33    void PrepareForEvaluation(Dataset dataset, int targetVariable, int start, int end, double punishmentFactor, IFunctionTree functionTree);
    3534    double Evaluate(int sampleIndex);
    3635  }
  • 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}
  • trunk/sources/HeuristicLab.Logging/3.2/BestSolutionStorer.cs

    r1530 r2034  
    3131  /// Keeps a variable in the global scope that contains the scope representing the best solution.
    3232  /// </summary>
    33   public class BestSolutionStorer : DelegatingOperator {
     33  public class BestSolutionStorer : OperatorBase {
    3434    /// <inheritdoc select="summary"/>
    3535    public override string Description {
  • trunk/sources/HeuristicLab.Modeling/3.2/HeuristicLab.Modeling-3.2.csproj

    r1906 r2034  
    8383  <ItemGroup>
    8484    <Compile Include="ClassificationProblemInjector.cs" />
     85    <Compile Include="VariableImpactCalculator.cs" />
    8586    <Compile Include="Model.cs" />
    8687    <Compile Include="IModel.cs" />
  • trunk/sources/HeuristicLab.Modeling/3.2/IModel.cs

    r1922 r2034  
    4545    double ValidationVarianceAccountedFor { get; }
    4646    double TestVarianceAccountedFor { get; }
     47    double GetVariableImpact(string variableName);
    4748
    4849    IItem Data { get; }
  • trunk/sources/HeuristicLab.Modeling/3.2/Model.cs

    r1922 r2034  
    120120    }
    121121
     122    public double GetVariableImpact(string variableName) {
     123      if (variableImpacts.ContainsKey(variableName)) return variableImpacts[variableName];
     124      else return 0.0;
     125    }
     126
    122127    private IItem data;
    123128    public IItem Data {
     
    127132
    128133    #endregion
     134
     135    private Dictionary<string, double> variableImpacts = new Dictionary<string, double>();
     136    public void SetVariableImpact(string variableName, double impact) {
     137      variableImpacts[variableName] = impact;
     138    }
     139
     140    public void SetVariableImpact(int variableIndex, double impact) {
     141      variableImpacts[dataset.GetVariableName(variableIndex)] = impact;
     142    }
    129143  }
    130144}
Note: See TracChangeset for help on using the changeset viewer.