Changeset 8660 for branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Timestamp:
- 09/14/12 18:58:15 (12 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 18 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification merged eligible /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification merged eligible /branches/Algorithms.GradientDescent/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5516-5520 /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 6917-7005 /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5815-6180 /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5060 /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5138-5162 /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 6828 /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 7787-8333 /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5370-5682 /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 6829-6865 /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5594-5752 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/GP-MoveOperators/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/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj
r8085 r8660 93 93 </PropertyGroup> 94 94 <ItemGroup> 95 <Reference Include="ALGLIB-3. 5.0, Version=3.5.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">96 <HintPath>..\..\bin\ALGLIB-3. 5.0.dll</HintPath>95 <Reference Include="ALGLIB-3.6.0, Version=3.6.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 96 <HintPath>..\..\bin\ALGLIB-3.6.0.dll</HintPath> 97 97 <Private>False</Private> 98 98 </Reference> … … 112 112 </ItemGroup> 113 113 <ItemGroup> 114 <Compile Include="Interfaces\ISymbolicClassificationModelCreatorOperator.cs" /> 115 <Compile Include="Interfaces\ISymbolicDiscriminantFunctionClassificationModelCreator.cs" /> 116 <Compile Include="Interfaces\ISymbolicClassificationModelCreator.cs" /> 114 117 <Compile Include="Interfaces\ISymbolicDiscriminantFunctionClassificationModel.cs" /> 118 <Compile Include="ModelCreators\AccuracyMaximizingThresholdsModelCreator.cs" /> 119 <Compile Include="ModelCreators\NearestNeighborModelCreator.cs" /> 120 <Compile Include="ModelCreators\NormalDistributedThresholdsModelCreator.cs" /> 115 121 <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 122 <Compile Include="SymbolicNearestNeighbourClassificationModel.cs" /> 116 123 <Compile Include="Plugin.cs" /> 124 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectivePenaltyScoreEvaluator.cs" /> 117 125 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs" /> 118 126 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveOverfittingAnalyzer.cs" /> … … 176 184 <Private>False</Private> 177 185 </ProjectReference> 186 <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj"> 187 <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project> 188 <Name>HeuristicLab.Common.Resources-3.3</Name> 189 </ProjectReference> 178 190 <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj"> 179 191 <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project> … … 246 258 --> 247 259 <PropertyGroup> 248 <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)260 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 249 261 set ProjectDir=$(ProjectDir) 250 262 set SolutionDir=$(SolutionDir) … … 253 265 call PreBuildEvent.cmd 254 266 </PreBuildEvent> 267 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 268 export ProjectDir=$(ProjectDir) 269 export SolutionDir=$(SolutionDir) 270 271 $SolutionDir/PreBuildEvent.sh 272 </PreBuildEvent> 255 273 </PropertyGroup> 256 274 </Project> -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicClassificationModel.cs
r7259 r8660 20 20 #endregion 21 21 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;22 using System.Collections.Generic; 23 23 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 24 24 public interface ISymbolicClassificationModel : IClassificationModel, ISymbolicDataAnalysisModel { 25 double LowerEstimationLimit { get; } 26 double UpperEstimationLimit { get; } 27 void RecalculateModelParameters(IClassificationProblemData problemData, IEnumerable<int> rows); 28 new ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData); 25 29 } 26 30 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicDiscriminantFunctionClassificationModel.cs
r7259 r8660 20 20 #endregion 21 21 22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;23 22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 24 23 public interface ISymbolicDiscriminantFunctionClassificationModel : IDiscriminantFunctionClassificationModel, ISymbolicClassificationModel { 25 double LowerEstimationLimit { get; } 26 double UpperEstimationLimit { get; } 24 27 25 } 28 26 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs
r8206 r8660 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 61 70 EstimationLimitsParameter.Hidden = true; … … 74 83 [StorableHook(HookType.AfterDeserialization)] 75 84 private void AfterDeserialization() { 85 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 86 Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator())); 76 87 RegisterEventHandlers(); 77 88 } … … 79 90 private void RegisterEventHandlers() { 80 91 SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols(); 92 ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators(); 81 93 } 82 94 … … 110 122 } 111 123 112 protected newvoid ParameterizeOperators() {124 protected override void ParameterizeOperators() { 113 125 base.ParameterizeOperators(); 114 126 if (Parameters.ContainsKey(EstimationLimitsParameterName)) { 115 127 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 } 128 foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) 129 op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name; 130 foreach (var op in operators.OfType<ISymbolicClassificationModelCreatorOperator>()) 131 op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name; 119 132 } 120 133 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r7259 r8660 34 34 [StorableClass] 35 35 public sealed class SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>, 36 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {36 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator { 37 37 private const string ProblemDataParameterName = "ProblemData"; 38 private const string ModelCreatorParameterName = "ModelCreator"; 38 39 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 39 40 private const string EstimationLimitsParameterName = "EstimationLimits"; … … 43 44 public ILookupParameter<IClassificationProblemData> ProblemDataParameter { 44 45 get { return (ILookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; } 46 } 47 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 48 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 49 } 50 ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter { 51 get { return ModelCreatorParameter; } 45 52 } 46 53 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { … … 67 74 : base() { 68 75 Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution.")); 76 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 69 77 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 70 78 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model.")); … … 75 83 } 76 84 85 [StorableHook(HookType.AfterDeserialization)] 86 private void AfterDeserialization() { 87 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 88 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 89 } 90 77 91 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());92 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 93 if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 94 95 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 96 return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 83 97 } 84 98 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs
r7259 r8660 34 34 [StorableClass] 35 35 public sealed class SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationMultiObjectiveEvaluator, IClassificationProblemData>, 36 ISymbolicDataAnalysisBoundedOperator { 36 ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator { 37 private const string ModelCreatorParameterName = "ModelCreator"; 37 38 private const string EstimationLimitsParameterName = "EstimationLimits"; 38 39 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; … … 44 45 public IValueParameter<BoolValue> ApplyLinearScalingParameter { 45 46 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 47 } 48 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 49 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 50 } 51 ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter { 52 get { return ModelCreatorParameter; } 46 53 } 47 54 #endregion … … 59 66 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The loewr and upper limit for the estimated values produced by the symbolic classification model.")); 60 67 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false))); 68 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 61 69 } 62 70 public override IDeepCloneable Clone(Cloner cloner) { … … 64 72 } 65 73 74 [StorableHook(HookType.AfterDeserialization)] 75 private void AfterDeserialization() { 76 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 77 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 78 } 79 66 80 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());81 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 82 if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 83 84 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 85 return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 72 86 } 73 87 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Plugin.cs.frame
r7675 r8660 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Classification","Provides classes to perform symbolic classification (single- or multiobjective).", "3.4. 2.$WCREV$")]28 [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Classification","Provides classes to perform symbolic classification (single- or multiobjective).", "3.4.3.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.ALGLIB", "3. 5")]30 [PluginDependency("HeuristicLab.ALGLIB", "3.6.0")] 31 31 [PluginDependency("HeuristicLab.Analysis", "3.3")] 32 32 [PluginDependency("HeuristicLab.Common", "3.3")] 33 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] 33 34 [PluginDependency("HeuristicLab.Collections", "3.3")] 34 35 [PluginDependency("HeuristicLab.Core", "3.3")] -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Properties/AssemblyInfo.cs.frame
r7259 r8660 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.4.0.0")] 55 [assembly: AssemblyFileVersion("3.4. 2.$WCREV$")]55 [assembly: AssemblyFileVersion("3.4.3.$WCREV$")] -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r8206 r8660 35 35 private const string EstimationLimitsParameterName = "EstimationLimits"; 36 36 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"; 37 38 38 39 #region parameter properties … … 40 41 get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 41 42 } 43 public IValueParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 44 get { return (IValueParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 45 } 42 46 #endregion 43 47 #region properties 44 48 public DoubleLimit EstimationLimits { 45 49 get { return EstimationLimitsParameter.Value; } 50 } 51 public ISymbolicClassificationModelCreator ModelCreator { 52 get { return ModelCreatorParameter.Value; } 46 53 } 47 54 #endregion … … 57 64 : base(new ClassificationProblemData(), new SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) { 58 65 Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription)); 66 Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator())); 59 67 60 68 EstimationLimitsParameter.Hidden = true; … … 71 79 [StorableHook(HookType.AfterDeserialization)] 72 80 private void AfterDeserialization() { 73 RegisterEventHandlers(); 74 // compatibility 81 82 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 83 Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator())); 84 75 85 bool changed = false; 76 86 if (!Operators.OfType<SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer>().Any()) { … … 83 93 } 84 94 if (changed) ParameterizeOperators(); 95 RegisterEventHandlers(); 85 96 } 86 97 87 98 private void RegisterEventHandlers() { 88 99 SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols(); 100 ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators(); 89 101 } 90 102 … … 125 137 if (Parameters.ContainsKey(EstimationLimitsParameterName)) { 126 138 var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators); 127 foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) {139 foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) 128 140 op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name; 129 } 141 foreach (var op in operators.OfType<ISymbolicClassificationModelCreatorOperator>()) 142 op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name; 130 143 } 131 144 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs
r7259 r8660 34 34 [StorableClass] 35 35 public sealed class SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>, 36 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {36 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator { 37 37 private const string ProblemDataParameterName = "ProblemData"; 38 private const string ModelCreatorParameterName = "ModelCreator"; 38 39 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 39 40 private const string EstimationLimitsParameterName = "UpperEstimationLimit"; … … 42 43 public ILookupParameter<IClassificationProblemData> ProblemDataParameter { 43 44 get { return (ILookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; } 45 } 46 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 47 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 48 } 49 ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter { 50 get { return ModelCreatorParameter; } 44 51 } 45 52 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter { … … 65 72 : base() { 66 73 Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution.")); 74 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 67 75 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 68 76 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model.")); 69 77 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false))); 70 78 } 79 71 80 public override IDeepCloneable Clone(Cloner cloner) { 72 81 return new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer(this, cloner); 73 82 } 83 [StorableHook(HookType.AfterDeserialization)] 84 private void AfterDeserialization() { 85 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 86 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 87 } 74 88 75 89 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());90 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 91 if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 92 93 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 94 return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 81 95 } 82 96 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
r8206 r8660 33 33 [Item("SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer", "An operator that collects the training Pareto-best symbolic classification solutions for single objective symbolic classification problems.")] 34 34 [StorableClass] 35 public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution> {35 public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution>, ISymbolicClassificationModelCreatorOperator { 36 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 37 private const string ModelCreatorParameterName = "ModelCreator"; 37 38 #region parameter properties 38 39 public IValueParameter<BoolValue> ApplyLinearScalingParameter { 39 40 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 41 } 42 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 43 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 44 } 45 ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter { 46 get { return ModelCreatorParameter; } 40 47 } 41 48 #endregion … … 53 60 : base() { 54 61 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false))); 62 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 55 63 } 56 64 public override IDeepCloneable Clone(Cloner cloner) { … … 58 66 } 59 67 68 [StorableHook(HookType.AfterDeserialization)] 69 private void AfterDeserialization() { 70 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 71 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 72 } 73 60 74 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()); 75 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 76 if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 77 78 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 79 return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 65 80 } 66 81 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs
r7259 r8660 34 34 [StorableClass] 35 35 public sealed class SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>, 36 ISymbolicDataAnalysisBoundedOperator {36 ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator { 37 37 private const string EstimationLimitsParameterName = "EstimationLimits"; 38 38 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 39 private const string ModelCreatorParameterName = "ModelCreator"; 39 40 40 41 #region parameter properties … … 44 45 public IValueParameter<BoolValue> ApplyLinearScalingParameter { 45 46 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 47 } 48 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 49 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 50 } 51 ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter { 52 get { return ModelCreatorParameter; } 46 53 } 47 54 #endregion … … 59 66 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model.")); 60 67 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false))); 68 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 61 69 } 62 70 public override IDeepCloneable Clone(Cloner cloner) { … … 64 72 } 65 73 74 [StorableHook(HookType.AfterDeserialization)] 75 private void AfterDeserialization() { 76 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 77 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 78 } 79 66 80 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());81 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 82 if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 83 84 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 85 return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 72 86 } 73 87 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs
r8206 r8660 33 33 [Item("SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer", "An operator that collects the validation Pareto-best symbolic classification solutions for single objective symbolic classification problems.")] 34 34 [StorableClass] 35 public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData> {35 public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>, ISymbolicClassificationModelCreatorOperator { 36 36 private const string ApplyLinearScalingParameterName = "ApplyLinearScaling"; 37 private const string ModelCreatorParameterName = "ModelCreator"; 37 38 #region parameter properties 38 39 public IValueParameter<BoolValue> ApplyLinearScalingParameter { 39 40 get { return (IValueParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; } 41 } 42 public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 43 get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 44 } 45 ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter { 46 get { return ModelCreatorParameter; } 40 47 } 41 48 #endregion … … 53 60 : base() { 54 61 Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false))); 62 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 55 63 } 56 64 public override IDeepCloneable Clone(Cloner cloner) { … … 58 66 } 59 67 68 [StorableHook(HookType.AfterDeserialization)] 69 private void AfterDeserialization() { 70 if (!Parameters.ContainsKey(ModelCreatorParameterName)) 71 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "")); 72 } 73 60 74 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()); 75 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper); 76 if (ApplyLinearScaling.Value) SymbolicClassificationModel.Scale(model, ProblemDataParameter.ActualValue); 77 78 model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices); 79 return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 65 80 } 66 81 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs
r7259 r8660 32 32 [StorableClass] 33 33 [Item(Name = "SymbolicClassificationModel", Description = "Represents a symbolic classification model.")] 34 public class SymbolicClassificationModel : SymbolicDataAnalysisModel, ISymbolicClassificationModel { 34 public abstract class 35 SymbolicClassificationModel : SymbolicDataAnalysisModel, ISymbolicClassificationModel { 36 [Storable] 37 private double lowerEstimationLimit; 38 public double LowerEstimationLimit { get { return lowerEstimationLimit; } } 39 [Storable] 40 private double upperEstimationLimit; 41 public double UpperEstimationLimit { get { return upperEstimationLimit; } } 42 35 43 [StorableConstructor] 36 44 protected SymbolicClassificationModel(bool deserializing) : base(deserializing) { } 37 45 protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner) 38 46 : base(original, cloner) { 47 lowerEstimationLimit = original.lowerEstimationLimit; 48 upperEstimationLimit = original.upperEstimationLimit; 39 49 } 40 p ublic SymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter)50 protected SymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 41 51 : base(tree, interpreter) { 52 this.lowerEstimationLimit = lowerEstimationLimit; 53 this.upperEstimationLimit = upperEstimationLimit; 42 54 } 43 55 44 public override IDeepCloneable Clone(Cloner cloner) { 45 return new SymbolicClassificationModel(this, cloner); 46 } 56 public abstract IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows); 57 public abstract void RecalculateModelParameters(IClassificationProblemData problemData, IEnumerable<int> rows); 47 58 48 public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) { 49 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows); 50 } 59 public abstract ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData); 51 60 52 public ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {53 return new SymbolicClassificationSolution(this, problemData);54 }55 61 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) { 56 62 return CreateClassificationSolution(problemData); 57 63 } 58 64 65 #region scaling 66 public static void Scale(ISymbolicClassificationModel model, IClassificationProblemData problemData) { 67 var dataset = problemData.Dataset; 68 var targetVariable = problemData.TargetVariable; 69 var rows = problemData.TrainingIndices; 70 var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows); 71 var targetValues = dataset.GetDoubleValues(targetVariable, rows); 72 double alpha; 73 double beta; 74 OnlineCalculatorError errorState; 75 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState); 76 if (errorState != OnlineCalculatorError.None) return; 59 77 78 ConstantTreeNode alphaTreeNode = null; 79 ConstantTreeNode betaTreeNode = null; 80 // check if model has been scaled previously by analyzing the structure of the tree 81 var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0); 82 if (startNode.GetSubtree(0).Symbol is Addition) { 83 var addNode = startNode.GetSubtree(0); 84 if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) { 85 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode; 86 var mulNode = addNode.GetSubtree(0); 87 if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) { 88 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode; 89 } 90 } 91 } 92 // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes 93 if (alphaTreeNode != null && betaTreeNode != null) { 94 betaTreeNode.Value *= beta; 95 alphaTreeNode.Value *= beta; 96 alphaTreeNode.Value += alpha; 97 } else { 98 var mainBranch = startNode.GetSubtree(0); 99 startNode.RemoveSubtree(0); 100 var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha); 101 startNode.AddSubtree(scaledMainBranch); 102 } 103 } 104 105 private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) { 106 if (alpha.IsAlmost(0.0)) { 107 return treeNode; 108 } else { 109 var addition = new Addition(); 110 var node = addition.CreateTreeNode(); 111 var alphaConst = MakeConstant(alpha); 112 node.AddSubtree(treeNode); 113 node.AddSubtree(alphaConst); 114 return node; 115 } 116 } 117 118 private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) { 119 if (beta.IsAlmost(1.0)) { 120 return treeNode; 121 } else { 122 var multipliciation = new Multiplication(); 123 var node = multipliciation.CreateTreeNode(); 124 var betaConst = MakeConstant(beta); 125 node.AddSubtree(treeNode); 126 node.AddSubtree(betaConst); 127 return node; 128 } 129 } 130 131 private static ISymbolicExpressionTreeNode MakeConstant(double c) { 132 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 133 node.Value = c; 134 return node; 135 } 136 #endregion 60 137 } 61 138 } -
branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs
r8206 r8660 34 34 [StorableClass] 35 35 [Item(Name = "SymbolicDiscriminantFunctionClassificationModel", Description = "Represents a symbolic classification model unsing a discriminant function.")] 36 public class SymbolicDiscriminantFunctionClassificationModel : Symbolic DataAnalysisModel, ISymbolicDiscriminantFunctionClassificationModel {36 public class SymbolicDiscriminantFunctionClassificationModel : SymbolicClassificationModel, ISymbolicDiscriminantFunctionClassificationModel { 37 37 38 38 [Storable] … … 48 48 private set { classValues = value.ToArray(); } 49 49 } 50 51 private IDiscriminantFunctionThresholdCalculator thresholdCalculator; 50 52 [Storable] 51 p rivate double lowerEstimationLimit;52 public double LowerEstimationLimit { get { return lowerEstimationLimit; }}53 [Storable]54 private double upperEstimationLimit;55 public double UpperEstimationLimit { get { return upperEstimationLimit; } } 53 public IDiscriminantFunctionThresholdCalculator ThresholdCalculator { 54 get { return thresholdCalculator; } 55 private set { thresholdCalculator = value; } 56 } 57 56 58 57 59 [StorableConstructor] … … 61 63 classValues = (double[])original.classValues.Clone(); 62 64 thresholds = (double[])original.thresholds.Clone(); 63 lowerEstimationLimit = original.lowerEstimationLimit; 64 upperEstimationLimit = original.upperEstimationLimit; 65 thresholdCalculator = cloner.Clone(original.thresholdCalculator); 65 66 } 66 public SymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 67 public SymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDiscriminantFunctionThresholdCalculator thresholdCalculator, 67 68 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) 68 : base(tree, interpreter) { 69 thresholds = new double[] { double.NegativeInfinity }; 70 classValues = new double[] { 0.0 }; 71 this.lowerEstimationLimit = lowerEstimationLimit; 72 this.upperEstimationLimit = upperEstimationLimit; 69 : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { 70 this.thresholds = new double[0]; 71 this.classValues = new double[0]; 72 this.ThresholdCalculator = thresholdCalculator; 73 } 74 75 [StorableHook(HookType.AfterDeserialization)] 76 private void AfterDeserialization() { 77 if (ThresholdCalculator == null) ThresholdCalculator = new AccuracyMaximizationThresholdCalculator(); 73 78 } 74 79 … … 87 92 } 88 93 89 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 90 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows) 91 .LimitToRange(lowerEstimationLimit, upperEstimationLimit); 94 public override void RecalculateModelParameters(IClassificationProblemData problemData, IEnumerable<int> rows) { 95 double[] classValues; 96 double[] thresholds; 97 var targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 98 var estimatedTrainingValues = GetEstimatedValues(problemData.Dataset, rows); 99 thresholdCalculator.Calculate(problemData, estimatedTrainingValues, targetClassValues, out classValues, out thresholds); 100 SetThresholdsAndClassValues(thresholds, classValues); 92 101 } 93 102 94 public IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) { 103 public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) { 104 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows).LimitToRange(LowerEstimationLimit, UpperEstimationLimit); 105 } 106 107 public override IEnumerable<double> GetEstimatedClassValues(Dataset dataset, IEnumerable<int> rows) { 108 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current symbolic classification model."); 95 109 foreach (var x in GetEstimatedValues(dataset, rows)) { 96 110 int classIndex = 0; … … 104 118 } 105 119 106 public SymbolicDiscriminantFunctionClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 107 return new SymbolicDiscriminantFunctionClassificationSolution(this, problemData); 120 121 public override ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 122 return CreateDiscriminantClassificationSolution(problemData); 123 } 124 public SymbolicDiscriminantFunctionClassificationSolution CreateDiscriminantClassificationSolution(IClassificationProblemData problemData) { 125 return new SymbolicDiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData)); 108 126 } 109 127 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) { 110 return Create ClassificationSolution(problemData);128 return CreateDiscriminantClassificationSolution(problemData); 111 129 } 112 130 IDiscriminantFunctionClassificationSolution IDiscriminantFunctionClassificationModel.CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) { 113 return Create ClassificationSolution(problemData);131 return CreateDiscriminantClassificationSolution(problemData); 114 132 } 115 133 … … 121 139 } 122 140 #endregion 123 124 public static void Scale(SymbolicDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData) {125 var dataset = problemData.Dataset;126 var targetVariable = problemData.TargetVariable;127 var rows = problemData.TrainingIndices;128 var estimatedValues = model.Interpreter.GetSymbolicExpressionTreeValues(model.SymbolicExpressionTree, dataset, rows);129 var targetValues = dataset.GetDoubleValues(targetVariable, rows);130 double alpha;131 double beta;132 OnlineCalculatorError errorState;133 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState);134 if (errorState != OnlineCalculatorError.None) return;135 136 ConstantTreeNode alphaTreeNode = null;137 ConstantTreeNode betaTreeNode = null;138 // check if model has been scaled previously by analyzing the structure of the tree139 var startNode = model.SymbolicExpressionTree.Root.GetSubtree(0);140 if (startNode.GetSubtree(0).Symbol is Addition) {141 var addNode = startNode.GetSubtree(0);142 if (addNode.SubtreeCount == 2 && addNode.GetSubtree(0).Symbol is Multiplication && addNode.GetSubtree(1).Symbol is Constant) {143 alphaTreeNode = addNode.GetSubtree(1) as ConstantTreeNode;144 var mulNode = addNode.GetSubtree(0);145 if (mulNode.SubtreeCount == 2 && mulNode.GetSubtree(1).Symbol is Constant) {146 betaTreeNode = mulNode.GetSubtree(1) as ConstantTreeNode;147 }148 }149 }150 // if tree structure matches the structure necessary for linear scaling then reuse the existing tree nodes151 if (alphaTreeNode != null && betaTreeNode != null) {152 betaTreeNode.Value *= beta;153 alphaTreeNode.Value *= beta;154 alphaTreeNode.Value += alpha;155 } else {156 var mainBranch = startNode.GetSubtree(0);157 startNode.RemoveSubtree(0);158 var scaledMainBranch = MakeSum(MakeProduct(mainBranch, beta), alpha);159 startNode.AddSubtree(scaledMainBranch);160 }161 }162 163 private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode treeNode, double alpha) {164 if (alpha.IsAlmost(0.0)) {165 return treeNode;166 } else {167 var addition = new Addition();168 var node = addition.CreateTreeNode();169 var alphaConst = MakeConstant(alpha);170 node.AddSubtree(treeNode);171 node.AddSubtree(alphaConst);172 return node;173 }174 }175 176 private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {177 if (beta.IsAlmost(1.0)) {178 return treeNode;179 } else {180 var multipliciation = new Multiplication();181 var node = multipliciation.CreateTreeNode();182 var betaConst = MakeConstant(beta);183 node.AddSubtree(treeNode);184 node.AddSubtree(betaConst);185 return node;186 }187 }188 189 private static ISymbolicExpressionTreeNode MakeConstant(double c) {190 var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();191 node.Value = c;192 return node;193 }194 141 } 195 142 }
Note: See TracChangeset
for help on using the changeset viewer.