Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/12 18:58:15 (12 years ago)
Author:
gkronber
Message:

#1847 merged r8205:8635 from trunk into branch

Location:
branches/GP-MoveOperators
Files:
18 edited
6 copied

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Classificationmergedeligible
      /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classificationmergedeligible
      /branches/Algorithms.GradientDescent/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5516-5520
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification4458-4459,​4462,​4464
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5060
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5138-5162
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification7568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification6828
      /branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification7787-8333
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification6829-6865
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification5959-6341
  • branches/GP-MoveOperators/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/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj

    r8085 r8660  
    9393  </PropertyGroup>
    9494  <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>
    9797      <Private>False</Private>
    9898    </Reference>
     
    112112  </ItemGroup>
    113113  <ItemGroup>
     114    <Compile Include="Interfaces\ISymbolicClassificationModelCreatorOperator.cs" />
     115    <Compile Include="Interfaces\ISymbolicDiscriminantFunctionClassificationModelCreator.cs" />
     116    <Compile Include="Interfaces\ISymbolicClassificationModelCreator.cs" />
    114117    <Compile Include="Interfaces\ISymbolicDiscriminantFunctionClassificationModel.cs" />
     118    <Compile Include="ModelCreators\AccuracyMaximizingThresholdsModelCreator.cs" />
     119    <Compile Include="ModelCreators\NearestNeighborModelCreator.cs" />
     120    <Compile Include="ModelCreators\NormalDistributedThresholdsModelCreator.cs" />
    115121    <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs" />
     122    <Compile Include="SymbolicNearestNeighbourClassificationModel.cs" />
    116123    <Compile Include="Plugin.cs" />
     124    <Compile Include="SingleObjective\SymbolicClassificationSingleObjectivePenaltyScoreEvaluator.cs" />
    117125    <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs" />
    118126    <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveOverfittingAnalyzer.cs" />
     
    176184      <Private>False</Private>
    177185    </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>
    178190    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
    179191      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     
    246258  -->
    247259  <PropertyGroup>
    248     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     260   <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    249261set ProjectDir=$(ProjectDir)
    250262set SolutionDir=$(SolutionDir)
     
    253265call PreBuildEvent.cmd
    254266</PreBuildEvent>
     267<PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     268export ProjectDir=$(ProjectDir)
     269export SolutionDir=$(SolutionDir)
     270
     271$SolutionDir/PreBuildEvent.sh
     272</PreBuildEvent>
    255273  </PropertyGroup>
    256274</Project>
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicClassificationModel.cs

    r7259 r8660  
    2020#endregion
    2121
    22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     22using System.Collections.Generic;
    2323namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    2424  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);
    2529  }
    2630}
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Interfaces/ISymbolicDiscriminantFunctionClassificationModel.cs

    r7259 r8660  
    2020#endregion
    2121
    22 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2322namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    2423  public interface ISymbolicDiscriminantFunctionClassificationModel : IDiscriminantFunctionClassificationModel, ISymbolicClassificationModel {
    25     double LowerEstimationLimit { get; }
    26     double UpperEstimationLimit { get; }
     24
    2725  }
    2826}
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveProblem.cs

    r8206 r8660  
    3636    private const string EstimationLimitsParameterName = "EstimationLimits";
    3737    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
    3840
    3941    #region parameter properties
     
    4143      get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    4244    }
     45    public IValueParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     46      get { return (IValueParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     47    }
    4348    #endregion
    4449    #region properties
    4550    public DoubleLimit EstimationLimits {
    4651      get { return EstimationLimitsParameter.Value; }
     52    }
     53    public ISymbolicClassificationModelCreator ModelCreator {
     54      get { return ModelCreatorParameter.Value; }
    4755    }
    4856    #endregion
     
    5866      : base(new ClassificationProblemData(), new SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
    5967      Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
     68      Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
    6069
    6170      EstimationLimitsParameter.Hidden = true;
     
    7483    [StorableHook(HookType.AfterDeserialization)]
    7584    private void AfterDeserialization() {
     85      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     86        Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
    7687      RegisterEventHandlers();
    7788    }
     
    7990    private void RegisterEventHandlers() {
    8091      SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
     92      ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators();
    8193    }
    8294
     
    110122    }
    111123
    112     protected new void ParameterizeOperators() {
     124    protected override void ParameterizeOperators() {
    113125      base.ParameterizeOperators();
    114126      if (Parameters.ContainsKey(EstimationLimitsParameterName)) {
    115127        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;
    119132      }
    120133    }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r8660  
    3434  [StorableClass]
    3535  public sealed class SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>,
    36     ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
     36    ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
    3737    private const string ProblemDataParameterName = "ProblemData";
     38    private const string ModelCreatorParameterName = "ModelCreator";
    3839    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3940    private const string EstimationLimitsParameterName = "EstimationLimits";
     
    4344    public ILookupParameter<IClassificationProblemData> ProblemDataParameter {
    4445      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; }
    4552    }
    4653    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
     
    6774      : base() {
    6875      Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution."));
     76      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6977      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    7078      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
     
    7583    }
    7684
     85    [StorableHook(HookType.AfterDeserialization)]
     86    private void AfterDeserialization() {
     87      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     88        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     89    }
     90
    7791    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());
    8397    }
    8498  }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r8660  
    3434  [StorableClass]
    3535  public sealed class SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationMultiObjectiveEvaluator, IClassificationProblemData>,
    36   ISymbolicDataAnalysisBoundedOperator {
     36  ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
     37    private const string ModelCreatorParameterName = "ModelCreator";
    3738    private const string EstimationLimitsParameterName = "EstimationLimits";
    3839    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     
    4445    public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    4546      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; }
    4653    }
    4754    #endregion
     
    5966      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The loewr and upper limit for the estimated values produced by the symbolic classification model."));
    6067      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, ""));
    6169    }
    6270    public override IDeepCloneable Clone(Cloner cloner) {
     
    6472    }
    6573
     74    [StorableHook(HookType.AfterDeserialization)]
     75    private void AfterDeserialization() {
     76      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     77        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     78    }
     79
    6680    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());
    7286    }
    7387  }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Plugin.cs.frame

    r7675 r8660  
    2626
    2727namespace 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$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB", "3.5")]
     30  [PluginDependency("HeuristicLab.ALGLIB", "3.6.0")]
    3131  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3232  [PluginDependency("HeuristicLab.Common", "3.3")]
     33  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    3334  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3435  [PluginDependency("HeuristicLab.Core", "3.3")]
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/Properties/AssemblyInfo.cs.frame

    r7259 r8660  
    5353// by using the '*' as shown below:
    5454[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  
    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
    6068      EstimationLimitsParameter.Hidden = true;
     
    7179    [StorableHook(HookType.AfterDeserialization)]
    7280    private void AfterDeserialization() {
    73       RegisterEventHandlers();
    74       // compatibility
     81
     82      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     83        Parameters.Add(new ValueParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "", new AccuracyMaximizingThresholdsModelCreator()));
     84
    7585      bool changed = false;
    7686      if (!Operators.OfType<SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer>().Any()) {
     
    8393      }
    8494      if (changed) ParameterizeOperators();
     95      RegisterEventHandlers();
    8596    }
    8697
    8798    private void RegisterEventHandlers() {
    8899      SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
     100      ModelCreatorParameter.NameChanged += (o, e) => ParameterizeOperators();
    89101    }
    90102
     
    125137      if (Parameters.ContainsKey(EstimationLimitsParameterName)) {
    126138        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>())
    128140          op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name;
    129         }
     141        foreach (var op in operators.OfType<ISymbolicClassificationModelCreatorOperator>())
     142          op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name;
    130143      }
    131144    }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r8660  
    3434  [StorableClass]
    3535  public sealed class SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>,
    36     ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
     36    ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
    3737    private const string ProblemDataParameterName = "ProblemData";
     38    private const string ModelCreatorParameterName = "ModelCreator";
    3839    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3940    private const string EstimationLimitsParameterName = "UpperEstimationLimit";
     
    4243    public ILookupParameter<IClassificationProblemData> ProblemDataParameter {
    4344      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; }
    4451    }
    4552    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
     
    6572      : base() {
    6673      Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution."));
     74      Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
    6775      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    6876      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
    6977      Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic classification solution should be linearly scaled.", new BoolValue(false)));
    7078    }
     79
    7180    public override IDeepCloneable Clone(Cloner cloner) {
    7281      return new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer(this, cloner);
    7382    }
     83    [StorableHook(HookType.AfterDeserialization)]
     84    private void AfterDeserialization() {
     85      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     86        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     87    }
    7488
    7589    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());
    8195    }
    8296  }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r8206 r8660  
    3333  [Item("SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer", "An operator that collects the training Pareto-best symbolic classification solutions for single objective symbolic classification problems.")]
    3434  [StorableClass]
    35   public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution> {
     35  public sealed class SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IClassificationProblemData, ISymbolicClassificationSolution>, ISymbolicClassificationModelCreatorOperator {
    3636    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     37    private const string ModelCreatorParameterName = "ModelCreator";
    3738    #region parameter properties
    3839    public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    3940      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; }
    4047    }
    4148    #endregion
     
    5360      : base() {
    5461      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, ""));
    5563    }
    5664    public override IDeepCloneable Clone(Cloner cloner) {
     
    5866    }
    5967
     68    [StorableHook(HookType.AfterDeserialization)]
     69    private void AfterDeserialization() {
     70      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     71        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     72    }
     73
    6074    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());
    6580    }
    6681  }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r8660  
    3434  [StorableClass]
    3535  public sealed class SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>,
    36   ISymbolicDataAnalysisBoundedOperator {
     36  ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
    3737    private const string EstimationLimitsParameterName = "EstimationLimits";
    3838    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     39    private const string ModelCreatorParameterName = "ModelCreator";
    3940
    4041    #region parameter properties
     
    4445    public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    4546      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; }
    4653    }
    4754    #endregion
     
    5966      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
    6067      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, ""));
    6169    }
    6270    public override IDeepCloneable Clone(Cloner cloner) {
     
    6472    }
    6573
     74    [StorableHook(HookType.AfterDeserialization)]
     75    private void AfterDeserialization() {
     76      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     77        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     78    }
     79
    6680    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());
    7286    }
    7387  }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r8206 r8660  
    3333  [Item("SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer", "An operator that collects the validation Pareto-best symbolic classification solutions for single objective symbolic classification problems.")]
    3434  [StorableClass]
    35   public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData> {
     35  public sealed class SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicClassificationSolution, ISymbolicClassificationSingleObjectiveEvaluator, IClassificationProblemData>, ISymbolicClassificationModelCreatorOperator {
    3636    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     37    private const string ModelCreatorParameterName = "ModelCreator";
    3738    #region parameter properties
    3839    public IValueParameter<BoolValue> ApplyLinearScalingParameter {
    3940      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; }
    4047    }
    4148    #endregion
     
    5360      : base() {
    5461      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, ""));
    5563    }
    5664    public override IDeepCloneable Clone(Cloner cloner) {
     
    5866    }
    5967
     68    [StorableHook(HookType.AfterDeserialization)]
     69    private void AfterDeserialization() {
     70      if (!Parameters.ContainsKey(ModelCreatorParameterName))
     71        Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
     72    }
     73
    6074    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());
    6580    }
    6681  }
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationModel.cs

    r7259 r8660  
    3232  [StorableClass]
    3333  [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
    3543    [StorableConstructor]
    3644    protected SymbolicClassificationModel(bool deserializing) : base(deserializing) { }
    3745    protected SymbolicClassificationModel(SymbolicClassificationModel original, Cloner cloner)
    3846      : base(original, cloner) {
     47      lowerEstimationLimit = original.lowerEstimationLimit;
     48      upperEstimationLimit = original.upperEstimationLimit;
    3949    }
    40     public SymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter)
     50    protected SymbolicClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    4151      : base(tree, interpreter) {
     52      this.lowerEstimationLimit = lowerEstimationLimit;
     53      this.upperEstimationLimit = upperEstimationLimit;
    4254    }
    4355
    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);
    4758
    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);
    5160
    52     public ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    53       return new SymbolicClassificationSolution(this, problemData);
    54     }
    5561    IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    5662      return CreateClassificationSolution(problemData);
    5763    }
    5864
     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;
    5977
     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
    60137  }
    61138}
  • branches/GP-MoveOperators/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs

    r8206 r8660  
    3434  [StorableClass]
    3535  [Item(Name = "SymbolicDiscriminantFunctionClassificationModel", Description = "Represents a symbolic classification model unsing a discriminant function.")]
    36   public class SymbolicDiscriminantFunctionClassificationModel : SymbolicDataAnalysisModel, ISymbolicDiscriminantFunctionClassificationModel {
     36  public class SymbolicDiscriminantFunctionClassificationModel : SymbolicClassificationModel, ISymbolicDiscriminantFunctionClassificationModel {
    3737
    3838    [Storable]
     
    4848      private set { classValues = value.ToArray(); }
    4949    }
     50
     51    private IDiscriminantFunctionThresholdCalculator thresholdCalculator;
    5052    [Storable]
    51     private 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
    5658
    5759    [StorableConstructor]
     
    6163      classValues = (double[])original.classValues.Clone();
    6264      thresholds = (double[])original.thresholds.Clone();
    63       lowerEstimationLimit = original.lowerEstimationLimit;
    64       upperEstimationLimit = original.upperEstimationLimit;
     65      thresholdCalculator = cloner.Clone(original.thresholdCalculator);
    6566    }
    66     public SymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     67    public SymbolicDiscriminantFunctionClassificationModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDiscriminantFunctionThresholdCalculator thresholdCalculator,
    6768      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();
    7378    }
    7479
     
    8792    }
    8893
    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);
    92101    }
    93102
    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.");
    95109      foreach (var x in GetEstimatedValues(dataset, rows)) {
    96110        int classIndex = 0;
     
    104118    }
    105119
    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));
    108126    }
    109127    IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
    110       return CreateClassificationSolution(problemData);
     128      return CreateDiscriminantClassificationSolution(problemData);
    111129    }
    112130    IDiscriminantFunctionClassificationSolution IDiscriminantFunctionClassificationModel.CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) {
    113       return CreateClassificationSolution(problemData);
     131      return CreateDiscriminantClassificationSolution(problemData);
    114132    }
    115133
     
    121139    }
    122140    #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 tree
    139       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 nodes
    151       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     }
    194141  }
    195142}
Note: See TracChangeset for help on using the changeset viewer.