Changeset 9363 for branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective
- Timestamp:
- 04/16/13 13:13:41 (12 years ago)
- Location:
- branches/OaaS
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 23 24 packages
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
-
branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4
- Property svn:ignore
-
old new 1 *.user 2 Plugin.cs 1 3 bin 2 *.user3 HeuristicLabProblemsDataAnalysisSymbolicClassificationPlugin.cs4 4 obj 5 *.vs10x6 Plugin.cs
-
- Property svn:ignore
-
branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r7259 r9363 65 65 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context; 66 66 EstimationLimitsParameter.ExecutionContext = context; 67 ApplyLinearScalingParameter.ExecutionContext = context; 67 68 68 69 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows); … … 70 71 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 71 72 EstimationLimitsParameter.ExecutionContext = null; 73 ApplyLinearScalingParameter.ExecutionContext = null; 72 74 73 75 return quality; -
branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r6740 r9363 1 using System.Collections.Generic; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System.Collections.Generic; 2 23 using HeuristicLab.Common; 3 24 using HeuristicLab.Core; … … 26 47 IEnumerable<int> rows = GenerateRowsToEvaluate(); 27 48 var solution = SymbolicExpressionTreeParameter.ActualValue; 28 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows );49 double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value); 29 50 QualitiesParameter.ActualValue = new DoubleArray(qualities); 30 51 return base.Apply(); 31 52 } 32 53 33 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) { 34 55 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 35 IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);56 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 36 57 OnlineCalculatorError errorState; 37 double r2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState); 38 if (errorState != OnlineCalculatorError.None) r2 = 0.0; 39 return new double[] { r2, solution.Length }; 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 70 if (errorState != OnlineCalculatorError.None) r2 = double.NaN; 71 return new double[2] { r2, solution.Length }; 40 72 41 73 } … … 45 77 EstimationLimitsParameter.ExecutionContext = context; 46 78 47 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows );79 double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value); 48 80 49 81 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs
r8175 r9363 36 36 private const string EstimationLimitsParameterName = "EstimationLimits"; 37 37 private const string EstimationLimitsParameterDescription = "The lower and upper limit for the estimated value that can be returned by the symbolic classification model."; 38 private const string ModelCreatorParameterName = "ModelCreator"; 39 38 40 39 41 #region parameter properties … … 41 43 get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 42 44 } 45 public IValueParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 46 get { return (IValueParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 47 } 43 48 #endregion 44 49 #region properties 45 50 public DoubleLimit EstimationLimits { 46 51 get { return EstimationLimitsParameter.Value; } 52 } 53 public ISymbolicClassificationModelCreator ModelCreator { 54 get { return ModelCreatorParameter.Value; } 47 55 } 48 56 #endregion … … 58 66 : base(new ClassificationProblemData(), new SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) { 59 67 Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription)); 68 Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator())); 60 69 70 ApplyLinearScalingParameter.Value.Value = false; 61 71 EstimationLimitsParameter.Hidden = true; 62 72 … … 74 84 [StorableHook(HookType.AfterDeserialization)] 75 85 private void AfterDeserialization() { 86 // BackwardsCompatibility3.4 87 #region Backwards compatible code, remove with 3.5 88 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 89 Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator())); 90 #endregion 76 91 RegisterEventHandlers(); 77 92 } … … 79 94 private void RegisterEventHandlers() { 80 95 SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols(); 96 ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators(); 81 97 } 82 98 … … 110 126 } 111 127 112 protected newvoid ParameterizeOperators() {128 protected override void ParameterizeOperators() { 113 129 base.ParameterizeOperators(); 114 130 if (Parameters.ContainsKey(EstimationLimitsParameterName)) { 115 131 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators); 116 foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) { 117 op.EstimationLimitsParameter.ActualName = EstimationLimitsParameterName; 118 } 132 foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) 133 op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name; 134 foreach (var op in operators.OfType<ISymbolicClassificationModelCreatorOperator>()) 135 op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name; 119 136 } 120 137 } -
branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r7259 r9363 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 25 using HeuristicLab.Parameters; … … 34 33 [StorableClass] 35 34 public sealed class SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>, 36 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {35 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator { 37 36 private const string ProblemDataParameterName = "ProblemData"; 37 private const string ModelCreatorParameterName = "ModelCreator"; 38 38 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 39 39 private const string EstimationLimitsParameterName = "EstimationLimits"; 40 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";41 40 42 41 #region parameter properties 43 42 public ILookupParameter<IClassificationProblemData> ProblemDataParameter { 44 43 get { return (ILookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; } 44 } 45 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 46 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 47 } 48 ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter { 49 get { return ModelCreatorParameter; } 45 50 } 46 51 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { … … 49 54 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter { 50 55 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 51 }52 public IValueParameter<BoolValue> ApplyLinearScalingParameter {53 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }54 }55 #endregion56 57 #region properties58 public BoolValue ApplyLinearScaling {59 get { return ApplyLinearScalingParameter.Value; }60 56 } 61 57 #endregion … … 67 63 : base() { 68 64 Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution.")); 65 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 69 66 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 70 67 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model.")); 71 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));72 68 } 73 69 public override IDeepCloneable Clone(Cloner cloner) { … … 75 71 } 76 72 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 } 81 77 82 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) { 78 var model = new SymbolicDiscriminantFunctionClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);79 if (ApplyLinearScaling .Value) {80 SymbolicDiscriminantFunctionClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 81 }82 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()); 83 88 } 84 89 } -
branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs
r7259 r9363 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 25 using HeuristicLab.Parameters; … … 34 33 [StorableClass] 35 34 public sealed class SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationMultiObjectiveEvaluator, IClassificationProblemData>, 36 ISymbolicDataAnalysisBoundedOperator { 35 ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator { 36 private const string ModelCreatorParameterName = "ModelCreator"; 37 37 private const string EstimationLimitsParameterName = "EstimationLimits"; 38 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";39 38 40 39 #region parameter properties … … 42 41 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 43 42 } 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; } 46 48 } 47 49 #endregion 48 50 49 #region properties50 public BoolValue ApplyLinearScaling {51 get { return ApplyLinearScalingParameter.Value; }52 }53 #endregion54 51 [StorableConstructor] 55 52 private SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 58 55 : base() { 59 56 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The loewr and upper limit for the estimated values produced by the symbolic classification model.")); 60 Parameters.Add(new Value Parameter<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, "")); 61 58 } 62 59 public override IDeepCloneable Clone(Cloner cloner) { … … 64 61 } 65 62 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 66 72 protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQualities) { 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()); 72 78 } 73 79 }
Note: See TracChangeset
for help on using the changeset viewer.