Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/15 11:16:41 (10 years ago)
Author:
mkommend
Message:

#2175: Additional calculation of results for EuroCast 2015.

Location:
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
3 edited
1 copied
2 moved

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r11861 r11883  
    191191  </ItemGroup>
    192192  <ItemGroup>
    193     <Compile Include="MultiObjective\SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator.cs" />
    194     <Compile Include="MultiObjective\SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator.cs" />
     193    <Compile Include="MultiObjective\PearsonRSquaredNumberOfVariablesEvaluator.cs" />
     194    <Compile Include="MultiObjective\PearsonRSquaredNestedTreeSizeEvaluator.cs" />
     195    <Compile Include="MultiObjective\PearsonRSquaredTreeComplexityEvaluator.cs" />
    195196    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />
    196197    <Compile Include="Plugin.cs" />
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNestedTreeSizeEvaluator.cs

    r11882 r11883  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930
     
    3132  [Item("Pearson R² & Nested Tree size Evaluator", "Calculates the Pearson R² and the nested tree size of a symbolic regression solution.")]
    3233  [StorableClass]
    33   public class SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
     34  public class PearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
     35    private const string useConstantOptimizationParameterName = "Use constant optimization";
     36    public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
     37      get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
     38    }
     39    public bool UseConstantOptimization {
     40      get { return UseConstantOptimizationParameter.Value.Value; }
     41      set { UseConstantOptimizationParameter.Value.Value = value; }
     42    }
     43
    3444    [StorableConstructor]
    35     protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
    36     protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator original, Cloner cloner)
     45    protected PearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
     46    protected PearsonRSquaredNestedTreeSizeEvaluator(PearsonRSquaredNestedTreeSizeEvaluator original, Cloner cloner)
    3747      : base(original, cloner) {
    3848    }
    3949    public override IDeepCloneable Clone(Cloner cloner) {
    40       return new SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(this, cloner);
     50      return new PearsonRSquaredNestedTreeSizeEvaluator(this, cloner);
    4151    }
    4252
    43     public SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator() : base() { }
     53    public PearsonRSquaredNestedTreeSizeEvaluator()
     54      : base() {
     55      Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
     56    }
    4457
    4558    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
     
    4861      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4962      var solution = SymbolicExpressionTreeParameter.ActualValue;
     63      var problemData = ProblemDataParameter.ActualValue;
     64      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     65      var estimationLimits = EstimationLimitsParameter.ActualValue;
     66      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
     67
     68      if (UseConstantOptimization) {
     69        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower);
     70      }
     71
    5072      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5173      QualitiesParameter.ActualValue = new DoubleArray(qualities);
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredNumberofVariablesEvaluator.cs

    r11861 r11883  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     28using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    31   [Item("Pearson R² & Nested Tree size Evaluator", "Calculates the Pearson R² and the nested tree size of a symbolic regression solution.")]
     32  [Item("Pearson R² & Number of Variables Evaluator", "Calculates the Pearson R² and the number of used variables of a symbolic regression solution.")]
    3233  [StorableClass]
    33   public class SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
     34  public class PearsonRSquaredNumberOfVariablesEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
     35    private const string useConstantOptimizationParameterName = "Use constant optimization";
     36    public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
     37      get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
     38    }
     39    public bool UseConstantOptimization {
     40      get { return UseConstantOptimizationParameter.Value.Value; }
     41      set { UseConstantOptimizationParameter.Value.Value = value; }
     42    }
     43
    3444    [StorableConstructor]
    35     protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
    36     protected SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator original, Cloner cloner)
     45    protected PearsonRSquaredNumberOfVariablesEvaluator(bool deserializing) : base(deserializing) { }
     46    protected PearsonRSquaredNumberOfVariablesEvaluator(PearsonRSquaredNumberOfVariablesEvaluator original, Cloner cloner)
    3747      : base(original, cloner) {
    3848    }
    3949    public override IDeepCloneable Clone(Cloner cloner) {
    40       return new SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator(this, cloner);
     50      return new PearsonRSquaredNumberOfVariablesEvaluator(this, cloner);
    4151    }
    4252
    43     public SymbolicRegressionMultiObjectivePearsonRSquaredNestedTreeSizeEvaluator() : base() { }
     53    public PearsonRSquaredNumberOfVariablesEvaluator()
     54      : base() {
     55      Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
     56    }
    4457
    4558    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
     
    4861      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4962      var solution = SymbolicExpressionTreeParameter.ActualValue;
     63      var problemData = ProblemDataParameter.ActualValue;
     64      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     65      var estimationLimits = EstimationLimitsParameter.ActualValue;
     66      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
     67
     68      if (UseConstantOptimization) {
     69        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower);
     70      }
    5071      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5172      QualitiesParameter.ActualValue = new DoubleArray(qualities);
     
    5576    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5677      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
    57       return new double[2] { r2, solution.IterateNodesPostfix().Sum(n => n.GetLength()) };
     78      return new double[2] { r2, solution.IterateNodesPostfix().OfType<VariableTreeNode>().Count() };
    5879    }
    5980
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/PearsonRSquaredTreeComplexityEvaluator.cs

    r11861 r11883  
    3131  [Item("Pearson R² & Tree Complexity Evaluator", "Calculates the Pearson R² and the tree complexity of a symbolic regression solution.")]
    3232  [StorableClass]
    33   public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    34     private string useConstantOptimizationParameterName = "Use constant optimization";
    35 
     33  public class PearsonRSquaredTreeComplexityEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
     34    private const string useConstantOptimizationParameterName = "Use constant optimization";
    3635    public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
    3736      get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
    3837    }
    39 
    4038    public bool UseConstantOptimization {
    4139      get { return UseConstantOptimizationParameter.Value.Value; }
     
    4442
    4543    [StorableConstructor]
    46     protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator(bool deserializing) : base(deserializing) { }
    47     protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator original, Cloner cloner)
     44    protected PearsonRSquaredTreeComplexityEvaluator(bool deserializing) : base(deserializing) { }
     45    protected PearsonRSquaredTreeComplexityEvaluator(PearsonRSquaredTreeComplexityEvaluator original, Cloner cloner)
    4846      : base(original, cloner) {
    4947    }
    5048    public override IDeepCloneable Clone(Cloner cloner) {
    51       return new SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator(this, cloner);
     49      return new PearsonRSquaredTreeComplexityEvaluator(this, cloner);
    5250    }
    5351
    54     public SymbolicRegressionMultiObjectivePearsonRSquaredTreeComplexityEvaluator()
     52    public PearsonRSquaredTreeComplexityEvaluator()
    5553      : base() {
    5654      Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
    57 
    5855    }
    5956
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r11310 r11883  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     27using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
     
    3132  [StorableClass]
    3233  public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
     34    private const string useConstantOptimizationParameterName = "Use constant optimization";
     35    public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
     36      get { return (IFixedValueParameter<BoolValue>)Parameters[useConstantOptimizationParameterName]; }
     37    }
     38    public bool UseConstantOptimization {
     39      get { return UseConstantOptimizationParameter.Value.Value; }
     40      set { UseConstantOptimizationParameter.Value.Value = value; }
     41    }
     42
    3343    [StorableConstructor]
    3444    protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
     
    4050    }
    4151
    42     public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base() { }
     52    public SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base()
     53    {
     54      Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
     55    }
     56
     57    [StorableHook(HookType.AfterDeserialization)]
     58    private void AfterDeserialization() {
     59      if (!Parameters.ContainsKey(useConstantOptimizationParameterName)) {
     60        Parameters.Add(new FixedValueParameter<BoolValue>(useConstantOptimizationParameterName, "", new BoolValue(false)));
     61      }
     62    }
    4363
    4464    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
     
    4767      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4868      var solution = SymbolicExpressionTreeParameter.ActualValue;
     69      var problemData = ProblemDataParameter.ActualValue;
     70      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     71      var estimationLimits = EstimationLimitsParameter.ActualValue;
     72      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
     73
     74      if (UseConstantOptimization) {
     75        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, 5, estimationLimits.Upper, estimationLimits.Lower);
     76      }
    4977      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5078      QualitiesParameter.ActualValue = new DoubleArray(qualities);
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r11310 r11883  
    109109      }
    110110
    111       var problemData = ProblemDataParameter.ActualValue;
    112       var constantValue = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).Average();
    113       var constantSolution = CreateConstantSymbolicRegressionSolution(constantValue);
    114111
    115       int previousTreeLength = constantSolution.Model.SymbolicExpressionTree.Length;
     112      int previousTreeLength = -1;
    116113      var sizeParetoFront = new LinkedList<ISymbolicRegressionSolution>();
    117       sizeParetoFront.AddLast(constantSolution);
    118 
    119114      foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) {
    120115        int treeLength = solution.Model.SymbolicExpressionTree.Length;
     
    136131      qualityToTreeSize.Rows.Add(testRow);
    137132
    138       double trainingHyperVolume, testHyperVolume;
    139       CalculateNormalizedHyperVolume(sizeParetoFront, out trainingHyperVolume, out testHyperVolume);
     133      double trainingArea = sizeParetoFront.Select(s => s.Model.SymbolicExpressionTree.Length * s.TrainingNormalizedMeanSquaredError).Average();
     134      double testArea = sizeParetoFront.Select(s => s.Model.SymbolicExpressionTree.Length * s.TestNormalizedMeanSquaredError).Average();
    140135
    141       DoubleValue trainingHyperVolumeResult, testHyperVolumeResult;
    142       if (!ResultCollection.TryGetValue("HyperVolume training", out result)) {
    143         trainingHyperVolumeResult = new DoubleValue();
    144         ResultCollection.Add(new Result("HyperVolume training", trainingHyperVolumeResult));
    145       } else trainingHyperVolumeResult = (DoubleValue)result.Value;
     136      ResultCollection paretoFrontResults;
     137      if (!ResultCollection.TryGetValue("Pareto Front Results", out result)) {
     138        paretoFrontResults = new ResultCollection();
     139        ResultCollection.Add(new Result("Pareto Front Results", paretoFrontResults));
     140      } else paretoFrontResults = (ResultCollection)result.Value;
    146141
    147       if (!ResultCollection.TryGetValue("HyperVolume test", out result)) {
    148         testHyperVolumeResult = new DoubleValue();
    149         ResultCollection.Add(new Result("HyperVolume test", testHyperVolumeResult));
    150       } else testHyperVolumeResult = (DoubleValue)result.Value;
     142      DoubleValue trainingAreaResult, testAreaResult, areaDifferenceResult, avgTrainingNMSE, avgTestNMSE;
     143      if (!paretoFrontResults.TryGetValue("Non Dominated Area (training)", out result)) {
     144        trainingAreaResult = new DoubleValue();
     145        paretoFrontResults.Add(new Result("Non Dominated Area (training)", trainingAreaResult));
     146      } else trainingAreaResult = (DoubleValue)result.Value;
     147      if (!paretoFrontResults.TryGetValue("Non Dominated Area (test)", out result)) {
     148        testAreaResult = new DoubleValue();
     149        paretoFrontResults.Add(new Result("Non Dominated Area (test)", testAreaResult));
     150      } else testAreaResult = (DoubleValue)result.Value;
     151      if (!paretoFrontResults.TryGetValue("Non Dominated Area Difference", out result)) {
     152        areaDifferenceResult = new DoubleValue();
     153        paretoFrontResults.Add(new Result("Non Dominated Area Difference", areaDifferenceResult));
     154      } else areaDifferenceResult = (DoubleValue)result.Value;
     155      if (!paretoFrontResults.TryGetValue("Average Training NMSE", out result)) {
     156        avgTrainingNMSE = new DoubleValue();
     157        paretoFrontResults.Add(new Result("Average Training NMSE", avgTrainingNMSE));
     158      } else avgTrainingNMSE = (DoubleValue)result.Value;
     159      if (!paretoFrontResults.TryGetValue("Average Test NMSE", out result)) {
     160        avgTestNMSE = new DoubleValue();
     161        paretoFrontResults.Add(new Result("Average Test NMSE", avgTestNMSE));
     162      } else avgTestNMSE = (DoubleValue)result.Value;
    151163
    152       trainingHyperVolumeResult.Value = trainingHyperVolume;
    153       testHyperVolumeResult.Value = testHyperVolume;
     164      trainingAreaResult.Value = trainingArea;
     165      testAreaResult.Value = testArea;
     166      areaDifferenceResult.Value = trainingArea - testArea;
     167      avgTrainingNMSE.Value = sizeParetoFront.Select(s => s.TrainingNormalizedMeanSquaredError).Average();
     168      avgTestNMSE.Value = sizeParetoFront.Select(s => s.TestNormalizedMeanSquaredError).Average();
    154169
    155170      return operation;
    156171    }
    157172
    158     private void CalculateNormalizedHyperVolume(IEnumerable<ISymbolicRegressionSolution> solutions, out double trainingHyperVolume, out double testHyperVolume) {
    159       trainingHyperVolume = 0.0;
    160       testHyperVolume = 0.0;
    161 
    162       var prevX = 0;
    163       var prevYTraining = 1.0;
    164       var prevYTest = 1.0;
    165       var treeSize = 0;
    166 
    167       foreach (var solution in solutions) {
    168         treeSize = solution.Model.SymbolicExpressionTree.Length;
    169         trainingHyperVolume += (prevYTraining + solution.TrainingNormalizedMeanSquaredError) * (treeSize - prevX) / 2;
    170         testHyperVolume += (prevYTest + solution.TestNormalizedMeanSquaredError) * (treeSize - prevX) / 2;
    171         prevX = treeSize;
    172         prevYTraining = solution.TrainingNormalizedMeanSquaredError;
    173         prevYTest = solution.TestNormalizedMeanSquaredError;
    174       }
    175 
    176       trainingHyperVolume = trainingHyperVolume / treeSize;
    177       testHyperVolume = testHyperVolume / treeSize;
    178     }
    179 
    180     private ISymbolicRegressionSolution CreateConstantSymbolicRegressionSolution(double constantValue) {
    181       var grammar = new ArithmeticExpressionGrammar();
    182       var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
    183       var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode();
    184       var constantTreeNode = new ConstantTreeNode(new Constant()) { Value = constantValue };
    185       rootNode.AddSubtree(startNode);
    186       startNode.AddSubtree(constantTreeNode);
    187       var tree = new SymbolicExpressionTree();
    188       tree.Root = rootNode;
    189 
    190       var model = new SymbolicRegressionModel(tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue);
    191       var solution = new SymbolicRegressionSolution(model, ProblemDataParameter.ActualValue);
    192       return solution;
    193     }
    194173  }
    195174}
Note: See TracChangeset for help on using the changeset viewer.