Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/20 19:07:40 (4 years ago)
Author:
fbaching
Message:

#1837: merged changes from trunk

  • apply changes from Attic release to all SlidingWindow specific code files (replace StorableClass with StorableType)
Location:
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
Files:
5 added
38 edited

Legend:

Unmodified
Added
Removed
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj

    r10682 r17687  
    1111    <RootNamespace>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression</RootNamespace>
    1212    <AssemblyName>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</AssemblyName>
    13     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     13    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    1414    <TargetFrameworkProfile>
    1515    </TargetFrameworkProfile>
     
    4141    <DebugType>full</DebugType>
    4242    <Optimize>false</Optimize>
    43     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     43    <OutputPath>..\..\..\..\trunk\bin\</OutputPath>
    4444    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4545    <ErrorReport>prompt</ErrorReport>
    4646    <WarningLevel>4</WarningLevel>
    4747    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     48    <Prefer32Bit>false</Prefer32Bit>
    4849  </PropertyGroup>
    4950  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    5051    <DebugType>pdbonly</DebugType>
    5152    <Optimize>true</Optimize>
    52     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     53    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    5354    <DefineConstants>TRACE</DefineConstants>
    5455    <ErrorReport>prompt</ErrorReport>
    5556    <WarningLevel>4</WarningLevel>
    5657    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     58    <Prefer32Bit>false</Prefer32Bit>
    5759  </PropertyGroup>
    5860  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
    5961    <DebugSymbols>true</DebugSymbols>
    60     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     62    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    6163    <DefineConstants>DEBUG;TRACE</DefineConstants>
    6264    <DebugType>full</DebugType>
     
    6466    <ErrorReport>prompt</ErrorReport>
    6567    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     68    <Prefer32Bit>false</Prefer32Bit>
    6669  </PropertyGroup>
    6770  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    68     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     71    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    6972    <DefineConstants>TRACE</DefineConstants>
    7073    <Optimize>true</Optimize>
     
    7376    <ErrorReport>prompt</ErrorReport>
    7477    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     78    <Prefer32Bit>false</Prefer32Bit>
    7579  </PropertyGroup>
    7680  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    7781    <DebugSymbols>true</DebugSymbols>
    78     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     82    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    7983    <DefineConstants>DEBUG;TRACE</DefineConstants>
    8084    <DebugType>full</DebugType>
     
    8286    <ErrorReport>prompt</ErrorReport>
    8387    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
     88    <Prefer32Bit>false</Prefer32Bit>
    8489  </PropertyGroup>
    8590  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    86     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     91    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    8792    <DefineConstants>TRACE</DefineConstants>
    8893    <Optimize>true</Optimize>
     
    9196    <ErrorReport>prompt</ErrorReport>
    9297    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    93   </PropertyGroup>
    94   <ItemGroup>
    95     <Reference Include="ALGLIB-3.7.0">
    96       <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
     98    <Prefer32Bit>false</Prefer32Bit>
     99  </PropertyGroup>
     100  <ItemGroup>
     101    <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     102      <SpecificVersion>False</SpecificVersion>
     103      <HintPath>..\..\..\..\trunk\bin\ALGLIB-3.7.0.dll</HintPath>
    97104      <Private>False</Private>
    98105    </Reference>
    99     <Reference Include="AutoDiff-1.0">
    100       <HintPath>..\..\..\..\trunk\sources\bin\AutoDiff-1.0.dll</HintPath>
    101       <Private>False</Private>
    102     </Reference>
    103     <Reference Include="HeuristicLab.Analysis-3.3">
    104       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
    105       <Private>False</Private>
    106     </Reference>
    107     <Reference Include="HeuristicLab.Collections-3.3">
    108       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
    109       <Private>False</Private>
    110     </Reference>
    111     <Reference Include="HeuristicLab.Common-3.3">
    112       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
    113       <Private>False</Private>
    114     </Reference>
    115     <Reference Include="HeuristicLab.Common.Resources-3.3">
    116       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
    117       <Private>False</Private>
     106    <Reference Include="HEAL.Attic, Version=1.5.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     107      <SpecificVersion>False</SpecificVersion>
     108      <HintPath>..\..\..\..\trunk\bin\HEAL.Attic.dll</HintPath>
     109    </Reference>
     110    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     111      <SpecificVersion>False</SpecificVersion>
     112      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
     113    </Reference>
     114    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     115      <SpecificVersion>False</SpecificVersion>
     116      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Collections-3.3.dll</HintPath>
     117    </Reference>
     118    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     119      <SpecificVersion>False</SpecificVersion>
     120      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Common-3.3.dll</HintPath>
    118121    </Reference>
    119122    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    120123      <SpecificVersion>False</SpecificVersion>
    121       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
    122       <Private>False</Private>
    123     </Reference>
    124     <Reference Include="HeuristicLab.Data-3.3">
    125       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
    126       <Private>False</Private>
    127     </Reference>
    128     <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4">
    129       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
    130       <Private>False</Private>
    131     </Reference>
    132     <Reference Include="HeuristicLab.Operators-3.3">
    133       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
    134       <Private>False</Private>
    135     </Reference>
    136     <Reference Include="HeuristicLab.Optimization-3.3">
    137       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    138       <Private>False</Private>
    139     </Reference>
    140     <Reference Include="HeuristicLab.Parameters-3.3">
    141       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
    142       <Private>False</Private>
    143     </Reference>
    144     <Reference Include="HeuristicLab.Persistence-3.3">
    145       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
    146       <Private>False</Private>
    147     </Reference>
    148     <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    149       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    150       <Private>False</Private>
    151     </Reference>
    152     <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4">
    153       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
    154       <Private>False</Private>
    155     </Reference>
    156     <Reference Include="HeuristicLab.Problems.Instances-3.3">
    157       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
    158       <Private>False</Private>
     124      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Core-3.3.dll</HintPath>
     125    </Reference>
     126    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     127      <SpecificVersion>False</SpecificVersion>
     128      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Data-3.3.dll</HintPath>
     129    </Reference>
     130    <Reference Include="HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     131      <SpecificVersion>False</SpecificVersion>
     132      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
     133    </Reference>
     134    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     135      <SpecificVersion>False</SpecificVersion>
     136      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Operators-3.3.dll</HintPath>
     137    </Reference>
     138    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     139      <SpecificVersion>False</SpecificVersion>
     140      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
     141    </Reference>
     142    <Reference Include="HeuristicLab.Optimization.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     143      <SpecificVersion>False</SpecificVersion>
     144      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath>
     145    </Reference>
     146    <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     147      <SpecificVersion>False</SpecificVersion>
     148      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
     149    </Reference>
     150    <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     151      <SpecificVersion>False</SpecificVersion>
     152      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
     153    </Reference>
     154    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     155      <SpecificVersion>False</SpecificVersion>
     156      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     157    </Reference>
     158    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     159      <SpecificVersion>False</SpecificVersion>
     160      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
     161    </Reference>
     162    <Reference Include="HeuristicLab.Problems.Instances-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     163      <SpecificVersion>False</SpecificVersion>
     164      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
    159165    </Reference>
    160166    <Reference Include="System" />
     
    173179  </ItemGroup>
    174180  <ItemGroup>
     181    <Compile Include="MultiObjective\PearsonRSquaredNestedTreeSizeEvaluator.cs" />
     182    <Compile Include="MultiObjective\PearsonRSquaredNumberOfVariablesEvaluator.cs" />
     183    <Compile Include="MultiObjective\PearsonRSquaredAverageSimilarityEvaluator.cs" />
     184    <Compile Include="MultiObjective\PearsonRSquaredTreeComplexityEvaluator.cs" />
    175185    <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />
    176186    <Compile Include="Plugin.cs" />
     
    181191    <Compile Include="SlidingWindow\OffspringSelectionRegressionSlidingWindowAnalyzer.cs" />
    182192    <Compile Include="SlidingWindow\SlidingWindowBestRegressionSolutionsCollection.cs" />
     193    <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" />
    183194    <Compile Include="SymbolicRegressionPruningAnalyzer.cs" />
    184195    <Compile Include="SingleObjective\Evaluators\SymbolicRegressionLogResidualEvaluator.cs" />
     
    233244  <ItemGroup>
    234245    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
    235       <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
     246      <Project>{3d28463f-ec96-4d82-afee-38be91a0ca00}</Project>
    236247      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
    237       <Private>False</Private>
    238248    </ProjectReference>
    239249  </ItemGroup>
     
    261271</PreBuildEvent>
    262272  </PropertyGroup>
     273  <PropertyGroup>
     274    <PreBuildEvent />
     275  </PropertyGroup>
    263276</Project>
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionEvaluator.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    1919 */
    2020#endregion
    21 
     21using HEAL.Attic;
    2222
    2323namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     24  [StorableType("a8ef5d93-c9e3-46f6-8fd6-323dee5a406b")]
    2425  public interface ISymbolicRegressionEvaluator : ISymbolicDataAnalysisEvaluator<IRegressionProblemData> {
    2526  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionModel.cs

    r9587 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using HEAL.Attic;
     23
    2224namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     25  [StorableType("a411e2b5-f926-41a6-b55b-1aef862db2fb")]
    2326  public interface ISymbolicRegressionModel : IRegressionModel, ISymbolicDataAnalysisModel {
    2427    void Scale(IRegressionProblemData problemData);
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionMultiObjectiveEvaluator.cs

    r9456 r17687  
    1 #region License Information
     1using HEAL.Attic;
     2#region License Information
    23/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    45 *
    56 * This file is part of HeuristicLab.
     
    2122
    2223namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     24  [StorableType("75e2b69d-b610-4694-aad9-601b9c242f89")]
    2325  public interface ISymbolicRegressionMultiObjectiveEvaluator : ISymbolicRegressionEvaluator, ISymbolicDataAnalysisMultiObjectiveEvaluator<IRegressionProblemData> {
    2426  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionSingleObjectiveEvaluator.cs

    r9456 r17687  
    1 #region License Information
     1using HEAL.Attic;
     2#region License Information
    23/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    45 *
    56 * This file is part of HeuristicLab.
     
    2122
    2223namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     24  [StorableType("5dd2601a-b884-48c0-85bc-bc1f437187a3")]
    2325  public interface ISymbolicRegressionSingleObjectiveEvaluator : ISymbolicRegressionEvaluator, ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData> {
    2426  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionSolution.cs

    r9456 r17687  
    1 #region License Information
     1using HEAL.Attic;
     2#region License Information
    23/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    45 *
    56 * This file is part of HeuristicLab.
     
    2122
    2223
    23 using HeuristicLab.Problems.DataAnalysis.Symbolic;
     24
    2425namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     26  [StorableType("dff1a450-e958-454f-bf8e-6b763fdcaff3")]
    2527  public interface ISymbolicRegressionSolution : IRegressionSolution, ISymbolicDataAnalysisSolution {
    2628    new ISymbolicRegressionModel Model { get; }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveEvaluator.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222
    2323using HeuristicLab.Common;
    24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     24using HeuristicLab.Core;
     25using HeuristicLab.Data;
     26using HeuristicLab.Parameters;
     27using HEAL.Attic;
     28
    2529namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     30  [StorableType("1BEEE472-95E7-45C3-BD47-883B5E3A672D")]
    2631  public abstract class SymbolicRegressionMultiObjectiveEvaluator : SymbolicDataAnalysisMultiObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionMultiObjectiveEvaluator {
     32    private const string DecimalPlacesParameterName = "Decimal Places";
     33    private const string UseConstantOptimizationParameterName = "Use constant optimization";
     34    private const string ConstantOptimizationIterationsParameterName = "Constant optimization iterations";
     35
     36    private const string ConstantOptimizationUpdateVariableWeightsParameterName =
     37      "Constant optimization update variable weights";
     38
     39    public IFixedValueParameter<IntValue> DecimalPlacesParameter {
     40      get { return (IFixedValueParameter<IntValue>)Parameters[DecimalPlacesParameterName]; }
     41    }
     42    public IFixedValueParameter<BoolValue> UseConstantOptimizationParameter {
     43      get { return (IFixedValueParameter<BoolValue>)Parameters[UseConstantOptimizationParameterName]; }
     44    }
     45
     46    public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter {
     47      get { return (IFixedValueParameter<IntValue>)Parameters[ConstantOptimizationIterationsParameterName]; }
     48    }
     49
     50    public IFixedValueParameter<BoolValue> ConstantOptimizationUpdateVariableWeightsParameter {
     51      get { return (IFixedValueParameter<BoolValue>)Parameters[ConstantOptimizationUpdateVariableWeightsParameterName]; }
     52    }
     53
     54    public int DecimalPlaces {
     55      get { return DecimalPlacesParameter.Value.Value; }
     56      set { DecimalPlacesParameter.Value.Value = value; }
     57    }
     58    public bool UseConstantOptimization {
     59      get { return UseConstantOptimizationParameter.Value.Value; }
     60      set { UseConstantOptimizationParameter.Value.Value = value; }
     61    }
     62    public int ConstantOptimizationIterations {
     63      get { return ConstantOptimizationIterationsParameter.Value.Value; }
     64      set { ConstantOptimizationIterationsParameter.Value.Value = value; }
     65    }
     66    public bool ConstantOptimizationUpdateVariableWeights {
     67      get { return ConstantOptimizationUpdateVariableWeightsParameter.Value.Value; }
     68      set { ConstantOptimizationUpdateVariableWeightsParameter.Value.Value = value; }
     69    }
     70
    2771    [StorableConstructor]
    28     protected SymbolicRegressionMultiObjectiveEvaluator(bool deserializing) : base(deserializing) { }
     72    protected SymbolicRegressionMultiObjectiveEvaluator(StorableConstructorFlag _) : base(_) { }
    2973    protected SymbolicRegressionMultiObjectiveEvaluator(SymbolicRegressionMultiObjectiveEvaluator original, Cloner cloner)
    3074      : base(original, cloner) {
    3175    }
    3276
    33     protected SymbolicRegressionMultiObjectiveEvaluator() : base() { }
     77    protected SymbolicRegressionMultiObjectiveEvaluator()
     78      : base() {
     79      Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(5)) { Hidden = true });
     80      Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false)));
     81      Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, "The number of iterations constant optimization should be applied.", new IntValue(5)));
     82      Parameters.Add(new FixedValueParameter<BoolValue>(ConstantOptimizationUpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be optimized during constant optimization.", new BoolValue(true)) { Hidden = true });
     83    }
     84
     85    [StorableHook(HookType.AfterDeserialization)]
     86    private void AfterDeserialization() {
     87      if (!Parameters.ContainsKey(UseConstantOptimizationParameterName)) {
     88        Parameters.Add(new FixedValueParameter<BoolValue>(UseConstantOptimizationParameterName, "", new BoolValue(false)));
     89      }
     90      if (!Parameters.ContainsKey(DecimalPlacesParameterName)) {
     91        Parameters.Add(new FixedValueParameter<IntValue>(DecimalPlacesParameterName, "The number of decimal places used for rounding the quality values.", new IntValue(-1)) { Hidden = true });
     92      }
     93      if (!Parameters.ContainsKey(ConstantOptimizationIterationsParameterName)) {
     94        Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, "The number of iterations constant optimization should be applied.", new IntValue(5)));
     95      }
     96      if (!Parameters.ContainsKey(ConstantOptimizationUpdateVariableWeightsParameterName)) {
     97        Parameters.Add(new FixedValueParameter<BoolValue>(ConstantOptimizationUpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be optimized during constant optimization.", new BoolValue(true)));
     98      }
     99    }
    34100  }
    35101}
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs

    r10291 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    2526using HeuristicLab.Data;
    2627using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HEAL.Attic;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3031  [Item("Mean squared error & Tree size Evaluator", "Calculates the mean squared error and the tree size of a symbolic regression solution.")]
    31   [StorableClass]
     32  [StorableType("B1EFB303-9C37-4CBB-8269-BDBC223D9086")]
    3233  public class SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    3334    [StorableConstructor]
    34     protected SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator(bool deserializing) : base(deserializing) { }
     35    protected SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator(StorableConstructorFlag _) : base(_) { }
    3536    protected SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator(SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator original, Cloner cloner)
    3637      : base(original, cloner) {
     
    4748      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4849      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     50      var problemData = ProblemDataParameter.ActualValue;
     51      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     52      var estimationLimits = EstimationLimitsParameter.ActualValue;
     53      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
     54
     55      if (UseConstantOptimization) {
     56        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);
     57      }
     58
     59      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    5060      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    5161      return base.InstrumentedApply();
    5262    }
    5363
    54     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    55       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       OnlineCalculatorError errorState;
     64    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
     65      var mse = SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.Calculate(interpreter, solution, lowerEstimationLimit,
     66        upperEstimationLimit, problemData, rows, applyLinearScaling);
    5867
    59       double mse;
    60       if (applyLinearScaling) {
    61         var mseCalculator = new OnlineMeanSquaredErrorCalculator();
    62         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows);
    63         errorState = mseCalculator.ErrorState;
    64         mse = mseCalculator.MeanSquaredError;
    65       } else {
    66         IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    67         mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    68       }
    69       if (errorState != OnlineCalculatorError.None) mse = double.NaN;
     68      if (decimalPlaces >= 0)
     69        mse = Math.Round(mse, decimalPlaces);
     70
    7071      return new double[2] { mse, solution.Length };
    7172    }
     
    7677      ApplyLinearScalingParameter.ExecutionContext = context;
    7778
    78       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     79      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    7980
    8081      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r10291 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
     
    2526using HeuristicLab.Data;
    2627using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HEAL.Attic;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3031  [Item("Pearson R² & Tree size Evaluator", "Calculates the Pearson R² and the tree size of a symbolic regression solution.")]
    31   [StorableClass]
     32  [StorableType("58008433-3406-4374-9BF1-1C5EF944350A")]
    3233  public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator {
    3334    [StorableConstructor]
    34     protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
     35    protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(StorableConstructorFlag _) : base(_) { }
    3536    protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator original, Cloner cloner)
    3637      : base(original, cloner) {
     
    4748      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4849      var solution = SymbolicExpressionTreeParameter.ActualValue;
    49       double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value);
     50      var problemData = ProblemDataParameter.ActualValue;
     51      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     52      var estimationLimits = EstimationLimitsParameter.ActualValue;
     53      var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value;
     54
     55      if (UseConstantOptimization) {
     56        SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, solution, problemData, rows, applyLinearScaling, ConstantOptimizationIterations, updateVariableWeights: ConstantOptimizationUpdateVariableWeights, lowerEstimationLimit: estimationLimits.Lower, upperEstimationLimit: estimationLimits.Upper);
     57      }
     58      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    5059      QualitiesParameter.ActualValue = new DoubleArray(qualities);
    5160      return base.InstrumentedApply();
    5261    }
    5362
    54     public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) {
    55       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    56       IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    57       OnlineCalculatorError errorState;
    58 
    59       double r2;
    60       if (applyLinearScaling) {
    61         var r2Calculator = new OnlinePearsonsRSquaredCalculator();
    62         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
    63         errorState = r2Calculator.ErrorState;
    64         r2 = r2Calculator.RSquared;
    65       } else {
    66         IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    67         r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    68       }
    69 
    70       if (errorState != OnlineCalculatorError.None) r2 = double.NaN;
     63    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, int decimalPlaces) {
     64      double r2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     65      if (decimalPlaces >= 0)
     66        r2 = Math.Round(r2, decimalPlaces);
    7167      return new double[2] { r2, solution.Length };
    7268    }
     
    7773      ApplyLinearScalingParameter.ExecutionContext = context;
    7874
    79       double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value);
     75      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, DecimalPlaces);
    8076
    8177      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Optimization;
    2627using HeuristicLab.Parameters;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HEAL.Attic;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    30   [Item("Symbolic Regression Problem (multi objective)", "Represents a multi objective symbolic regression problem.")]
    31   [StorableClass]
    32   [Creatable("Problems")]
     31  [Item("Symbolic Regression Problem (multi-objective)", "Represents a multi objective symbolic regression problem.")]
     32  [StorableType("4A8D3658-66B3-48B4-B983-D46409045DBE")]
     33  [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 110)]
    3334  public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem {
    3435    private const double PunishmentFactor = 10;
     
    5253
    5354    [StorableConstructor]
    54     protected SymbolicRegressionMultiObjectiveProblem(bool deserializing) : base(deserializing) { }
     55    protected SymbolicRegressionMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { }
    5556    protected SymbolicRegressionMultiObjectiveProblem(SymbolicRegressionMultiObjectiveProblem original, Cloner cloner)
    5657      : base(original, cloner) {
     
    9394      Operators.Add(new SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer());
    9495      Operators.Add(new SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer());
     96      Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator());
     97      Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()));
    9598      ParameterizeOperators();
    9699    }
     
    122125        }
    123126      }
     127
     128      foreach (var op in Operators.OfType<ISolutionSimilarityCalculator>()) {
     129        op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     130        op.QualityVariableName = Evaluator.QualitiesParameter.ActualName;
     131
     132        if (op is SymbolicExpressionTreePhenotypicSimilarityCalculator) {
     133          var phenotypicSimilarityCalculator = (SymbolicExpressionTreePhenotypicSimilarityCalculator)op;
     134          phenotypicSimilarityCalculator.ProblemData = ProblemData;
     135          phenotypicSimilarityCalculator.Interpreter = SymbolicExpressionTreeInterpreter;
     136        }
     137      }
    124138    }
    125139  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
     24using HeuristicLab.Analysis;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2428using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     29using HeuristicLab.Optimization;
    2530using HeuristicLab.Parameters;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HEAL.Attic;
    2732
    2833namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3136  /// </summary>
    3237  [Item("SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic regression solution for multi objective symbolic regression problems.")]
    33   [StorableClass]
     38  [StorableType("431B0046-3115-493F-BD15-E3DA98E3E9C7")]
    3439  public sealed class SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicRegressionSolution>,
    3540    ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
     
    3742    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3843    private const string EstimationLimitsParameterName = "EstimationLimits";
     44    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     45    private const string ValidationPartitionParameterName = "ValidationPartition";
     46    private const string AnalyzeTestErrorParameterName = "Analyze Test Error";
     47
    3948    #region parameter properties
    4049    public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
     
    4756      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    4857    }
     58    public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     59      get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
     60    }
     61
     62    public IValueLookupParameter<IntRange> ValidationPartitionParameter {
     63      get { return (IValueLookupParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
     64    }
     65
     66    public IFixedValueParameter<BoolValue> AnalyzeTestErrorParameter {
     67      get { return (IFixedValueParameter<BoolValue>)Parameters[AnalyzeTestErrorParameterName]; }
     68    }
    4969    #endregion
    5070
     71    public bool AnalyzeTestError {
     72      get { return AnalyzeTestErrorParameter.Value.Value; }
     73      set { AnalyzeTestErrorParameter.Value.Value = value; }
     74    }
     75
    5176    [StorableConstructor]
    52     private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     77    private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { }
    5378    private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    5479    public SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer()
    5580      : base() {
    56       Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution."));
    57       Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    58       Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
     81      Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution.") { Hidden = true });
     82      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.") { Hidden = true });
     83      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model.") { Hidden = true });
     84      Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression.") { Hidden = true });
     85      Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
     86      Parameters.Add(new FixedValueParameter<BoolValue>(AnalyzeTestErrorParameterName, "Flag whether the test error should be displayed in the Pareto-Front", new BoolValue(false)));
     87    }
     88
     89    [StorableHook(HookType.AfterDeserialization)]
     90    private void AfterDeserialization() {
     91      if (!Parameters.ContainsKey(MaximumSymbolicExpressionTreeLengthParameterName))
     92        Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression.") { Hidden = true });
     93      if (!Parameters.ContainsKey(ValidationPartitionParameterName))
     94        Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
     95      if (!Parameters.ContainsKey(AnalyzeTestErrorParameterName))
     96        Parameters.Add(new FixedValueParameter<BoolValue>(AnalyzeTestErrorParameterName, "Flag whether the test error should be displayed in the Pareto-Front", new BoolValue(false)));
    5997    }
    6098
     
    64102
    65103    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    66       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     104      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    67105      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    68106      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    69107    }
     108
     109    public override IOperation Apply() {
     110      var operation = base.Apply();
     111      var paretoFront = TrainingBestSolutionsParameter.ActualValue;
     112
     113      IResult result;
     114      ScatterPlot qualityToTreeSize;
     115      if (!ResultCollection.TryGetValue("Pareto Front Analysis", out result)) {
     116        qualityToTreeSize = new ScatterPlot("Quality vs Tree Size", "");
     117        qualityToTreeSize.VisualProperties.XAxisMinimumAuto = false;
     118        qualityToTreeSize.VisualProperties.XAxisMaximumAuto = false;
     119        qualityToTreeSize.VisualProperties.YAxisMinimumAuto = false;
     120        qualityToTreeSize.VisualProperties.YAxisMaximumAuto = false;
     121
     122        qualityToTreeSize.VisualProperties.XAxisMinimumFixedValue = 0;
     123        qualityToTreeSize.VisualProperties.XAxisMaximumFixedValue = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
     124        qualityToTreeSize.VisualProperties.YAxisMinimumFixedValue = 0;
     125        qualityToTreeSize.VisualProperties.YAxisMaximumFixedValue = 2;
     126        ResultCollection.Add(new Result("Pareto Front Analysis", qualityToTreeSize));
     127      } else {
     128        qualityToTreeSize = (ScatterPlot)result.Value;
     129      }
     130
     131
     132      int previousTreeLength = -1;
     133      var sizeParetoFront = new LinkedList<ISymbolicRegressionSolution>();
     134      foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) {
     135        int treeLength = solution.Model.SymbolicExpressionTree.Length;
     136        if (!sizeParetoFront.Any()) sizeParetoFront.AddLast(solution);
     137        if (solution.TrainingNormalizedMeanSquaredError < sizeParetoFront.Last.Value.TrainingNormalizedMeanSquaredError) {
     138          if (treeLength == previousTreeLength)
     139            sizeParetoFront.RemoveLast();
     140          sizeParetoFront.AddLast(solution);
     141        }
     142        previousTreeLength = treeLength;
     143      }
     144
     145      qualityToTreeSize.Rows.Clear();
     146      var trainingRow = new ScatterPlotDataRow("Training NMSE", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TrainingNormalizedMeanSquaredError, x)));
     147      trainingRow.VisualProperties.PointSize = 8;
     148      qualityToTreeSize.Rows.Add(trainingRow);
     149
     150      if (AnalyzeTestError) {
     151        var testRow = new ScatterPlotDataRow("Test NMSE", "",
     152          sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TestNormalizedMeanSquaredError, x)));
     153        testRow.VisualProperties.PointSize = 8;
     154        qualityToTreeSize.Rows.Add(testRow);
     155      }
     156
     157      var validationPartition = ValidationPartitionParameter.ActualValue;
     158      if (validationPartition.Size != 0) {
     159        var problemData = ProblemDataParameter.ActualValue;
     160        var validationIndizes = Enumerable.Range(validationPartition.Start, validationPartition.Size).ToList();
     161        var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, validationIndizes).ToList();
     162        OnlineCalculatorError error;
     163        var validationRow = new ScatterPlotDataRow("Validation NMSE", "",
     164          sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length,
     165          OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, x.GetEstimatedValues(validationIndizes), out error))));
     166        validationRow.VisualProperties.PointSize = 7;
     167        qualityToTreeSize.Rows.Add(validationRow);
     168      }
     169
     170      return operation;
     171    }
     172
    70173  }
    71174}
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2525using HeuristicLab.Parameters;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3131  /// </summary>
    3232  [Item("SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer", "An operator that analyzes the validation best symbolic regression solution for multi objective symbolic regression problems.")]
    33   [StorableClass]
     33  [StorableType("64084F75-38B9-4501-BF2D-BB342B49F732")]
    3434  public sealed class SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionMultiObjectiveEvaluator, IRegressionProblemData>,
    3535    ISymbolicDataAnalysisBoundedOperator {
     
    4343
    4444    [StorableConstructor]
    45     private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     45    private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { }
    4646    private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer(SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    4747    public SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer()
     
    5454
    5555    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
    56       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     56      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    5757      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    5858      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Plugin.cs.frame

    r10037 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.5.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression","Provides classes to perform symbolic regression (single- or multiobjective).", "3.4.12.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
    31   [PluginDependency("HeuristicLab.AutoDiff", "1.0")]
    3231  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3332  [PluginDependency("HeuristicLab.Common", "3.3")]
     
    3938  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    4039  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    41   [PluginDependency("HeuristicLab.Persistence", "3.3")]
     40  [PluginDependency("HeuristicLab.Attic", "1.0")]
    4241  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
    4342  [PluginDependency("HeuristicLab.Problems.DataAnalysis.Symbolic", "3.4")]
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Properties/AssemblyInfo.cs.frame

    r10037 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3131[assembly: AssemblyCompany("")]
    3232[assembly: AssemblyProduct("HeuristicLab")]
    33 [assembly: AssemblyCopyright("(c) 2002-2013 HEAL")]
     33[assembly: AssemblyCopyright("(c) HEAL")]
    3434[assembly: AssemblyTrademark("")]
    3535[assembly: AssemblyCulture("")]
     
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.5.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.12.$WCREV$")]
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/ConstantOptimizationAnalyzer.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2828using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3535  /// </summary>
    3636  [Item("ConstantOptimizationAnalyzer", "An operator that performs a constant optimization on the best symbolic expression trees.")]
    37   [StorableClass]
     37  [StorableType("9FB87E7B-A9E2-49DD-A92A-78BD9FC17916")]
    3838  public sealed class ConstantOptimizationAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer, IStatefulItem {
    3939    private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions";
     
    8787
    8888    [StorableConstructor]
    89     private ConstantOptimizationAnalyzer(bool deserializing) : base(deserializing) { }
     89    private ConstantOptimizationAnalyzer(StorableConstructorFlag _) : base(_) { }
    9090    private ConstantOptimizationAnalyzer(ConstantOptimizationAnalyzer original, Cloner cloner) : base(original, cloner) { }
    9191    public override IDeepCloneable Clone(Cloner cloner) { return new ConstantOptimizationAnalyzer(this, cloner); }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r10291 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using AutoDiff;
     25using HEAL.Attic;
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Data;
    2929using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     30using HeuristicLab.Optimization;
    3031using HeuristicLab.Parameters;
    31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3434  [Item("Constant Optimization Evaluator", "Calculates Pearson R² of a symbolic regression solution and optimizes the constant used.")]
    35   [StorableClass]
     35  [StorableType("24B68851-036D-4446-BD6F-3823E9028FF4")]
    3636  public class SymbolicRegressionConstantOptimizationEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3737    private const string ConstantOptimizationIterationsParameterName = "ConstantOptimizationIterations";
     
    4040    private const string ConstantOptimizationRowsPercentageParameterName = "ConstantOptimizationRowsPercentage";
    4141    private const string UpdateConstantsInTreeParameterName = "UpdateConstantsInSymbolicExpressionTree";
     42    private const string UpdateVariableWeightsParameterName = "Update Variable Weights";
     43
     44    private const string FunctionEvaluationsResultParameterName = "Constants Optimization Function Evaluations";
     45    private const string GradientEvaluationsResultParameterName = "Constants Optimization Gradient Evaluations";
     46    private const string CountEvaluationsParameterName = "Count Function and Gradient Evaluations";
    4247
    4348    public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter {
     
    5661      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateConstantsInTreeParameterName]; }
    5762    }
     63    public IFixedValueParameter<BoolValue> UpdateVariableWeightsParameter {
     64      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateVariableWeightsParameterName]; }
     65    }
     66
     67    public IResultParameter<IntValue> FunctionEvaluationsResultParameter {
     68      get { return (IResultParameter<IntValue>)Parameters[FunctionEvaluationsResultParameterName]; }
     69    }
     70    public IResultParameter<IntValue> GradientEvaluationsResultParameter {
     71      get { return (IResultParameter<IntValue>)Parameters[GradientEvaluationsResultParameterName]; }
     72    }
     73    public IFixedValueParameter<BoolValue> CountEvaluationsParameter {
     74      get { return (IFixedValueParameter<BoolValue>)Parameters[CountEvaluationsParameterName]; }
     75    }
     76
    5877
    5978    public IntValue ConstantOptimizationIterations {
     
    7493    }
    7594
     95    public bool UpdateVariableWeights {
     96      get { return UpdateVariableWeightsParameter.Value.Value; }
     97      set { UpdateVariableWeightsParameter.Value.Value = value; }
     98    }
     99
     100    public bool CountEvaluations {
     101      get { return CountEvaluationsParameter.Value.Value; }
     102      set { CountEvaluationsParameter.Value.Value = value; }
     103    }
     104
    76105    public override bool Maximization {
    77106      get { return true; }
     
    79108
    80109    [StorableConstructor]
    81     protected SymbolicRegressionConstantOptimizationEvaluator(bool deserializing) : base(deserializing) { }
     110    protected SymbolicRegressionConstantOptimizationEvaluator(StorableConstructorFlag _) : base(_) { }
    82111    protected SymbolicRegressionConstantOptimizationEvaluator(SymbolicRegressionConstantOptimizationEvaluator original, Cloner cloner)
    83112      : base(original, cloner) {
     
    85114    public SymbolicRegressionConstantOptimizationEvaluator()
    86115      : base() {
    87       Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, "Determines how many iterations should be calculated while optimizing the constant of a symbolic expression tree (0 indicates other or default stopping criterion).", new IntValue(10), true));
    88       Parameters.Add(new FixedValueParameter<DoubleValue>(ConstantOptimizationImprovementParameterName, "Determines the relative improvement which must be achieved in the constant optimization to continue with it (0 indicates other or default stopping criterion).", new DoubleValue(0), true));
    89       Parameters.Add(new FixedValueParameter<PercentValue>(ConstantOptimizationProbabilityParameterName, "Determines the probability that the constants are optimized", new PercentValue(1), true));
    90       Parameters.Add(new FixedValueParameter<PercentValue>(ConstantOptimizationRowsPercentageParameterName, "Determines the percentage of the rows which should be used for constant optimization", new PercentValue(1), true));
    91       Parameters.Add(new FixedValueParameter<BoolValue>(UpdateConstantsInTreeParameterName, "Determines if the constants in the tree should be overwritten by the optimized constants.", new BoolValue(true)));
     116      Parameters.Add(new FixedValueParameter<IntValue>(ConstantOptimizationIterationsParameterName, "Determines how many iterations should be calculated while optimizing the constant of a symbolic expression tree (0 indicates other or default stopping criterion).", new IntValue(10)));
     117      Parameters.Add(new FixedValueParameter<DoubleValue>(ConstantOptimizationImprovementParameterName, "Determines the relative improvement which must be achieved in the constant optimization to continue with it (0 indicates other or default stopping criterion).", new DoubleValue(0)) { Hidden = true });
     118      Parameters.Add(new FixedValueParameter<PercentValue>(ConstantOptimizationProbabilityParameterName, "Determines the probability that the constants are optimized", new PercentValue(1)));
     119      Parameters.Add(new FixedValueParameter<PercentValue>(ConstantOptimizationRowsPercentageParameterName, "Determines the percentage of the rows which should be used for constant optimization", new PercentValue(1)));
     120      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateConstantsInTreeParameterName, "Determines if the constants in the tree should be overwritten by the optimized constants.", new BoolValue(true)) { Hidden = true });
     121      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be  optimized.", new BoolValue(true)) { Hidden = true });
     122
     123      Parameters.Add(new FixedValueParameter<BoolValue>(CountEvaluationsParameterName, "Determines if function and gradient evaluation should be counted.", new BoolValue(false)));
     124      Parameters.Add(new ResultParameter<IntValue>(FunctionEvaluationsResultParameterName, "The number of function evaluations performed by the constants optimization evaluator", "Results", new IntValue()));
     125      Parameters.Add(new ResultParameter<IntValue>(GradientEvaluationsResultParameterName, "The number of gradient evaluations performed by the constants optimization evaluator", "Results", new IntValue()));
    92126    }
    93127
     
    100134      if (!Parameters.ContainsKey(UpdateConstantsInTreeParameterName))
    101135        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateConstantsInTreeParameterName, "Determines if the constants in the tree should be overwritten by the optimized constants.", new BoolValue(true)));
    102     }
    103 
     136      if (!Parameters.ContainsKey(UpdateVariableWeightsParameterName))
     137        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be  optimized.", new BoolValue(true)));
     138
     139      if (!Parameters.ContainsKey(CountEvaluationsParameterName))
     140        Parameters.Add(new FixedValueParameter<BoolValue>(CountEvaluationsParameterName, "Determines if function and gradient evaluation should be counted.", new BoolValue(false)));
     141
     142      if (!Parameters.ContainsKey(FunctionEvaluationsResultParameterName))
     143        Parameters.Add(new ResultParameter<IntValue>(FunctionEvaluationsResultParameterName, "The number of function evaluations performed by the constants optimization evaluator", "Results", new IntValue()));
     144      if (!Parameters.ContainsKey(GradientEvaluationsResultParameterName))
     145        Parameters.Add(new ResultParameter<IntValue>(GradientEvaluationsResultParameterName, "The number of gradient evaluations performed by the constants optimization evaluator", "Results", new IntValue()));
     146    }
     147
     148    private static readonly object locker = new object();
    104149    public override IOperation InstrumentedApply() {
    105150      var solution = SymbolicExpressionTreeParameter.ActualValue;
     
    107152      if (RandomParameter.ActualValue.NextDouble() < ConstantOptimizationProbability.Value) {
    108153        IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value);
     154        var counter = new EvaluationsCounter();
    109155        quality = OptimizeConstants(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, ProblemDataParameter.ActualValue,
    110            constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ConstantOptimizationIterations.Value,
    111            EstimationLimitsParameter.ActualValue.Upper, EstimationLimitsParameter.ActualValue.Lower, UpdateConstantsInTree);
     156           constantOptimizationRows, ApplyLinearScalingParameter.ActualValue.Value, ConstantOptimizationIterations.Value, updateVariableWeights: UpdateVariableWeights, lowerEstimationLimit: EstimationLimitsParameter.ActualValue.Lower, upperEstimationLimit: EstimationLimitsParameter.ActualValue.Upper, updateConstantsInTree: UpdateConstantsInTree, counter: counter);
    112157
    113158        if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) {
     
    115160          quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value);
    116161        }
     162
     163        if (CountEvaluations) {
     164          lock (locker) {
     165            FunctionEvaluationsResultParameter.ActualValue.Value += counter.FunctionEvaluations;
     166            GradientEvaluationsResultParameter.ActualValue.Value += counter.GradientEvaluations;
     167          }
     168        }
     169
    117170      } else {
    118171        var evaluationRows = GenerateRowsToEvaluate();
     
    128181      EstimationLimitsParameter.ExecutionContext = context;
    129182      ApplyLinearScalingParameter.ExecutionContext = context;
     183      FunctionEvaluationsResultParameter.ExecutionContext = context;
     184      GradientEvaluationsResultParameter.ExecutionContext = context;
    130185
    131186      // Pearson R² evaluator is used on purpose instead of the const-opt evaluator,
     
    137192      EstimationLimitsParameter.ExecutionContext = null;
    138193      ApplyLinearScalingParameter.ExecutionContext = null;
     194      FunctionEvaluationsResultParameter.ExecutionContext = null;
     195      GradientEvaluationsResultParameter.ExecutionContext = null;
    139196
    140197      return r2;
    141198    }
    142199
    143     #region derivations of functions
    144     // create function factory for arctangent
    145     private readonly Func<Term, UnaryFunc> arctan = UnaryFunc.Factory(
    146       eval: Math.Atan,
    147       diff: x => 1 / (1 + x * x));
    148     private static readonly Func<Term, UnaryFunc> sin = UnaryFunc.Factory(
    149       eval: Math.Sin,
    150       diff: Math.Cos);
    151     private static readonly Func<Term, UnaryFunc> cos = UnaryFunc.Factory(
    152        eval: Math.Cos,
    153        diff: x => -Math.Sin(x));
    154     private static readonly Func<Term, UnaryFunc> tan = UnaryFunc.Factory(
    155       eval: Math.Tan,
    156       diff: x => 1 + Math.Tan(x) * Math.Tan(x));
    157     private static readonly Func<Term, UnaryFunc> square = UnaryFunc.Factory(
    158        eval: x => x * x,
    159        diff: x => 2 * x);
    160     private static readonly Func<Term, UnaryFunc> erf = UnaryFunc.Factory(
    161       eval: alglib.errorfunction,
    162       diff: x => 2.0 * Math.Exp(-(x * x)) / Math.Sqrt(Math.PI));
    163     private static readonly Func<Term, UnaryFunc> norm = UnaryFunc.Factory(
    164       eval: alglib.normaldistribution,
    165       diff: x => -(Math.Exp(-(x * x)) * Math.Sqrt(Math.Exp(x * x)) * x) / Math.Sqrt(2 * Math.PI));
    166     #endregion
    167 
    168 
    169     public static double OptimizeConstants(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, IRegressionProblemData problemData,
    170       IEnumerable<int> rows, bool applyLinearScaling, int maxIterations, double upperEstimationLimit = double.MaxValue, double lowerEstimationLimit = double.MinValue, bool updateConstantsInTree = true) {
    171 
    172       List<AutoDiff.Variable> variables = new List<AutoDiff.Variable>();
    173       List<AutoDiff.Variable> parameters = new List<AutoDiff.Variable>();
    174       List<string> variableNames = new List<string>();
    175 
    176       AutoDiff.Term func;
    177       if (!TryTransformToAutoDiff(tree.Root.GetSubtree(0), variables, parameters, variableNames, out func))
     200    public class EvaluationsCounter {
     201      public int FunctionEvaluations = 0;
     202      public int GradientEvaluations = 0;
     203    }
     204
     205    public static double OptimizeConstants(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     206      ISymbolicExpressionTree tree, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling,
     207      int maxIterations, bool updateVariableWeights = true,
     208      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue,
     209      bool updateConstantsInTree = true, Action<double[], double, object> iterationCallback = null, EvaluationsCounter counter = null) {
     210
     211      // numeric constants in the tree become variables for constant opt
     212      // variables in the tree become parameters (fixed values) for constant opt
     213      // for each parameter (variable in the original tree) we store the
     214      // variable name, variable value (for factor vars) and lag as a DataForVariable object.
     215      // A dictionary is used to find parameters
     216      double[] initialConstants;
     217      var parameters = new List<TreeToAutoDiffTermConverter.DataForVariable>();
     218
     219      TreeToAutoDiffTermConverter.ParametricFunction func;
     220      TreeToAutoDiffTermConverter.ParametricFunctionGradient func_grad;
     221      if (!TreeToAutoDiffTermConverter.TryConvertToAutoDiff(tree, updateVariableWeights, applyLinearScaling, out parameters, out initialConstants, out func, out func_grad))
    178222        throw new NotSupportedException("Could not optimize constants of symbolic expression tree due to not supported symbols used in the tree.");
    179       if (variableNames.Count == 0) return 0.0;
    180 
    181       AutoDiff.IParametricCompiledTerm compiledFunc = AutoDiff.TermUtils.Compile(func, variables.ToArray(), parameters.ToArray());
    182 
    183       List<SymbolicExpressionTreeTerminalNode> terminalNodes = tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>().ToList();
    184       double[] c = new double[variables.Count];
    185 
    186       {
     223      if (parameters.Count == 0) return 0.0; // gkronber: constant expressions always have a R² of 0.0
     224      var parameterEntries = parameters.ToArray(); // order of entries must be the same for x
     225
     226      //extract inital constants
     227      double[] c;
     228      if (applyLinearScaling) {
     229        c = new double[initialConstants.Length + 2];
    187230        c[0] = 0.0;
    188231        c[1] = 1.0;
    189         //extract inital constants
    190         int i = 2;
    191         foreach (var node in terminalNodes) {
    192           ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
    193           VariableTreeNode variableTreeNode = node as VariableTreeNode;
    194           if (constantTreeNode != null)
    195             c[i++] = constantTreeNode.Value;
    196           else if (variableTreeNode != null)
    197             c[i++] = variableTreeNode.Weight;
    198         }
    199       }
    200       double[] originalConstants = (double[])c.Clone();
     232        Array.Copy(initialConstants, 0, c, 2, initialConstants.Length);
     233      } else {
     234        c = (double[])initialConstants.Clone();
     235      }
     236
    201237      double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
     238
     239      if (counter == null) counter = new EvaluationsCounter();
     240      var rowEvaluationsCounter = new EvaluationsCounter();
    202241
    203242      alglib.lsfitstate state;
    204243      alglib.lsfitreport rep;
    205       int info;
    206 
    207       Dataset ds = problemData.Dataset;
    208       double[,] x = new double[rows.Count(), variableNames.Count];
     244      int retVal;
     245
     246      IDataset ds = problemData.Dataset;
     247      double[,] x = new double[rows.Count(), parameters.Count];
    209248      int row = 0;
    210249      foreach (var r in rows) {
    211         for (int col = 0; col < variableNames.Count; col++) {
    212           x[row, col] = ds.GetDoubleValue(variableNames[col], r);
     250        int col = 0;
     251        foreach (var info in parameterEntries) {
     252          if (ds.VariableHasType<double>(info.variableName)) {
     253            x[row, col] = ds.GetDoubleValue(info.variableName, r + info.lag);
     254          } else if (ds.VariableHasType<string>(info.variableName)) {
     255            x[row, col] = ds.GetStringValue(info.variableName, r) == info.variableValue ? 1 : 0;
     256          } else throw new InvalidProgramException("found a variable of unknown type");
     257          col++;
    213258        }
    214259        row++;
     
    219264      int k = c.Length;
    220265
    221       alglib.ndimensional_pfunc function_cx_1_func = CreatePFunc(compiledFunc);
    222       alglib.ndimensional_pgrad function_cx_1_grad = CreatePGrad(compiledFunc);
     266      alglib.ndimensional_pfunc function_cx_1_func = CreatePFunc(func);
     267      alglib.ndimensional_pgrad function_cx_1_grad = CreatePGrad(func_grad);
     268      alglib.ndimensional_rep xrep = (p, f, obj) => iterationCallback(p, f, obj);
    223269
    224270      try {
    225271        alglib.lsfitcreatefg(x, y, c, n, m, k, false, out state);
    226272        alglib.lsfitsetcond(state, 0.0, 0.0, maxIterations);
     273        alglib.lsfitsetxrep(state, iterationCallback != null);
    227274        //alglib.lsfitsetgradientcheck(state, 0.001);
    228         alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, null, null);
    229         alglib.lsfitresults(state, out info, out c, out rep);
    230       }
    231       catch (ArithmeticException) {
     275        alglib.lsfitfit(state, function_cx_1_func, function_cx_1_grad, xrep, rowEvaluationsCounter);
     276        alglib.lsfitresults(state, out retVal, out c, out rep);
     277      } catch (ArithmeticException) {
    232278        return originalQuality;
    233       }
    234       catch (alglib.alglibexception) {
     279      } catch (alglib.alglibexception) {
    235280        return originalQuality;
    236281      }
    237282
    238       //info == -7  => constant optimization failed due to wrong gradient
    239       if (info != -7) UpdateConstants(tree, c.Skip(2).ToArray());
     283      counter.FunctionEvaluations += rowEvaluationsCounter.FunctionEvaluations / n;
     284      counter.GradientEvaluations += rowEvaluationsCounter.GradientEvaluations / n;
     285
     286      //retVal == -7  => constant optimization failed due to wrong gradient
     287      if (retVal != -7) {
     288        if (applyLinearScaling) {
     289          var tmp = new double[c.Length - 2];
     290          Array.Copy(c, 2, tmp, 0, tmp.Length);
     291          UpdateConstants(tree, tmp, updateVariableWeights);
     292        } else UpdateConstants(tree, c, updateVariableWeights);
     293      }
    240294      var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling);
    241295
    242       if (!updateConstantsInTree) UpdateConstants(tree, originalConstants.Skip(2).ToArray());
     296      if (!updateConstantsInTree) UpdateConstants(tree, initialConstants, updateVariableWeights);
     297
    243298      if (originalQuality - quality > 0.001 || double.IsNaN(quality)) {
    244         UpdateConstants(tree, originalConstants.Skip(2).ToArray());
     299        UpdateConstants(tree, initialConstants, updateVariableWeights);
    245300        return originalQuality;
    246301      }
     
    248303    }
    249304
    250     private static void UpdateConstants(ISymbolicExpressionTree tree, double[] constants) {
     305    private static void UpdateConstants(ISymbolicExpressionTree tree, double[] constants, bool updateVariableWeights) {
    251306      int i = 0;
    252307      foreach (var node in tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>()) {
    253308        ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
    254         VariableTreeNode variableTreeNode = node as VariableTreeNode;
     309        VariableTreeNodeBase variableTreeNodeBase = node as VariableTreeNodeBase;
     310        FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode;
    255311        if (constantTreeNode != null)
    256312          constantTreeNode.Value = constants[i++];
    257         else if (variableTreeNode != null)
    258           variableTreeNode.Weight = constants[i++];
    259       }
    260     }
    261 
    262     private static alglib.ndimensional_pfunc CreatePFunc(AutoDiff.IParametricCompiledTerm compiledFunc) {
    263       return (double[] c, double[] x, ref double func, object o) => {
    264         func = compiledFunc.Evaluate(c, x);
     313        else if (updateVariableWeights && variableTreeNodeBase != null)
     314          variableTreeNodeBase.Weight = constants[i++];
     315        else if (factorVarTreeNode != null) {
     316          for (int j = 0; j < factorVarTreeNode.Weights.Length; j++)
     317            factorVarTreeNode.Weights[j] = constants[i++];
     318        }
     319      }
     320    }
     321
     322    private static alglib.ndimensional_pfunc CreatePFunc(TreeToAutoDiffTermConverter.ParametricFunction func) {
     323      return (double[] c, double[] x, ref double fx, object o) => {
     324        fx = func(c, x);
     325        var counter = (EvaluationsCounter)o;
     326        counter.FunctionEvaluations++;
    265327      };
    266328    }
    267329
    268     private static alglib.ndimensional_pgrad CreatePGrad(AutoDiff.IParametricCompiledTerm compiledFunc) {
    269       return (double[] c, double[] x, ref double func, double[] grad, object o) => {
    270         var tupel = compiledFunc.Differentiate(c, x);
    271         func = tupel.Item2;
    272         Array.Copy(tupel.Item1, grad, grad.Length);
     330    private static alglib.ndimensional_pgrad CreatePGrad(TreeToAutoDiffTermConverter.ParametricFunctionGradient func_grad) {
     331      return (double[] c, double[] x, ref double fx, double[] grad, object o) => {
     332        var tuple = func_grad(c, x);
     333        fx = tuple.Item2;
     334        Array.Copy(tuple.Item1, grad, grad.Length);
     335        var counter = (EvaluationsCounter)o;
     336        counter.GradientEvaluations++;
    273337      };
    274338    }
    275 
    276     private static bool TryTransformToAutoDiff(ISymbolicExpressionTreeNode node, List<AutoDiff.Variable> variables, List<AutoDiff.Variable> parameters, List<string> variableNames, out AutoDiff.Term term) {
    277       if (node.Symbol is Constant) {
    278         var var = new AutoDiff.Variable();
    279         variables.Add(var);
    280         term = var;
    281         return true;
    282       }
    283       if (node.Symbol is Variable) {
    284         var varNode = node as VariableTreeNode;
    285         var par = new AutoDiff.Variable();
    286         parameters.Add(par);
    287         variableNames.Add(varNode.VariableName);
    288         var w = new AutoDiff.Variable();
    289         variables.Add(w);
    290         term = AutoDiff.TermBuilder.Product(w, par);
    291         return true;
    292       }
    293       if (node.Symbol is Addition) {
    294         List<AutoDiff.Term> terms = new List<Term>();
    295         foreach (var subTree in node.Subtrees) {
    296           AutoDiff.Term t;
    297           if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, out t)) {
    298             term = null;
    299             return false;
    300           }
    301           terms.Add(t);
    302         }
    303         term = AutoDiff.TermBuilder.Sum(terms);
    304         return true;
    305       }
    306       if (node.Symbol is Subtraction) {
    307         List<AutoDiff.Term> terms = new List<Term>();
    308         for (int i = 0; i < node.SubtreeCount; i++) {
    309           AutoDiff.Term t;
    310           if (!TryTransformToAutoDiff(node.GetSubtree(i), variables, parameters, variableNames, out t)) {
    311             term = null;
    312             return false;
    313           }
    314           if (i > 0) t = -t;
    315           terms.Add(t);
    316         }
    317         term = AutoDiff.TermBuilder.Sum(terms);
    318         return true;
    319       }
    320       if (node.Symbol is Multiplication) {
    321         AutoDiff.Term a, b;
    322         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out a) ||
    323           !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, out b)) {
    324           term = null;
    325           return false;
    326         } else {
    327           List<AutoDiff.Term> factors = new List<Term>();
    328           foreach (var subTree in node.Subtrees.Skip(2)) {
    329             AutoDiff.Term f;
    330             if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, out f)) {
    331               term = null;
    332               return false;
    333             }
    334             factors.Add(f);
    335           }
    336           term = AutoDiff.TermBuilder.Product(a, b, factors.ToArray());
    337           return true;
    338         }
    339       }
    340       if (node.Symbol is Division) {
    341         // only works for at least two subtrees
    342         AutoDiff.Term a, b;
    343         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out a) ||
    344           !TryTransformToAutoDiff(node.GetSubtree(1), variables, parameters, variableNames, out b)) {
    345           term = null;
    346           return false;
    347         } else {
    348           List<AutoDiff.Term> factors = new List<Term>();
    349           foreach (var subTree in node.Subtrees.Skip(2)) {
    350             AutoDiff.Term f;
    351             if (!TryTransformToAutoDiff(subTree, variables, parameters, variableNames, out f)) {
    352               term = null;
    353               return false;
    354             }
    355             factors.Add(1.0 / f);
    356           }
    357           term = AutoDiff.TermBuilder.Product(a, 1.0 / b, factors.ToArray());
    358           return true;
    359         }
    360       }
    361       if (node.Symbol is Logarithm) {
    362         AutoDiff.Term t;
    363         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    364           term = null;
    365           return false;
    366         } else {
    367           term = AutoDiff.TermBuilder.Log(t);
    368           return true;
    369         }
    370       }
    371       if (node.Symbol is Exponential) {
    372         AutoDiff.Term t;
    373         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    374           term = null;
    375           return false;
    376         } else {
    377           term = AutoDiff.TermBuilder.Exp(t);
    378           return true;
    379         }
    380       } if (node.Symbol is Sine) {
    381         AutoDiff.Term t;
    382         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    383           term = null;
    384           return false;
    385         } else {
    386           term = sin(t);
    387           return true;
    388         }
    389       } if (node.Symbol is Cosine) {
    390         AutoDiff.Term t;
    391         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    392           term = null;
    393           return false;
    394         } else {
    395           term = cos(t);
    396           return true;
    397         }
    398       } if (node.Symbol is Tangent) {
    399         AutoDiff.Term t;
    400         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    401           term = null;
    402           return false;
    403         } else {
    404           term = tan(t);
    405           return true;
    406         }
    407       }
    408       if (node.Symbol is Square) {
    409         AutoDiff.Term t;
    410         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    411           term = null;
    412           return false;
    413         } else {
    414           term = square(t);
    415           return true;
    416         }
    417       } if (node.Symbol is Erf) {
    418         AutoDiff.Term t;
    419         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    420           term = null;
    421           return false;
    422         } else {
    423           term = erf(t);
    424           return true;
    425         }
    426       } if (node.Symbol is Norm) {
    427         AutoDiff.Term t;
    428         if (!TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out t)) {
    429           term = null;
    430           return false;
    431         } else {
    432           term = norm(t);
    433           return true;
    434         }
    435       }
    436       if (node.Symbol is StartSymbol) {
    437         var alpha = new AutoDiff.Variable();
    438         var beta = new AutoDiff.Variable();
    439         variables.Add(beta);
    440         variables.Add(alpha);
    441         AutoDiff.Term branchTerm;
    442         if (TryTransformToAutoDiff(node.GetSubtree(0), variables, parameters, variableNames, out branchTerm)) {
    443           term = branchTerm * alpha + beta;
    444           return true;
    445         } else {
    446           term = null;
    447           return false;
    448         }
    449       }
    450       term = null;
    451       return false;
    452     }
    453 
    454339    public static bool CanOptimizeConstants(ISymbolicExpressionTree tree) {
    455       var containsUnknownSymbol = (
    456         from n in tree.Root.GetSubtree(0).IterateNodesPrefix()
    457         where
    458          !(n.Symbol is Variable) &&
    459          !(n.Symbol is Constant) &&
    460          !(n.Symbol is Addition) &&
    461          !(n.Symbol is Subtraction) &&
    462          !(n.Symbol is Multiplication) &&
    463          !(n.Symbol is Division) &&
    464          !(n.Symbol is Logarithm) &&
    465          !(n.Symbol is Exponential) &&
    466          !(n.Symbol is Sine) &&
    467          !(n.Symbol is Cosine) &&
    468          !(n.Symbol is Tangent) &&
    469          !(n.Symbol is Square) &&
    470          !(n.Symbol is Erf) &&
    471          !(n.Symbol is Norm) &&
    472          !(n.Symbol is StartSymbol)
    473         select n).
    474       Any();
    475       return !containsUnknownSymbol;
     340      return TreeToAutoDiffTermConverter.IsCompatible(tree);
    476341    }
    477342  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionLogResidualEvaluator.cs

    r10486 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3838                                  "This effects GP convergence because functional fragments which are necessary to explain small variations are also more likely" +
    3939                                  " to stay in the population. This is useful even when the actual objective function is mean of squared errors.")]
    40   [StorableClass]
     40  [StorableType("8CEA1A56-167D-481B-9167-C1DED8E06680")]
    4141  public class SymbolicRegressionLogResidualEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    4242    [StorableConstructor]
    43     protected SymbolicRegressionLogResidualEvaluator(bool deserializing) : base(deserializing) { }
     43    protected SymbolicRegressionLogResidualEvaluator(StorableConstructorFlag _) : base(_) { }
    4444    protected SymbolicRegressionLogResidualEvaluator(SymbolicRegressionLogResidualEvaluator original, Cloner cloner)
    4545      : base(original, cloner) {
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionMeanRelativeErrorEvaluator.cs

    r10432 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3333                                         "The +1 is necessary to handle data with the value of 0.0 correctly. " +
    3434                                         "Notice: Linear scaling is ignored for this evaluator.")]
    35   [StorableClass]
     35  [StorableType("8A5AAF93-5338-4E11-B3B2-3D9274329E5F")]
    3636  public class SymbolicRegressionMeanRelativeErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3737    public override bool Maximization { get { return false; } }
    3838    [StorableConstructor]
    39     protected SymbolicRegressionMeanRelativeErrorEvaluator(bool deserializing) : base(deserializing) { }
     39    protected SymbolicRegressionMeanRelativeErrorEvaluator(StorableConstructorFlag _) : base(_) { }
    4040    protected SymbolicRegressionMeanRelativeErrorEvaluator(SymbolicRegressionMeanRelativeErrorEvaluator original, Cloner cloner)
    4141      : base(original, cloner) {
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    2522using HeuristicLab.Common;
    26 using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    28 using HeuristicLab.Parameters;
    29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     23using HEAL.Attic;
    3024namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    31   [StorableClass]
     25  [StorableType("7EB90F03-4385-474F-BDE7-3B133E8FEAAB")]
    3226  public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 
    3327    [StorableConstructor]
    34     protected SymbolicRegressionSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
     28    protected SymbolicRegressionSingleObjectiveEvaluator(StorableConstructorFlag _) : base(_) { }
    3529    protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { }
    3630    protected SymbolicRegressionSingleObjectiveEvaluator(): base() {}   
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs

    r10291 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3030  [Item("Maximum absolute error Evaluator", "Calculates the maximum squared error of a symbolic regression solution.")]
    31   [StorableClass]
     31  [StorableType("256A6405-D1EE-4D8D-963A-42C56FEE8571")]
    3232  public class SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3333    public override bool Maximization { get { return false; } }
    3434    [StorableConstructor]
    35     protected SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator(bool deserializing) : base(deserializing) { }
     35    protected SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator(StorableConstructorFlag _) : base(_) { }
    3636    protected SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator(SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator original, Cloner cloner)
    3737      : base(original, cloner) {
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs

    r10291 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3030  [Item("Mean absolute error Evaluator", "Calculates the mean absolute error of a symbolic regression solution.")]
    31   [StorableClass]
     31  [StorableType("8ABB1AC3-0ACE-43AB-8E6B-B0FC925429DC")]
    3232  public class SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3333    public override bool Maximization { get { return false; } }
    3434    [StorableConstructor]
    35     protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(bool deserializing) : base(deserializing) { }
     35    protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(StorableConstructorFlag _) : base(_) { }
    3636    protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator original, Cloner cloner)
    3737      : base(original, cloner) {
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs

    r10291 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3030  [Item("Mean squared error Evaluator", "Calculates the mean squared error of a symbolic regression solution.")]
    31   [StorableClass]
     31  [StorableType("8D4B5243-1635-46A6-AEF9-18C9BCB725DD")]
    3232  public class SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3333    public override bool Maximization { get { return false; } }
    3434    [StorableConstructor]
    35     protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { }
     35    protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(StorableConstructorFlag _) : base(_) { }
    3636    protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator original, Cloner cloner)
    3737      : base(original, cloner) {
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r10291 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3030  [Item("Pearson R² Evaluator", "Calculates the square of the pearson correlation coefficient (also known as coefficient of determination) of a symbolic regression solution.")]
    31   [StorableClass]
     31  [StorableType("6FAEC6C2-C747-452A-A60D-29AE37898A90")]
    3232  public class SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
    3333    [StorableConstructor]
    34     protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(bool deserializing) : base(deserializing) { }
     34    protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(StorableConstructorFlag _) : base(_) { }
    3535    protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator original, Cloner cloner)
    3636      : base(original, cloner) {
     
    5959      OnlineCalculatorError errorState;
    6060
    61       double r2;
     61      double r;
    6262      if (applyLinearScaling) {
    63         var r2Calculator = new OnlinePearsonsRSquaredCalculator();
    64         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
    65         errorState = r2Calculator.ErrorState;
    66         r2 = r2Calculator.RSquared;
     63        var rCalculator = new OnlinePearsonsRCalculator();
     64        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows);
     65        errorState = rCalculator.ErrorState;
     66        r = rCalculator.R;
    6767      } else {
    6868        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    69         r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     69        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    7070      }
    7171      if (errorState != OnlineCalculatorError.None) return double.NaN;
    72       return r2;
     72      return r*r;
    7373    }
    7474
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs

    r10576 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2828using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3333  [Item("SymbolicRegressionSingleObjectiveOverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic regression models.")]
    34   [StorableClass]
     34  [StorableType("AE1F0A23-BEB1-47AF-8ECF-DBCFD32AA5A9")]
    3535  public sealed class SymbolicRegressionSingleObjectiveOverfittingAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> {
    3636    private const string TrainingValidationCorrelationParameterName = "Training and validation fitness correlation";
     
    5959
    6060    [StorableConstructor]
    61     private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(bool deserializing) : base(deserializing) { }
     61    private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(StorableConstructorFlag _) : base(_) { }
    6262    private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(SymbolicRegressionSingleObjectiveOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { }
    6363    public SymbolicRegressionSingleObjectiveOverfittingAnalyzer()
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r10596 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Optimization;
    2526using HeuristicLab.Parameters;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HEAL.Attic;
    2728
    2829namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    29   [Item("Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem.")]
    30   [StorableClass]
    31   [Creatable("Problems")]
     30  [Item("Symbolic Regression Problem (single-objective)", "Represents a single objective symbolic regression problem.")]
     31  [StorableType("7DDCF683-96FC-4F70-BF4F-FE3A0B0DE6E0")]
     32  [Creatable(CreatableAttribute.Categories.GeneticProgrammingProblems, Priority = 100)]
    3233  public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem {
    3334    private const double PunishmentFactor = 10;
     
    4849    #endregion
    4950    [StorableConstructor]
    50     protected SymbolicRegressionSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
     51    protected SymbolicRegressionSingleObjectiveProblem(StorableConstructorFlag _) : base(_) { }
    5152    protected SymbolicRegressionSingleObjectiveProblem(SymbolicRegressionSingleObjectiveProblem original, Cloner cloner)
    5253      : base(original, cloner) {
     
    111112      Operators.Add(new SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer());
    112113      Operators.Add(new SymbolicRegressionSolutionsAnalyzer());
    113 
     114      Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator());
     115      Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Diversity" });
    114116      ParameterizeOperators();
    115117    }
     
    141143        }
    142144      }
     145
     146      foreach (var op in Operators.OfType<ISolutionSimilarityCalculator>()) {
     147        op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     148        op.QualityVariableName = Evaluator.QualityParameter.ActualName;
     149
     150        if (op is SymbolicExpressionTreePhenotypicSimilarityCalculator) {
     151          var phenotypicSimilarityCalculator = (SymbolicExpressionTreePhenotypicSimilarityCalculator)op;
     152          phenotypicSimilarityCalculator.ProblemData = ProblemData;
     153          phenotypicSimilarityCalculator.Interpreter = SymbolicExpressionTreeInterpreter;
     154        }
     155      }
    143156    }
    144157  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2525using HeuristicLab.Parameters;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3131  /// </summary>
    3232  [Item("SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic regression solution for single objective symbolic regression problems.")]
    33   [StorableClass]
     33  [StorableType("85786F8E-F84D-4909-9A66-620668B0C7FB")]
    3434  public sealed class SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicRegressionSolution>,
    3535  ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
     
    5050
    5151    [StorableConstructor]
    52     private SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     52    private SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { }
    5353    private SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    5454    public SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer()
     
    6363
    6464    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    65       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     65      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    6666      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    6767      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HEAL.Attic;
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3030  /// </summary>
    3131  [Item("SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer", "An operator that collects the training Pareto-best symbolic regression solutions for single objective symbolic regression problems.")]
    32   [StorableClass]
     32  [StorableType("8FDF5528-8E95-44D6-AFFD-433B4AA55559")]
    3333  public sealed class SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IRegressionProblemData, ISymbolicRegressionSolution> {
    3434
    3535    [StorableConstructor]
    36     private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     36    private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { }
    3737    private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    3838    public SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer() : base() { }
     
    4242
    4343    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    44       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     44      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    4545      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    4646      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2525using HeuristicLab.Parameters;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HEAL.Attic;
    2727
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3131  /// </summary>
    3232  [Item("SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer", "An operator that analyzes the validation best symbolic regression solution for single objective symbolic regression problems.")]
    33   [StorableClass]
     33  [StorableType("75E2AFFF-95B2-4FA4-8544-CF2025B65820")]
    3434  public sealed class SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData>,
    3535    ISymbolicDataAnalysisBoundedOperator {
     
    4343
    4444    [StorableConstructor]
    45     private SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     45    private SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { }
    4646    private SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    4747    public SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer()
     
    5555
    5656    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    57       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     57      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    5858      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    5959      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs

    r9456 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HEAL.Attic;
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3030  /// </summary>
    3131  [Item("SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer", "An operator that collects the validation Pareto-best symbolic regression solutions for single objective symbolic regression problems.")]
    32   [StorableClass]
     32  [StorableType("B58782FE-FAC0-4B03-9210-CAE5CF74357B")]
    3333  public sealed class SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> {
    3434    [StorableConstructor]
    35     private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
     35    private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { }
    3636    private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
    3737    public SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer() : base() { }
     
    4242
    4343    protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree) {
    44       var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
     44      var model = new SymbolicRegressionModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
    4545      if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
    4646      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSolutionsAnalyzer.cs

    r10596 r17687  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    2222#endregion
    2323
    24 using System;
    2524using System.Linq;
    2625using HeuristicLab.Analysis;
    2726using HeuristicLab.Common;
    2827using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2929using HeuristicLab.Operators;
    3030using HeuristicLab.Optimization;
    3131using HeuristicLab.Parameters;
    32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HEAL.Attic;
    3333
    3434namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     35  [StorableType("789E0217-6DDC-44E8-85CC-A51A976A8FB8")]
    3536  public class SymbolicRegressionSolutionsAnalyzer : SingleSuccessorOperator, IAnalyzer {
    3637    private const string ResultCollectionParameterName = "Results";
    3738    private const string RegressionSolutionQualitiesResultName = "Regression Solution Qualities";
     39    private const string TrainingQualityParameterName = "TrainingRSquared";
     40    private const string TestQualityParameterName = "TestRSquared";
    3841
    3942    public ILookupParameter<ResultCollection> ResultCollectionParameter {
    4043      get { return (ILookupParameter<ResultCollection>)Parameters[ResultCollectionParameterName]; }
     44    }
     45    public ILookupParameter<DoubleValue> TrainingQualityParameter {
     46      get { return (ILookupParameter<DoubleValue>)Parameters[TrainingQualityParameterName]; }
     47    }
     48    public ILookupParameter<DoubleValue> TestQualityParameter {
     49      get { return (ILookupParameter<DoubleValue>)Parameters[TestQualityParameterName]; }
    4150    }
    4251
     
    4655
    4756    [StorableConstructor]
    48     protected SymbolicRegressionSolutionsAnalyzer(bool deserializing) : base(deserializing) { }
     57    protected SymbolicRegressionSolutionsAnalyzer(StorableConstructorFlag _) : base(_) { }
    4958    protected SymbolicRegressionSolutionsAnalyzer(SymbolicRegressionSolutionsAnalyzer original, Cloner cloner)
    5059      : base(original, cloner) { }
     
    5564    public SymbolicRegressionSolutionsAnalyzer() {
    5665      Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName, "The result collection to store the analysis results."));
     66      Parameters.Add(new LookupParameter<DoubleValue>(TrainingQualityParameterName));
     67      Parameters.Add(new LookupParameter<DoubleValue>(TestQualityParameterName));
     68    }
     69
     70    [StorableHook(HookType.AfterDeserialization)]
     71    private void AfterDeserialization() {
     72      // BackwardsCompatibility3.3
     73
     74      #region Backwards compatible code, remove with 3.4
     75      if (!Parameters.ContainsKey(TrainingQualityParameterName))
     76        Parameters.Add(new LookupParameter<DoubleValue>(TrainingQualityParameterName));
     77      if (!Parameters.ContainsKey(TestQualityParameterName))
     78        Parameters.Add(new LookupParameter<DoubleValue>(TestQualityParameterName));
     79      #endregion
    5780    }
    5881
     
    6689
    6790      var dataTable = (DataTable)results[RegressionSolutionQualitiesResultName].Value;
     91
     92      // only if the parameters are available (not available in old persisted code)
     93      ILookupParameter<DoubleValue> trainingQualityParam = null;
     94      ILookupParameter<DoubleValue> testQualityParam = null;
     95      // store actual names of parameter because it is changed below
     96      trainingQualityParam = TrainingQualityParameter;
     97      string prevTrainingQualityParamName = trainingQualityParam.ActualName;
     98      testQualityParam = TestQualityParameter;
     99      string prevTestQualityParamName = testQualityParam.ActualName;
    68100      foreach (var result in results.Where(r => r.Value is IRegressionSolution)) {
    69101        var solution = (IRegressionSolution)result.Value;
    70102
    71         var trainingR2 = result.Name + Environment.NewLine + "Training R²";
    72         if (!dataTable.Rows.ContainsKey(trainingR2))
    73           dataTable.Rows.Add(new DataRow(trainingR2));
     103        var trainingR2Name = result.Name + " Training R²";
     104        if (!dataTable.Rows.ContainsKey(trainingR2Name))
     105          dataTable.Rows.Add(new DataRow(trainingR2Name));
    74106
    75         var testR2 = result.Name + Environment.NewLine + " Test R²";
    76         if (!dataTable.Rows.ContainsKey(testR2))
    77           dataTable.Rows.Add(new DataRow(testR2));
     107        var testR2Name = result.Name + " Test R²";
     108        if (!dataTable.Rows.ContainsKey(testR2Name))
     109          dataTable.Rows.Add(new DataRow(testR2Name));
    78110
    79         dataTable.Rows[trainingR2].Values.Add(solution.TrainingRSquared);
    80         dataTable.Rows[testR2].Values.Add(solution.TestRSquared);
     111        dataTable.Rows[trainingR2Name].Values.Add(solution.TrainingRSquared);
     112        dataTable.Rows[testR2Name].Values.Add(solution.TestRSquared);
     113
     114        // also add training and test R² to the scope using the parameters
     115        // HACK: we change the ActualName of the parameter to write two variables for each solution in the results collection
     116        trainingQualityParam.ActualName = trainingR2Name;
     117        trainingQualityParam.ActualValue = new DoubleValue(solution.TrainingRSquared);
     118        testQualityParam.ActualName = testR2Name;
     119        testQualityParam.ActualValue = new DoubleValue(solution.TestRSquared);
    81120      }
     121
     122      trainingQualityParam.ActualName = prevTrainingQualityParamName;
     123      testQualityParam.ActualName = prevTestQualityParamName;
    82124
    83125      return base.Apply();
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SlidingWindow/GenerationalRegressionSlidingWindowAnalyzer.cs

    r10720 r17687  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Optimization;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HEAL.Attic;
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    28   [StorableClass]
    2928  [Item("Generational Regression Sliding Window Analyzer", "")]
     29  [StorableType("9157AEF9-838B-48EC-9E0B-CE75F8A1FF8D")]
    3030  public class GenerationalRegressionSlidingWindowAnalyzer : GenerationalSlidingWindowAnalyzer {
    3131    [StorableConstructor]
    32     protected GenerationalRegressionSlidingWindowAnalyzer(bool deserializing) : base(deserializing) { }
     32    protected GenerationalRegressionSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { }
    3333    [StorableHook(HookType.AfterDeserialization)]
    3434    private void AfterDeserialization() { }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SlidingWindow/OffspringSelectionRegressionSlidingWindowAnalyzer.cs

    r10720 r17687  
    2424using HeuristicLab.Optimization;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HEAL.Attic;
    2627
    2728namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    28   [StorableClass]
    2929  [Item("OffspringSelectionRegressionSlidingWindowAnalyzer", "")]
     30  [StorableType("821B7755-1914-416A-AF83-55B0BF74E26A")]
    3031  public class OffspringSelectionRegressionSlidingWindowAnalyzer : OffspringSelectionSlidingWindowAnalyzer {
    3132    [StorableConstructor]
    32     protected OffspringSelectionRegressionSlidingWindowAnalyzer(bool deserializing) : base(deserializing) { }
     33    protected OffspringSelectionRegressionSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { }
    3334    [StorableHook(HookType.AfterDeserialization)]
    3435    private void AfterDeserialization() { }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SlidingWindow/SlidingWindowBestRegressionSolutionsCollection.cs

    r10681 r17687  
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HEAL.Attic;
    2627
    2728namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    28   [StorableClass]
    2929  [Item("SlidingWindowBestRegressionSolutionsCollection", "A collection of best sliding window solutions for symbolic regression.")]
     30  [StorableType("8F78030E-16F3-42CD-ABE7-0526E4738676")]
    3031  public class SlidingWindowBestRegressionSolutionsCollection : SlidingWindowBestSolutionsCollection {
    3132    public new IRegressionProblemData ProblemData {
     
    3435    }
    3536    [StorableConstructor]
    36     protected SlidingWindowBestRegressionSolutionsCollection(bool deserializing) : base(deserializing) { }
     37    protected SlidingWindowBestRegressionSolutionsCollection(StorableConstructorFlag _) : base(_) { }
    3738    [StorableHook(HookType.AfterDeserialization)]
    3839    private void AfterDeserialization() { }
     
    4647    public override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    4748      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue) {
    48       return new SymbolicRegressionModel(tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
     49      return new SymbolicRegressionModel(ProblemData.TargetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
    4950    }
    5051    public override ISymbolicDataAnalysisSolution CreateSolution(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData) {
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r9587 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HEAL.Attic;
    2728
    2829namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3031  /// Represents a symbolic regression model
    3132  /// </summary>
    32   [StorableClass]
     33  [StorableType("2739C33E-4DDB-4285-9DFB-C056D900B2F2")]
    3334  [Item(Name = "Symbolic Regression Model", Description = "Represents a symbolic regression model.")]
    3435  public class SymbolicRegressionModel : SymbolicDataAnalysisModel, ISymbolicRegressionModel {
    35 
     36    [Storable]
     37    private string targetVariable;
     38    public string TargetVariable {
     39      get { return targetVariable; }
     40      set {
     41        if (string.IsNullOrEmpty(value) || targetVariable == value) return;
     42        targetVariable = value;
     43        OnTargetVariableChanged(this, EventArgs.Empty);
     44      }
     45    }
    3646
    3747    [StorableConstructor]
    38     protected SymbolicRegressionModel(bool deserializing) : base(deserializing) { }
    39     protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner) : base(original, cloner) { }
     48    protected SymbolicRegressionModel(StorableConstructorFlag _) : base(_) {
     49      targetVariable = string.Empty;
     50    }
    4051
    41     public SymbolicRegressionModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     52    protected SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner)
     53      : base(original, cloner) {
     54      this.targetVariable = original.targetVariable;
     55    }
     56
     57    public SymbolicRegressionModel(string targetVariable, ISymbolicExpressionTree tree,
     58      ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    4259      double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue)
    43       : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) { }
     60      : base(tree, interpreter, lowerEstimationLimit, upperEstimationLimit) {
     61      this.targetVariable = targetVariable;
     62    }
    4463
    4564    public override IDeepCloneable Clone(Cloner cloner) {
     
    4766    }
    4867
    49     public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
     68    public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    5069      return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows)
    5170        .LimitToRange(LowerEstimationLimit, UpperEstimationLimit);
     
    6281      Scale(problemData, problemData.TargetVariable);
    6382    }
     83
     84    public virtual bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
     85      return RegressionModel.IsProblemDataCompatible(this, problemData, out errorMessage);
     86    }
     87
     88    public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) {
     89      if (problemData == null) throw new ArgumentNullException("problemData", "The provided problemData is null.");
     90      var regressionProblemData = problemData as IRegressionProblemData;
     91      if (regressionProblemData == null)
     92        throw new ArgumentException("The problem data is not compatible with this symbolic regression model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     93      return IsProblemDataCompatible(regressionProblemData, out errorMessage);
     94    }
     95
     96    #region events
     97    public event EventHandler TargetVariableChanged;
     98    private void OnTargetVariableChanged(object sender, EventArgs args) {
     99      var changed = TargetVariableChanged;
     100      if (changed != null)
     101        changed(sender, args);
     102    }
     103    #endregion
    64104  }
    65105}
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs

    r10469 r17687  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
     
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2627using HeuristicLab.Parameters;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HEAL.Attic;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3031  [Item("SymbolicRegressionPruningAnalyzer", "An analyzer that prunes introns from the population.")]
    31   [StorableClass]
     32  [StorableType("F1180389-1393-4102-9EEC-E4F183A017F2")]
    3233  public sealed class SymbolicRegressionPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer {
    33     private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";
    3434    private const string PruningOperatorParameterName = "PruningOperator";
    35     private SymbolicRegressionPruningAnalyzer(SymbolicRegressionPruningAnalyzer original, Cloner cloner)
    36       : base(original, cloner) {
    37     }
    38     public override IDeepCloneable Clone(Cloner cloner) {
    39       return new SymbolicRegressionPruningAnalyzer(this, cloner);
     35    public IValueParameter<SymbolicRegressionPruningOperator> PruningOperatorParameter {
     36      get { return (IValueParameter<SymbolicRegressionPruningOperator>)Parameters[PruningOperatorParameterName]; }
    4037    }
    4138
     39    protected override SymbolicDataAnalysisExpressionPruningOperator PruningOperator {
     40      get { return PruningOperatorParameter.Value; }
     41    }
     42
     43    private SymbolicRegressionPruningAnalyzer(SymbolicRegressionPruningAnalyzer original, Cloner cloner) : base(original, cloner) { }
     44    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionPruningAnalyzer(this, cloner); }
     45
    4246    [StorableConstructor]
    43     private SymbolicRegressionPruningAnalyzer(bool deserializing) : base(deserializing) { }
     47    private SymbolicRegressionPruningAnalyzer(StorableConstructorFlag _) : base(_) { }
    4448
    4549    public SymbolicRegressionPruningAnalyzer() {
    46       Parameters.Add(new ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, "The impact values calculator", new SymbolicRegressionSolutionImpactValuesCalculator()));
    47       Parameters.Add(new ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator()));
     50      Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
     51    }
     52
     53    [StorableHook(HookType.AfterDeserialization)]
     54    private void AfterDeserialization() {
     55      // BackwardsCompatibility3.3
     56
     57      #region Backwards compatible code, remove with 3.4
     58      if (Parameters.ContainsKey(PruningOperatorParameterName)) {
     59        var oldParam = Parameters[PruningOperatorParameterName] as ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>;
     60        if (oldParam != null) {
     61          Parameters.Remove(oldParam);
     62          Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
     63        }
     64      } else {
     65        // not yet contained
     66        Parameters.Add(new ValueParameter<SymbolicRegressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator(new SymbolicRegressionSolutionImpactValuesCalculator())));
     67      }
     68
     69
     70      if (Parameters.ContainsKey("PruneOnlyZeroImpactNodes")) {
     71        PruningOperator.PruneOnlyZeroImpactNodes = ((IFixedValueParameter<BoolValue>)Parameters["PruneOnlyZeroImpactNodes"]).Value.Value;
     72        Parameters.Remove(Parameters["PruneOnlyZeroImpactNodes"]);
     73      }
     74      if (Parameters.ContainsKey("ImpactThreshold")) {
     75        PruningOperator.NodeImpactThreshold = ((IFixedValueParameter<DoubleValue>)Parameters["ImpactThreshold"]).Value.Value;
     76        Parameters.Remove(Parameters["ImpactThreshold"]);
     77      }
     78      if (Parameters.ContainsKey("ImpactValuesCalculator")) {
     79        PruningOperator.ImpactValuesCalculator = ((ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters["ImpactValuesCalculator"]).Value;
     80        Parameters.Remove(Parameters["ImpactValuesCalculator"]);
     81      }
     82
     83      #endregion
    4884    }
    4985  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r10469 r17687  
    1 using System.Linq;
     1#region License Information
     2
     3/* HeuristicLab
     4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     5 *
     6 * This file is part of HeuristicLab.
     7 *
     8 * HeuristicLab is free software: you can redistribute it and/or modify
     9 * it under the terms of the GNU General Public License as published by
     10 * the Free Software Foundation, either version 3 of the License, or
     11 * (at your option) any later version.
     12 *
     13 * HeuristicLab is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 * GNU General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU General Public License
     19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     20 */
     21
     22#endregion
     23
     24using System.Collections.Generic;
     25using System.Linq;
    226using HeuristicLab.Common;
    327using HeuristicLab.Core;
     28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    429using HeuristicLab.Parameters;
    5 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HEAL.Attic;
    631
    732namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    8   [StorableClass]
     33  [StorableType("75843B4E-C69C-423A-87BD-A64619D380BB")]
    934  [Item("SymbolicRegressionPruningOperator", "An operator which prunes symbolic regression trees.")]
    1035  public class SymbolicRegressionPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
    11     private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";
    12     private const string ImpactValuesCalculatorParameterDescription = "The impact values calculator to be used for figuring out the node impacts.";
    13 
    1436    private const string EvaluatorParameterName = "Evaluator";
    1537
     38    #region parameter properties
    1639    public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
    1740      get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
    1841    }
     42    #endregion
    1943
    2044    protected SymbolicRegressionPruningOperator(SymbolicRegressionPruningOperator original, Cloner cloner)
     
    2650
    2751    [StorableConstructor]
    28     protected SymbolicRegressionPruningOperator(bool deserializing) : base(deserializing) { }
     52    protected SymbolicRegressionPruningOperator(StorableConstructorFlag _) : base(_) { }
    2953
    30     public SymbolicRegressionPruningOperator() {
    31       var impactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
    32       Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, ImpactValuesCalculatorParameterDescription, impactValuesCalculator));
     54    public SymbolicRegressionPruningOperator(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactValuesCalculator)
     55      : base(impactValuesCalculator) {
    3356      Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
    3457    }
    3558
    36     protected override ISymbolicDataAnalysisModel CreateModel() {
    37       return new SymbolicRegressionModel(SymbolicExpressionTree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper);
     59    [StorableHook(HookType.AfterDeserialization)]
     60    private void AfterDeserialization() {
     61      // BackwardsCompatibility3.3
     62      #region Backwards compatible code, remove with 3.4
     63      base.ImpactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
     64      if (!Parameters.ContainsKey(EvaluatorParameterName)) {
     65        Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
     66      }
     67      #endregion
     68    }
     69
     70    protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IDataAnalysisProblemData problemData, DoubleLimit estimationLimits) {
     71      var regressionProblemData = (IRegressionProblemData)problemData;
     72      return new SymbolicRegressionModel(regressionProblemData.TargetVariable, tree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
    3873    }
    3974
    4075    protected override double Evaluate(IDataAnalysisModel model) {
    41       var regressionModel = (IRegressionModel)model;
    42       var regressionProblemData = (IRegressionProblemData)ProblemData;
    43       var trainingIndices = ProblemData.TrainingIndices.ToList();
    44       var estimatedValues = regressionModel.GetEstimatedValues(ProblemData.Dataset, trainingIndices); // also bounds the values
    45       var targetValues = ProblemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, trainingIndices);
    46       OnlineCalculatorError errorState;
    47       var quality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
    48       if (errorState != OnlineCalculatorError.None) return double.NaN;
    49       return quality;
     76      var regressionModel = (ISymbolicRegressionModel)model;
     77      var regressionProblemData = (IRegressionProblemData)ProblemDataParameter.ActualValue;
     78      var evaluator = EvaluatorParameter.ActualValue;
     79      var fitnessEvaluationPartition = FitnessCalculationPartitionParameter.ActualValue;
     80      var rows = Enumerable.Range(fitnessEvaluationPartition.Start, fitnessEvaluationPartition.Size);
     81      return evaluator.Evaluate(this.ExecutionContext, regressionModel.SymbolicExpressionTree, regressionProblemData, rows);
     82    }
     83
     84    public static ISymbolicExpressionTree Prune(ISymbolicExpressionTree tree, SymbolicRegressionSolutionImpactValuesCalculator impactValuesCalculator, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, IRegressionProblemData problemData, DoubleLimit estimationLimits, IEnumerable<int> rows, double nodeImpactThreshold = 0.0, bool pruneOnlyZeroImpactNodes = false) {
     85      var clonedTree = (ISymbolicExpressionTree)tree.Clone();
     86      var model = new SymbolicRegressionModel(problemData.TargetVariable, clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
     87      var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol
     88
     89      double qualityForImpactsCalculation = double.NaN; // pass a NaN value initially so the impact calculator will calculate the quality
     90
     91      for (int i = 0; i < nodes.Count; ++i) {
     92        var node = nodes[i];
     93        if (node is ConstantTreeNode) continue;
     94
     95        double impactValue, replacementValue;
     96        double newQualityForImpactsCalculation;
     97        impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
     98
     99        if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
     100        if (!pruneOnlyZeroImpactNodes && impactValue > nodeImpactThreshold) continue;
     101
     102        var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
     103        constantNode.Value = replacementValue;
     104
     105        ReplaceWithConstant(node, constantNode);
     106        i += node.GetLength() - 1; // skip subtrees under the node that was folded
     107
     108        qualityForImpactsCalculation = newQualityForImpactsCalculation;
     109      }
     110      return model.SymbolicExpressionTree;
    50111    }
    51112  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r9456 r17687  
    1 #region License Information
     1#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System.Linq;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Data;
     27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2628using HeuristicLab.Optimization;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    3132  /// Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity
    3233  /// </summary>
    33   [StorableClass]
     34  [StorableType("88E56AF9-AD72-47E4-A613-8875703BD927")]
    3435  [Item(Name = "SymbolicRegressionSolution", Description = "Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity.")]
    3536  public sealed class SymbolicRegressionSolution : RegressionSolution, ISymbolicRegressionSolution {
     
    4647    private const string TestNaNEvaluationsResultName = "Test NaN Evaluations";
    4748
     49    private const string ModelBoundsResultName = "Model Bounds";
     50
    4851    public new ISymbolicRegressionModel Model {
    4952      get { return (ISymbolicRegressionModel)base.Model; }
     
    9598    }
    9699
     100    public IntervalCollection ModelBoundsCollection {
     101      get {
     102        if (!ContainsKey(ModelBoundsResultName)) return null;
     103        return (IntervalCollection)this[ModelBoundsResultName].Value;
     104      }
     105      private set {
     106        if (ContainsKey(ModelBoundsResultName)) {
     107          this[ModelBoundsResultName].Value = value;
     108        } else {
     109          Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", value));
     110        }
     111
     112      }
     113    }
     114
     115
     116
    97117    [StorableConstructor]
    98     private SymbolicRegressionSolution(bool deserializing) : base(deserializing) { }
     118    private SymbolicRegressionSolution(StorableConstructorFlag _) : base(_) { }
    99119    private SymbolicRegressionSolution(SymbolicRegressionSolution original, Cloner cloner)
    100120      : base(original, cloner) {
     
    102122    public SymbolicRegressionSolution(ISymbolicRegressionModel model, IRegressionProblemData problemData)
    103123      : base(model, problemData) {
     124      foreach (var node in model.SymbolicExpressionTree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTopLevelNode>())
     125        node.SetGrammar(null);
     126
    104127      Add(new Result(ModelLengthResultName, "Length of the symbolic regression model.", new IntValue()));
    105128      Add(new Result(ModelDepthResultName, "Depth of the symbolic regression model.", new IntValue()));
     
    114137      estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue()));
    115138      Add(new Result(EstimationLimitsResultsResultName, "Results concerning the estimation limits of symbolic regression solution", estimationLimitResults));
     139
     140      if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree))
     141        Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", new IntervalCollection()));
    116142
    117143      RecalculateResults();
     
    136162        CalculateResults();
    137163      }
     164
     165      if (!ContainsKey(ModelBoundsResultName)) {
     166        if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree)) {
     167          Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", new IntervalCollection()));
     168          CalculateResults();
     169        }
     170      }
    138171    }
    139172
     
    156189      TrainingNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TrainingIndices).Count(double.IsNaN);
    157190      TestNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TestIndices).Count(double.IsNaN);
     191
     192      //Check if the tree contains unknown symbols for the interval calculation
     193      if (IntervalInterpreter.IsCompatible(Model.SymbolicExpressionTree))
     194        ModelBoundsCollection = CalculateModelIntervals(this);
     195    }
     196
     197    private static IntervalCollection CalculateModelIntervals(ISymbolicRegressionSolution solution) {
     198      var intervalEvaluation = new IntervalCollection();
     199      var interpreter = new IntervalInterpreter();
     200      var problemData = solution.ProblemData;
     201      var model = solution.Model;
     202      var variableRanges = problemData.VariableRanges.GetReadonlyDictionary();
     203
     204      intervalEvaluation.AddInterval($"Target {problemData.TargetVariable}", new Interval(variableRanges[problemData.TargetVariable].LowerBound, variableRanges[problemData.TargetVariable].UpperBound));
     205      intervalEvaluation.AddInterval("Model", interpreter.GetSymbolicExpressionTreeInterval(model.SymbolicExpressionTree, variableRanges));
     206
     207      if (DerivativeCalculator.IsCompatible(model.SymbolicExpressionTree)) {
     208        foreach (var inputVariable in model.VariablesUsedForPrediction.OrderBy(v => v, new NaturalStringComparer())) {
     209          var derivedModel = DerivativeCalculator.Derive(model.SymbolicExpressionTree, inputVariable);
     210          var derivedResultInterval = interpreter.GetSymbolicExpressionTreeInterval(derivedModel, variableRanges);
     211
     212          intervalEvaluation.AddInterval(" ∂f/∂" + inputVariable, new Interval(derivedResultInterval.LowerBound, derivedResultInterval.UpperBound));
     213        }
     214      }
     215
     216      return intervalEvaluation;
    158217    }
    159218  }
  • branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs

    r10469 r17687  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HEAL.Attic;
    2826
    2927namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    30   [StorableClass]
     28  [StorableType("927C21BD-8913-406F-ADEA-DA4FED3FE4A2")]
    3129  [Item("SymbolicRegressionSolutionImpactValuesCalculator", "Calculate symbolic expression tree node impact values for regression problems.")]
    3230  public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator {
    3331    public SymbolicRegressionSolutionImpactValuesCalculator() { }
    34 
    3532    protected SymbolicRegressionSolutionImpactValuesCalculator(SymbolicRegressionSolutionImpactValuesCalculator original, Cloner cloner)
    3633      : base(original, cloner) { }
     
    3835      return new SymbolicRegressionSolutionImpactValuesCalculator(this, cloner);
    3936    }
     37    [StorableConstructor]
     38    protected SymbolicRegressionSolutionImpactValuesCalculator(StorableConstructorFlag _) : base(_) { }
    4039
    41     [StorableConstructor]
    42     protected SymbolicRegressionSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    43     public override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) {
     40    protected override double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows) {
    4441      var regressionModel = (ISymbolicRegressionModel)model;
    4542      var regressionProblemData = (IRegressionProblemData)problemData;
    46 
    47       return CalculateReplacementValue(node, regressionModel.SymbolicExpressionTree, regressionModel.Interpreter, regressionProblemData.Dataset, rows);
    48     }
    49 
    50     public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) {
    51       double impactValue, replacementValue;
    52       CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality);
    53       return impactValue;
    54     }
    55 
    56     public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
    57       IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue,
    58       double originalQuality = Double.NaN) {
    59       var regressionModel = (ISymbolicRegressionModel)model;
    60       var regressionProblemData = (IRegressionProblemData)problemData;
    61 
    62       var dataset = regressionProblemData.Dataset;
    63       var targetValues = dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows);
    64 
     43      var estimatedValues = regressionModel.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values
     44      var targetValues = problemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows);
    6545      OnlineCalculatorError errorState;
    66       if (double.IsNaN(originalQuality)) {
    67         var originalValues = regressionModel.GetEstimatedValues(dataset, rows);
    68         originalQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalValues, out errorState);
    69         if (errorState != OnlineCalculatorError.None) originalQuality = 0.0;
    70       }
    71 
    72       replacementValue = CalculateReplacementValue(regressionModel, node, regressionProblemData, rows);
    73       var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue };
    74 
    75       var cloner = new Cloner();
    76       var tempModel = cloner.Clone(regressionModel);
    77       var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);
    78 
    79       var tempModelParentNode = tempModelNode.Parent;
    80       int i = tempModelParentNode.IndexOfSubtree(tempModelNode);
    81       tempModelParentNode.RemoveSubtree(i);
    82       tempModelParentNode.InsertSubtree(i, constantNode);
    83 
    84       var estimatedValues = tempModel.GetEstimatedValues(dataset, rows);
    85       double newQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
    86       if (errorState != OnlineCalculatorError.None) newQuality = 0.0;
    87 
    88       impactValue = originalQuality - newQuality;
     46      var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
     47      var quality = r * r;
     48      if (errorState != OnlineCalculatorError.None) return double.NaN;
     49      return quality;
    8950    }
    9051  }
Note: See TracChangeset for help on using the changeset viewer.