Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/19/11 15:07:45 (13 years ago)
Author:
mkommend
Message:

Added ApplyScalingParameter to RegressionAnalyzers (ticket #1369).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/TrainingBestScaledSymbolicRegressionSolutionAnalyzer.cs

    r5259 r5331  
    2222using System.Collections.Generic;
    2323using System.Linq;
    24 using HeuristicLab.Analysis;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    3130using HeuristicLab.Parameters;
    3231using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3333using HeuristicLab.Problems.DataAnalysis.Symbolic;
    34 using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3534
    3635namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
     
    4140  [StorableClass]
    4241  public sealed class TrainingBestScaledSymbolicRegressionSolutionAnalyzer : SingleSuccessorOperator, ISymbolicRegressionAnalyzer {
     42    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4343    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
    4444    private const string QualityParameterName = "Quality";
     
    128128      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
    129129    }
     130    public IValueLookupParameter<BoolValue> ApplyLinearScalingParameter {
     131      get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     132    }
    130133    #endregion
    131134    #region properties
     
    205208      get { return BestSolutionTestRelativeErrorParameter.ActualValue; }
    206209      set { BestSolutionTestRelativeErrorParameter.ActualValue = value; }
     210    }
     211    public BoolValue ApplyLinearScaling {
     212      get { return ApplyLinearScalingParameter.ActualValue; }
     213      set { ApplyLinearScalingParameter.ActualValue = value; }
    207214    }
    208215    #endregion
     
    213220    public TrainingBestScaledSymbolicRegressionSolutionAnalyzer()
    214221      : base() {
     222      Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyLinearScalingParameterName, "The switch determines if the best solution should be linearly scaled on the whole training set.", new BoolValue(true)));
    215223      Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
    216224      Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
    217225      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityParameterName, "The qualities of the symbolic expression trees to analyze."));
    218       Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the training best solution should be calculated.", new BoolValue(false)));
    219       Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionAccuracyParameterName, "Determines if the accuracy of the training best solution on the training and test set should be calculated.", new BoolValue(false)));
     226      Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the training best solution should be calculated.", new BoolValue(true)));
     227      Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionAccuracyParameterName, "Determines if the accuracy of the training best solution on the training and test set should be calculated.", new BoolValue(true)));
    220228      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used for the analysis of symbolic expression trees."));
    221229      Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data for which the symbolic expression tree is a solution."));
     
    241249
    242250    [StorableHook(HookType.AfterDeserialization)]
    243     private void AfterDeserialization() { }
     251    private void AfterDeserialization() {
     252      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     253        Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyLinearScalingParameterName, "The switch determines if the best solution should be linearly scaled on the whole training set.", new BoolValue(true)));
     254      }
     255    }
    244256
    245257    public override IOperation Apply() {
     
    269281        string targetVariable = ProblemData.TargetVariable.Value;
    270282
    271         // calculate scaling parameters and only for the best tree using the full training set
    272         double alpha, beta;
    273         SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree,
    274           lowerEstimationLimit, upperEstimationLimit,
    275           ProblemData.Dataset, targetVariable,
    276           ProblemData.TrainingIndizes, out beta, out alpha);
    277 
    278         // scale tree for solution
    279         var scaledTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta);
     283        if (ApplyLinearScaling.Value) {
     284          // calculate scaling parameters and only for the best tree using the full training set
     285          double alpha, beta;
     286          SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree,
     287            lowerEstimationLimit, upperEstimationLimit,
     288            ProblemData.Dataset, targetVariable,
     289            ProblemData.TrainingIndizes, out beta, out alpha);
     290
     291          // scale tree for solution
     292          bestTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta);
     293        }
    280294        var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(),
    281           scaledTree);
     295          bestTree);
    282296        var solution = new SymbolicRegressionSolution((DataAnalysisProblemData)ProblemData.Clone(), model, lowerEstimationLimit, upperEstimationLimit);
    283297        solution.Name = BestSolutionParameterName;
Note: See TracChangeset for help on using the changeset viewer.