Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/11/11 15:03:46 (14 years ago)
Author:
gkronber
Message:

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Analyzers/RegressionSolutionAnalyzer.cs

    r4308 r5275  
    2121
    2222using System.Collections.Generic;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
     
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930using HeuristicLab.Problems.DataAnalysis.Evaluators;
    30 using HeuristicLab.Analysis;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
     
    9090    #endregion
    9191
     92
     93    [StorableConstructor]
     94    protected RegressionSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     95    protected RegressionSolutionAnalyzer(RegressionSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    9296    public RegressionSolutionAnalyzer()
    9397      : base() {
     
    102106
    103107    [StorableHook(HookType.AfterDeserialization)]
    104     private void Initialize() {
     108    private void AfterDeserialization() {
    105109      // backwards compatibility
    106110      if (!Parameters.ContainsKey(GenerationsParameterName)) {
     
    119123    }
    120124
    121     public static void UpdateBestSolutionResults(DataAnalysisSolution bestSolution, DataAnalysisProblemData problemData, ResultCollection results, IntValue CurrentGeneration) {
    122       var solution = bestSolution;
     125    public static void UpdateBestSolutionResults(DataAnalysisSolution solution, DataAnalysisProblemData problemData, ResultCollection results, IntValue generation) {
    123126      #region update R2,MSE, Rel Error
    124       IEnumerable<double> trainingValues = problemData.Dataset.GetEnumeratedVariableValues(
    125         problemData.TargetVariable.Value,
    126         problemData.TrainingSamplesStart.Value,
    127         problemData.TrainingSamplesEnd.Value);
    128       IEnumerable<double> testValues = problemData.Dataset.GetEnumeratedVariableValues(
    129         problemData.TargetVariable.Value,
    130         problemData.TestSamplesStart.Value,
    131         problemData.TestSamplesEnd.Value);
     127      IEnumerable<double> trainingValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, problemData.TrainingIndizes);
     128      IEnumerable<double> testValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, problemData.TestIndizes);
    132129      OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();
    133130      OnlineMeanAbsolutePercentageErrorEvaluator relErrorEvaluator = new OnlineMeanAbsolutePercentageErrorEvaluator();
    134131      OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator();
     132
    135133      #region training
    136134      var originalEnumerator = trainingValues.GetEnumerator();
     
    145143      double trainingRelError = relErrorEvaluator.MeanAbsolutePercentageError;
    146144      #endregion
     145
    147146      mseEvaluator.Reset();
    148147      relErrorEvaluator.Reset();
    149148      r2Evaluator.Reset();
     149
    150150      #region test
    151151      originalEnumerator = testValues.GetEnumerator();
     
    160160      double testRelError = relErrorEvaluator.MeanAbsolutePercentageError;
    161161      #endregion
     162
    162163      if (results.ContainsKey(BestSolutionResultName)) {
    163164        results[BestSolutionResultName].Value = solution;
     
    168169        results[BestSolutionTrainingRelativeError].Value = new DoubleValue(trainingRelError);
    169170        results[BestSolutionTestRelativeError].Value = new DoubleValue(testRelError);
    170         if (CurrentGeneration != null) // this check is needed because linear regression solutions do not have a generations parameter
    171           results[BestSolutionGeneration].Value = new IntValue(CurrentGeneration.Value);
    172         var solutionQualityTable = (DataTable)results["Best solution quality table"].Value;
    173         solutionQualityTable.Rows["Training R²"].Values.Add(trainingR2);
    174         solutionQualityTable.Rows["Training MSE"].Values.Add(trainingMse);
    175         solutionQualityTable.Rows["Test R²"].Values.Add(testR2);
    176         solutionQualityTable.Rows["Test MSE"].Values.Add(testMse);
     171        if (generation != null) // this check is needed because linear regression solutions do not have a generations parameter
     172          results[BestSolutionGeneration].Value = new IntValue(generation.Value);
    177173      } else {
    178174        results.Add(new Result(BestSolutionResultName, solution));
     
    183179        results.Add(new Result(BestSolutionTrainingRelativeError, new DoubleValue(trainingRelError)));
    184180        results.Add(new Result(BestSolutionTestRelativeError, new DoubleValue(testRelError)));
    185         if (CurrentGeneration != null)
    186           results.Add(new Result(BestSolutionGeneration, new IntValue(CurrentGeneration.Value)));
    187         var solutionQualityTable = new DataTable("Best solution quality table");
    188         solutionQualityTable.Rows.Add(new DataRow("Training R²"));
    189         solutionQualityTable.Rows.Add(new DataRow("Training MSE"));
    190         solutionQualityTable.Rows.Add(new DataRow("Test R²"));
    191         solutionQualityTable.Rows.Add(new DataRow("Test MSE"));
    192         solutionQualityTable.Rows["Training R²"].Values.Add(trainingR2);
    193         solutionQualityTable.Rows["Training MSE"].Values.Add(trainingMse);
    194         solutionQualityTable.Rows["Test R²"].Values.Add(testR2);
    195         solutionQualityTable.Rows["Test MSE"].Values.Add(testMse);
    196         results.Add(new Result("Best solution quality table", solutionQualityTable));
     181        if (generation != null)
     182          results.Add(new Result(BestSolutionGeneration, new IntValue(generation.Value)));
    197183      }
    198184      #endregion
Note: See TracChangeset for help on using the changeset viewer.