Free cookie consent management tool by TermsFeed Policy Generator

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

Added ApplyScalingParameter to RegressionAnalyzers (ticket #1369).

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic
Files:
3 edited

Legend:

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

    r5246 r5331  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Analysis;
    2523using HeuristicLab.Common;
     
    2725using HeuristicLab.Data;
    2826using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Operators;
    3027using HeuristicLab.Optimization;
    3128using HeuristicLab.Parameters;
     
    4037  [StorableClass]
    4138  public sealed class FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer : SymbolicRegressionValidationAnalyzer, ISymbolicRegressionAnalyzer {
     39    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4240    private const string MaximizationParameterName = "Maximization";
    4341    private const string CalculateSolutionComplexityParameterName = "CalculateSolutionComplexity";
     
    8482      get { return (ILookupParameter<DataTable>)Parameters[VariableFrequenciesParameterName]; }
    8583    }
    86 
     84    public IValueLookupParameter<BoolValue> ApplyLinearScalingParameter {
     85      get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     86    }
    8787    #endregion
    8888    #region properties
     
    114114      set { BestSolutionHeightParameter.ActualValue = value; }
    115115    }
    116 
     116    public BoolValue ApplyLinearScaling {
     117      get { return ApplyLinearScalingParameter.ActualValue; }
     118      set { ApplyLinearScalingParameter.ActualValue = value; }
     119    }
    117120    #endregion
    118121
     
    122125    public FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer()
    123126      : base() {
     127      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)));
    124128      Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
    125       Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the validation best solution should be calculated.", new BoolValue(false)));
     129      Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the validation best solution should be calculated.", new BoolValue(true)));
    126130      Parameters.Add(new LookupParameter<SymbolicRegressionSolution>(BestSolutionParameterName, "The best symbolic regression solution."));
    127131      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations calculated so far."));
     
    155159      if (!Parameters.ContainsKey(BestSolutionHeightParameterName)) {
    156160        Parameters.Add(new LookupParameter<IntValue>(BestSolutionHeightParameterName, "The height of the best symbolic regression solution."));
     161      }
     162      if (!Parameters.ContainsKey(ApplyLinearScalingParameterName)) {
     163        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)));
    157164      }
    158165      #endregion
     
    182189        string targetVariable = ProblemData.TargetVariable.Value;
    183190
    184         // calculate scaling parameters and only for the best tree using the full training set
    185         double alpha, beta;
    186         SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree,
    187           lowerEstimationLimit, upperEstimationLimit,
    188           ProblemData.Dataset, targetVariable,
    189           ProblemData.TrainingIndizes, out beta, out alpha);
    190 
    191         // scale tree for solution
    192         var scaledTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta);
     191        if (ApplyLinearScaling.Value) {
     192          // calculate scaling parameters and only for the best tree using the full training set
     193          double alpha, beta;
     194          SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree,
     195            lowerEstimationLimit, upperEstimationLimit,
     196            ProblemData.Dataset, targetVariable,
     197            ProblemData.TrainingIndizes, out beta, out alpha);
     198
     199          // scale tree for solution
     200          bestTree = SymbolicRegressionSolutionLinearScaler.Scale(bestTree, alpha, beta);
     201        }
    193202        var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(),
    194           scaledTree);
     203          bestTree);
    195204        var solution = new SymbolicRegressionSolution((DataAnalysisProblemData)ProblemData.Clone(), model, lowerEstimationLimit, upperEstimationLimit);
    196205        solution.Name = BestSolutionParameterName;
  • 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;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r5260 r5331  
    148148      AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
    149149      AddOperator(new SymbolicRegressionOverfittingAnalyzer());
     150      AddOperator(new TrainingBestScaledSymbolicRegressionSolutionAnalyzer());
    150151      ParameterizeAnalyzers();
    151152    }
Note: See TracChangeset for help on using the changeset viewer.