Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/13 13:13:41 (12 years ago)
Author:
spimming
Message:

#1888:

  • Merged revisions from trunk
Location:
branches/OaaS
Files:
11 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/OaaS

  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4

    • Property svn:ignore
      •  

        old new  
         1*.user
         2Plugin.cs
        13bin
        2 *.user
        3 HeuristicLabProblemsDataAnalysisSymbolicClassificationPlugin.cs
        44obj
        5 *.vs10x
        6 Plugin.cs
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs

    r7259 r9363  
    4747      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4848      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     49      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5050      QualityParameter.ActualValue = new DoubleValue(quality);
    5151      return base.Apply();
    5252    }
    5353
    54     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     54    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5555      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     56      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     57      OnlineCalculatorError errorState;
    5858
    59       double minClassValue = problemData.ClassValues.OrderBy(x => x).First();
    60       double maxClassValue = problemData.ClassValues.OrderBy(x => x).Last();
     59      double lowestClassValue = problemData.ClassValues.OrderBy(x => x).First();
     60      double upmostClassValue = problemData.ClassValues.OrderByDescending(x => x).First();
    6161
    62       IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
    63       IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    64       double errorSum = 0.0;
    65       int n = 0;
    66 
    67       // always move forward both enumerators (do not use short-circuit evaluation!)
    68       while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
    69         double estimated = estimatedEnumerator.Current;
    70         double original = originalEnumerator.Current;
    71         double error = estimated - original;
    72 
    73         if (estimated < minClassValue || estimated > maxClassValue)
    74           errorSum += Math.Abs(error);
    75         else
    76           errorSum += Math.Pow(error, 2);
    77         n++;
     62      double boundedMse;
     63      if (applyLinearScaling) {
     64        var boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowestClassValue, upmostClassValue);
     65        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, boundedMseCalculator, problemData.Dataset.Rows);
     66        errorState = boundedMseCalculator.ErrorState;
     67        boundedMse = boundedMseCalculator.BoundedMeanSquaredError;
     68      } else {
     69        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     70        boundedMse = OnlineBoundedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, lowestClassValue, upmostClassValue, out errorState);
    7871      }
    79 
    80       // check if both enumerators are at the end to make sure both enumerations have the same length
    81       if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) {
    82         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    83       } else {
    84         return errorSum / n;
    85       }
     72      if (errorState != OnlineCalculatorError.None) return Double.NaN;
     73      return boundedMse;
    8674    }
    8775
     
    8977      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    9078      EstimationLimitsParameter.ExecutionContext = context;
     79      ApplyLinearScalingParameter.ExecutionContext = context;
    9180
    92       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     81      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    9382
    9483      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    9584      EstimationLimitsParameter.ExecutionContext = null;
     85      ApplyLinearScalingParameter.ExecutionContext = null;
    9686
    9787      return mse;
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7259 r9363  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    4748      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4849      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     50      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5051      QualityParameter.ActualValue = new DoubleValue(quality);
    5152      return base.Apply();
    5253    }
    5354
    54     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     55    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5556      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     57      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5858      OnlineCalculatorError errorState;
    59       double mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState);
    60       if (errorState != OnlineCalculatorError.None) return double.NaN;
    61       else return mse;
     59
     60      double mse;
     61      if (applyLinearScaling) {
     62        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
     63        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows);
     64        errorState = mseCalculator.ErrorState;
     65        mse = mseCalculator.MeanSquaredError;
     66      } else {
     67        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     68        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     69      }
     70      if (errorState != OnlineCalculatorError.None) return Double.NaN;
     71      return mse;
    6272    }
    6373
     
    6575      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6676      EstimationLimitsParameter.ExecutionContext = context;
     77      ApplyLinearScalingParameter.ExecutionContext = context;
    6778
    68       double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     79      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    6980
    7081      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7182      EstimationLimitsParameter.ExecutionContext = null;
     83      ApplyLinearScalingParameter.ExecutionContext = null;
    7284
    7385      return mse;
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs

    r7259 r9363  
    4747      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4848      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     49      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
    5050      QualityParameter.ActualValue = new DoubleValue(quality);
    5151      return base.Apply();
    5252    }
    5353
    54     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
     54    public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    5555      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     56      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    5757      OnlineCalculatorError errorState;
    58       double r2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState);
    59       if (errorState != OnlineCalculatorError.None) return 0.0;
    60       else return r2;
     58
     59      double r2;
     60      if (applyLinearScaling) {
     61        var r2Calculator = new OnlinePearsonsRSquaredCalculator();
     62        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
     63        errorState = r2Calculator.ErrorState;
     64        r2 = r2Calculator.RSquared;
     65      } else {
     66        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     67        r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     68      }
     69      if (errorState != OnlineCalculatorError.None) return double.NaN;
     70      return r2;
    6171    }
    6272
     
    6474      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    6575      EstimationLimitsParameter.ExecutionContext = context;
     76      ApplyLinearScalingParameter.ExecutionContext = context;
    6677
    67       double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     78      double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
    6879
    6980      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7081      EstimationLimitsParameter.ExecutionContext = null;
     82      ApplyLinearScalingParameter.ExecutionContext = null;
    7183
    7284      return r2;
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r8175 r9363  
    3535    private const string EstimationLimitsParameterName = "EstimationLimits";
    3636    private const string EstimationLimitsParameterDescription = "The lower and upper limit for the estimated value that can be returned by the symbolic classification model.";
     37    private const string ModelCreatorParameterName = "ModelCreator";
    3738
    3839    #region parameter properties
     
    4041      get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    4142    }
     43    public IValueParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     44      get { return (IValueParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     45    }
    4246    #endregion
    4347    #region properties
    4448    public DoubleLimit EstimationLimits {
    4549      get { return EstimationLimitsParameter.Value; }
     50    }
     51    public ISymbolicClassificationModelCreator ModelCreator {
     52      get { return ModelCreatorParameter.Value; }
    4653    }
    4754    #endregion
     
    5764      : base(new ClassificationProblemData(), new SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
    5865      Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
     66      Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
    5967
     68      ApplyLinearScalingParameter.Value.Value = false;
    6069      EstimationLimitsParameter.Hidden = true;
    6170
     
    7180    [StorableHook(HookType.AfterDeserialization)]
    7281    private void AfterDeserialization() {
    73       RegisterEventHandlers();
    74       // compatibility
     82      // BackwardsCompatibility3.4
     83      #region Backwards compatible code, remove with 3.5
     84      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     85        Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
     86
    7587      bool changed = false;
    7688      if (!Operators.OfType<SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer>().Any()) {
     
    8395      }
    8496      if (changed) ParameterizeOperators();
     97      #endregion
     98      RegisterEventHandlers();
    8599    }
    86100
    87101    private void RegisterEventHandlers() {
    88102      SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
     103      ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators();
    89104    }
    90105
     
    125140      if (Parameters.ContainsKey(EstimationLimitsParameterName)) {
    126141        var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
    127         foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) {
     142        foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>())
    128143          op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name;
    129         }
     144        foreach (var op in operators.OfType<ISymbolicClassificationModelCreatorOperator>())
     145          op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name;
    130146      }
    131147    }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r9363  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3433  [StorableClass]
    3534  public sealed class SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>,
    36     ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
     35    ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
    3736    private const string ProblemDataParameterName = "ProblemData";
     37    private const string ModelCreatorParameterName = "ModelCreator";
    3838    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3939    private const string EstimationLimitsParameterName = "UpperEstimationLimit";
    40     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    4140    #region parameter properties
    4241    public ILookupParameter<IClassificationProblemData> ProblemDataParameter {
    4342      get { return (ILookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; }
     43    }
     44    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     45      get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     46    }
     47    ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter {
     48      get { return ModelCreatorParameter; }
    4449    }
    4550    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
     
    4954      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    5055    }
    51     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    52       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
    53     }
    5456    #endregion
    55     #region properties
    56     public BoolValue ApplyLinearScaling {
    57       get { return ApplyLinearScalingParameter.Value; }
    58     }
    59     #endregion
     57
    6058
    6159    [StorableConstructor]
     
    6563      : base() {
    6664      Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution."));
     65      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6766      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    6867      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
    69       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    7068    }
     69
    7170    public override IDeepCloneable Clone(Cloner cloner) {
    7271      return new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer(this, cloner);
    7372    }
     73    [StorableHook(HookType.AfterDeserialization)]
     74    private void AfterDeserialization() {
     75      // BackwardsCompatibility3.4
     76      #region Backwards compatible code, remove with 3.5
     77      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     78        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     79      #endregion
     80    }
    7481
    7582    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    76       var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    77       if (ApplyLinearScaling.Value) {
    78         SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
    79       }
    80       return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
     83      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     84      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
     85
     86      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
     87      return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
    8188    }
    8289  }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r8169 r9363  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3332  [Item("SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer", "An operator that collects the training Pareto-best symbolic classification solutions for single objective symbolic classification problems.")]
    3433  [StorableClass]
    35   public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution> {
    36     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     34  public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution>, ISymbolicClassificationModelCreatorOperator {
     35    private const string ModelCreatorParameterName = "ModelCreator";
    3736    #region parameter properties
    38     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    39       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     37    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     38      get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
    4039    }
    41     #endregion
    42 
    43     #region properties
    44     public BoolValue ApplyLinearScaling {
    45       get { return ApplyLinearScalingParameter.Value; }
     40    ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter {
     41      get { return ModelCreatorParameter; }
    4642    }
    4743    #endregion
     
    5248    public SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer()
    5349      : base() {
    54       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
     50      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    5551    }
    5652    public override IDeepCloneable Clone(Cloner cloner) {
     
    5854    }
    5955
     56    [StorableHook(HookType.AfterDeserialization)]
     57    private void AfterDeserialization() {
     58      // BackwardsCompatibility3.4
     59      #region Backwards compatible code, remove with 3.5
     60      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     61        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     62      #endregion
     63    }
     64
    6065    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    61       var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    62       if (ApplyLinearScaling.Value)
    63         SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
    64       return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
     66      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     67      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
     68
     69      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
     70      return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
    6571    }
    6672  }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r9363  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3433  [StorableClass]
    3534  public sealed class SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>,
    36   ISymbolicDataAnalysisBoundedOperator {
     35  ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
    3736    private const string EstimationLimitsParameterName = "EstimationLimits";
    38     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     37    private const string ModelCreatorParameterName = "ModelCreator";
    3938
    4039    #region parameter properties
     
    4241      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    4342    }
    44     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    45       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     43    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     44      get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     45    }
     46    ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter {
     47      get { return ModelCreatorParameter; }
    4648    }
    4749    #endregion
    4850
    49     #region properties
    50     public BoolValue ApplyLinearScaling {
    51       get { return ApplyLinearScalingParameter.Value; }
    52     }
    53     #endregion
    5451    [StorableConstructor]
    5552    private SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     
    5855      : base() {
    5956      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
    60       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
     57      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6158    }
    6259    public override IDeepCloneable Clone(Cloner cloner) {
     
    6461    }
    6562
     63    [StorableHook(HookType.AfterDeserialization)]
     64    private void AfterDeserialization() {
     65      // BackwardsCompatibility3.4
     66      #region Backwards compatible code, remove with 3.5
     67      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     68        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     69      #endregion
     70    }
     71
    6672    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    67       var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    68       if (ApplyLinearScaling.Value) {
    69         SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
    70       }
    71       return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
     73      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     74      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
     75
     76      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
     77      return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
    7278    }
    7379  }
  • branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r8169 r9363  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2625using HeuristicLab.Parameters;
     
    3332  [Item("SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer", "An operator that collects the validation Pareto-best symbolic classification solutions for single objective symbolic classification problems.")]
    3433  [StorableClass]
    35   public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData> {
    36     private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     34  public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>, ISymbolicClassificationModelCreatorOperator {
     35    private const string ModelCreatorParameterName = "ModelCreator";
    3736    #region parameter properties
    38     public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    39       get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     37    public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     38      get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
    4039    }
    41     #endregion
    42 
    43     #region properties
    44     public BoolValue ApplyLinearScaling {
    45       get { return ApplyLinearScalingParameter.Value; }
     40    ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter {
     41      get { return ModelCreatorParameter; }
    4642    }
    4743    #endregion
     
    5248    public SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer()
    5349      : base() {
    54       Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
     50      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    5551    }
    5652    public override IDeepCloneable Clone(Cloner cloner) {
     
    5854    }
    5955
     56    [StorableHook(HookType.AfterDeserialization)]
     57    private void AfterDeserialization() {
     58      // BackwardsCompatibility3.4
     59      #region Backwards compatible code, remove with 3.5
     60      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     61        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     62      #endregion
     63    }
     64
    6065    protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    61       var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    62       if (ApplyLinearScaling.Value)
    63         SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue);
    64       return new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
     66      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     67      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
     68
     69      model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
     70      return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
    6571    }
    6672  }
Note: See TracChangeset for help on using the changeset viewer.