Changeset 17687 for branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Timestamp:
- 07/19/20 19:07:40 (4 years ago)
- 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 11 11 <RootNamespace>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression</RootNamespace> 12 12 <AssemblyName>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</AssemblyName> 13 <TargetFrameworkVersion>v4. 0</TargetFrameworkVersion>13 <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> 14 14 <TargetFrameworkProfile> 15 15 </TargetFrameworkProfile> … … 41 41 <DebugType>full</DebugType> 42 42 <Optimize>false</Optimize> 43 <OutputPath>..\..\..\..\trunk\ sources\bin\</OutputPath>43 <OutputPath>..\..\..\..\trunk\bin\</OutputPath> 44 44 <DefineConstants>DEBUG;TRACE</DefineConstants> 45 45 <ErrorReport>prompt</ErrorReport> 46 46 <WarningLevel>4</WarningLevel> 47 47 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 48 <Prefer32Bit>false</Prefer32Bit> 48 49 </PropertyGroup> 49 50 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 50 51 <DebugType>pdbonly</DebugType> 51 52 <Optimize>true</Optimize> 52 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>53 <OutputPath>$(SolutionDir)\bin\</OutputPath> 53 54 <DefineConstants>TRACE</DefineConstants> 54 55 <ErrorReport>prompt</ErrorReport> 55 56 <WarningLevel>4</WarningLevel> 56 57 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 58 <Prefer32Bit>false</Prefer32Bit> 57 59 </PropertyGroup> 58 60 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> 59 61 <DebugSymbols>true</DebugSymbols> 60 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>62 <OutputPath>$(SolutionDir)\bin\</OutputPath> 61 63 <DefineConstants>DEBUG;TRACE</DefineConstants> 62 64 <DebugType>full</DebugType> … … 64 66 <ErrorReport>prompt</ErrorReport> 65 67 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 68 <Prefer32Bit>false</Prefer32Bit> 66 69 </PropertyGroup> 67 70 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 68 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>71 <OutputPath>$(SolutionDir)\bin\</OutputPath> 69 72 <DefineConstants>TRACE</DefineConstants> 70 73 <Optimize>true</Optimize> … … 73 76 <ErrorReport>prompt</ErrorReport> 74 77 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 78 <Prefer32Bit>false</Prefer32Bit> 75 79 </PropertyGroup> 76 80 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> 77 81 <DebugSymbols>true</DebugSymbols> 78 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>82 <OutputPath>$(SolutionDir)\bin\</OutputPath> 79 83 <DefineConstants>DEBUG;TRACE</DefineConstants> 80 84 <DebugType>full</DebugType> … … 82 86 <ErrorReport>prompt</ErrorReport> 83 87 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 88 <Prefer32Bit>false</Prefer32Bit> 84 89 </PropertyGroup> 85 90 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> 86 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>91 <OutputPath>$(SolutionDir)\bin\</OutputPath> 87 92 <DefineConstants>TRACE</DefineConstants> 88 93 <Optimize>true</Optimize> … … 91 96 <ErrorReport>prompt</ErrorReport> 92 97 <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> 97 104 <Private>False</Private> 98 105 </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> 118 121 </Reference> 119 122 <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 120 123 <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> 159 165 </Reference> 160 166 <Reference Include="System" /> … … 173 179 </ItemGroup> 174 180 <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" /> 175 185 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 176 186 <Compile Include="Plugin.cs" /> … … 181 191 <Compile Include="SlidingWindow\OffspringSelectionRegressionSlidingWindowAnalyzer.cs" /> 182 192 <Compile Include="SlidingWindow\SlidingWindowBestRegressionSolutionsCollection.cs" /> 193 <Compile Include="SymbolicRegressionPhenotypicDiversityAnalyzer.cs" /> 183 194 <Compile Include="SymbolicRegressionPruningAnalyzer.cs" /> 184 195 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionLogResidualEvaluator.cs" /> … … 233 244 <ItemGroup> 234 245 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj"> 235 <Project>{3 D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>246 <Project>{3d28463f-ec96-4d82-afee-38be91a0ca00}</Project> 236 247 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name> 237 <Private>False</Private>238 248 </ProjectReference> 239 249 </ItemGroup> … … 261 271 </PreBuildEvent> 262 272 </PropertyGroup> 273 <PropertyGroup> 274 <PreBuildEvent /> 275 </PropertyGroup> 263 276 </Project> -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionEvaluator.cs
r9456 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 19 19 */ 20 20 #endregion 21 21 using HEAL.Attic; 22 22 23 23 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 24 [StorableType("a8ef5d93-c9e3-46f6-8fd6-323dee5a406b")] 24 25 public interface ISymbolicRegressionEvaluator : ISymbolicDataAnalysisEvaluator<IRegressionProblemData> { 25 26 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionModel.cs
r9587 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using HEAL.Attic; 23 22 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 25 [StorableType("a411e2b5-f926-41a6-b55b-1aef862db2fb")] 23 26 public interface ISymbolicRegressionModel : IRegressionModel, ISymbolicDataAnalysisModel { 24 27 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 1 using HEAL.Attic; 2 #region License Information 2 3 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 5 * 5 6 * This file is part of HeuristicLab. … … 21 22 22 23 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 24 [StorableType("75e2b69d-b610-4694-aad9-601b9c242f89")] 23 25 public interface ISymbolicRegressionMultiObjectiveEvaluator : ISymbolicRegressionEvaluator, ISymbolicDataAnalysisMultiObjectiveEvaluator<IRegressionProblemData> { 24 26 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionSingleObjectiveEvaluator.cs
r9456 r17687 1 #region License Information 1 using HEAL.Attic; 2 #region License Information 2 3 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 5 * 5 6 * This file is part of HeuristicLab. … … 21 22 22 23 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 24 [StorableType("5dd2601a-b884-48c0-85bc-bc1f437187a3")] 23 25 public interface ISymbolicRegressionSingleObjectiveEvaluator : ISymbolicRegressionEvaluator, ISymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData> { 24 26 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/ISymbolicRegressionSolution.cs
r9456 r17687 1 #region License Information 1 using HEAL.Attic; 2 #region License Information 2 3 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 5 * 5 6 * This file is part of HeuristicLab. … … 21 22 22 23 23 using HeuristicLab.Problems.DataAnalysis.Symbolic; 24 24 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 26 [StorableType("dff1a450-e958-454f-bf8e-6b763fdcaff3")] 25 27 public interface ISymbolicRegressionSolution : IRegressionSolution, ISymbolicDataAnalysisSolution { 26 28 new ISymbolicRegressionModel Model { get; } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveEvaluator.cs
r9456 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 26 using HeuristicLab.Parameters; 27 using HEAL.Attic; 28 25 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 [StorableType("1BEEE472-95E7-45C3-BD47-883B5E3A672D")] 26 31 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 27 71 [StorableConstructor] 28 protected SymbolicRegressionMultiObjectiveEvaluator( bool deserializing) : base(deserializing) { }72 protected SymbolicRegressionMultiObjectiveEvaluator(StorableConstructorFlag _) : base(_) { } 29 73 protected SymbolicRegressionMultiObjectiveEvaluator(SymbolicRegressionMultiObjectiveEvaluator original, Cloner cloner) 30 74 : base(original, cloner) { 31 75 } 32 76 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 } 34 100 } 35 101 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r10291 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;28 using HEAL.Attic; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 31 [Item("Mean squared error & Tree size Evaluator", "Calculates the mean squared error and the tree size of a symbolic regression solution.")] 31 [Storable Class]32 [StorableType("B1EFB303-9C37-4CBB-8269-BDBC223D9086")] 32 33 public class SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 33 34 [StorableConstructor] 34 protected SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator( bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator(StorableConstructorFlag _) : base(_) { } 35 36 protected SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator(SymbolicRegressionMultiObjectiveMeanSquaredErrorSolutionSizeEvaluator original, Cloner cloner) 36 37 : base(original, cloner) { … … 47 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 49 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); 50 60 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 61 return base.InstrumentedApply(); 52 62 } 53 63 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); 58 67 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 70 71 return new double[2] { mse, solution.Length }; 71 72 } … … 76 77 ApplyLinearScalingParameter.ExecutionContext = context; 77 78 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); 79 80 80 81 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r10291 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 25 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;28 using HEAL.Attic; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 31 [Item("Pearson R² & Tree size Evaluator", "Calculates the Pearson R² and the tree size of a symbolic regression solution.")] 31 [Storable Class]32 [StorableType("58008433-3406-4374-9BF1-1C5EF944350A")] 32 33 public class SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator : SymbolicRegressionMultiObjectiveEvaluator { 33 34 [StorableConstructor] 34 protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator( bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(StorableConstructorFlag _) : base(_) { } 35 36 protected SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator original, Cloner cloner) 36 37 : base(original, cloner) { … … 47 48 IEnumerable<int> rows = GenerateRowsToEvaluate(); 48 49 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); 50 59 QualitiesParameter.ActualValue = new DoubleArray(qualities); 51 60 return base.InstrumentedApply(); 52 61 } 53 62 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); 71 67 return new double[2] { r2, solution.Length }; 72 68 } … … 77 73 ApplyLinearScalingParameter.ExecutionContext = context; 78 74 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); 80 76 81 77 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs
r9456 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;28 using HEAL.Attic; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 [Item("Symbolic Regression Problem (multi 31 [Storable Class]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)] 33 34 public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem { 34 35 private const double PunishmentFactor = 10; … … 52 53 53 54 [StorableConstructor] 54 protected SymbolicRegressionMultiObjectiveProblem( bool deserializing) : base(deserializing) { }55 protected SymbolicRegressionMultiObjectiveProblem(StorableConstructorFlag _) : base(_) { } 55 56 protected SymbolicRegressionMultiObjectiveProblem(SymbolicRegressionMultiObjectiveProblem original, Cloner cloner) 56 57 : base(original, cloner) { … … 93 94 Operators.Add(new SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer()); 94 95 Operators.Add(new SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer()); 96 Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator()); 97 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>())); 95 98 ParameterizeOperators(); 96 99 } … … 122 125 } 123 126 } 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 } 124 138 } 125 139 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs
r9456 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 24 using HeuristicLab.Analysis; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 24 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Optimization; 25 30 using HeuristicLab.Parameters; 26 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;31 using HEAL.Attic; 27 32 28 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 31 36 /// </summary> 32 37 [Item("SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic regression solution for multi objective symbolic regression problems.")] 33 [Storable Class]38 [StorableType("431B0046-3115-493F-BD15-E3DA98E3E9C7")] 34 39 public sealed class SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicRegressionSolution>, 35 40 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator { … … 37 42 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 38 43 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 39 48 #region parameter properties 40 49 public ILookupParameter<IRegressionProblemData> ProblemDataParameter { … … 47 56 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 48 57 } 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 } 49 69 #endregion 50 70 71 public bool AnalyzeTestError { 72 get { return AnalyzeTestErrorParameter.Value.Value; } 73 set { AnalyzeTestErrorParameter.Value.Value = value; } 74 } 75 51 76 [StorableConstructor] 52 private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer( bool deserializing) : base(deserializing) { }77 private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { } 53 78 private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 54 79 public SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer() 55 80 : 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))); 59 97 } 60 98 … … 64 102 65 103 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); 67 105 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 68 106 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); 69 107 } 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 70 173 } 71 174 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs
r9456 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Parameters; 26 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;26 using HEAL.Attic; 27 27 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 31 31 /// </summary> 32 32 [Item("SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer", "An operator that analyzes the validation best symbolic regression solution for multi objective symbolic regression problems.")] 33 [Storable Class]33 [StorableType("64084F75-38B9-4501-BF2D-BB342B49F732")] 34 34 public sealed class SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionMultiObjectiveEvaluator, IRegressionProblemData>, 35 35 ISymbolicDataAnalysisBoundedOperator { … … 43 43 44 44 [StorableConstructor] 45 private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer( bool deserializing) : base(deserializing) { }45 private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { } 46 46 private SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer(SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 47 47 public SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer() … … 54 54 55 55 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); 57 57 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 58 58 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 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 26 26 27 27 namespace 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$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")] 31 [PluginDependency("HeuristicLab.AutoDiff", "1.0")]32 31 [PluginDependency("HeuristicLab.Analysis", "3.3")] 33 32 [PluginDependency("HeuristicLab.Common", "3.3")] … … 39 38 [PluginDependency("HeuristicLab.Optimization", "3.3")] 40 39 [PluginDependency("HeuristicLab.Parameters", "3.3")] 41 [PluginDependency("HeuristicLab. Persistence", "3.3")]40 [PluginDependency("HeuristicLab.Attic", "1.0")] 42 41 [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")] 43 42 [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 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 [assembly: AssemblyCompany("")] 32 32 [assembly: AssemblyProduct("HeuristicLab")] 33 [assembly: AssemblyCopyright("(c) 2002-2013HEAL")]33 [assembly: AssemblyCopyright("(c) HEAL")] 34 34 [assembly: AssemblyTrademark("")] 35 35 [assembly: AssemblyCulture("")] … … 53 53 // by using the '*' as shown below: 54 54 [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 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Parameters; 30 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;30 using HEAL.Attic; 31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 35 35 /// </summary> 36 36 [Item("ConstantOptimizationAnalyzer", "An operator that performs a constant optimization on the best symbolic expression trees.")] 37 [Storable Class]37 [StorableType("9FB87E7B-A9E2-49DD-A92A-78BD9FC17916")] 38 38 public sealed class ConstantOptimizationAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer, IStatefulItem { 39 39 private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions"; … … 87 87 88 88 [StorableConstructor] 89 private ConstantOptimizationAnalyzer( bool deserializing) : base(deserializing) { }89 private ConstantOptimizationAnalyzer(StorableConstructorFlag _) : base(_) { } 90 90 private ConstantOptimizationAnalyzer(ConstantOptimizationAnalyzer original, Cloner cloner) : base(original, cloner) { } 91 91 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 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using AutoDiff;25 using HEAL.Attic; 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 using HeuristicLab.Optimization; 30 31 using HeuristicLab.Parameters; 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 34 34 [Item("Constant Optimization Evaluator", "Calculates Pearson R² of a symbolic regression solution and optimizes the constant used.")] 35 [Storable Class]35 [StorableType("24B68851-036D-4446-BD6F-3823E9028FF4")] 36 36 public class SymbolicRegressionConstantOptimizationEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 37 37 private const string ConstantOptimizationIterationsParameterName = "ConstantOptimizationIterations"; … … 40 40 private const string ConstantOptimizationRowsPercentageParameterName = "ConstantOptimizationRowsPercentage"; 41 41 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"; 42 47 43 48 public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter { … … 56 61 get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateConstantsInTreeParameterName]; } 57 62 } 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 58 77 59 78 public IntValue ConstantOptimizationIterations { … … 74 93 } 75 94 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 76 105 public override bool Maximization { 77 106 get { return true; } … … 79 108 80 109 [StorableConstructor] 81 protected SymbolicRegressionConstantOptimizationEvaluator( bool deserializing) : base(deserializing) { }110 protected SymbolicRegressionConstantOptimizationEvaluator(StorableConstructorFlag _) : base(_) { } 82 111 protected SymbolicRegressionConstantOptimizationEvaluator(SymbolicRegressionConstantOptimizationEvaluator original, Cloner cloner) 83 112 : base(original, cloner) { … … 85 114 public SymbolicRegressionConstantOptimizationEvaluator() 86 115 : 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())); 92 126 } 93 127 … … 100 134 if (!Parameters.ContainsKey(UpdateConstantsInTreeParameterName)) 101 135 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(); 104 149 public override IOperation InstrumentedApply() { 105 150 var solution = SymbolicExpressionTreeParameter.ActualValue; … … 107 152 if (RandomParameter.ActualValue.NextDouble() < ConstantOptimizationProbability.Value) { 108 153 IEnumerable<int> constantOptimizationRows = GenerateRowsToEvaluate(ConstantOptimizationRowsPercentage.Value); 154 var counter = new EvaluationsCounter(); 109 155 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); 112 157 113 158 if (ConstantOptimizationRowsPercentage.Value != RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value) { … … 115 160 quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, evaluationRows, ApplyLinearScalingParameter.ActualValue.Value); 116 161 } 162 163 if (CountEvaluations) { 164 lock (locker) { 165 FunctionEvaluationsResultParameter.ActualValue.Value += counter.FunctionEvaluations; 166 GradientEvaluationsResultParameter.ActualValue.Value += counter.GradientEvaluations; 167 } 168 } 169 117 170 } else { 118 171 var evaluationRows = GenerateRowsToEvaluate(); … … 128 181 EstimationLimitsParameter.ExecutionContext = context; 129 182 ApplyLinearScalingParameter.ExecutionContext = context; 183 FunctionEvaluationsResultParameter.ExecutionContext = context; 184 GradientEvaluationsResultParameter.ExecutionContext = context; 130 185 131 186 // Pearson R² evaluator is used on purpose instead of the const-opt evaluator, … … 137 192 EstimationLimitsParameter.ExecutionContext = null; 138 193 ApplyLinearScalingParameter.ExecutionContext = null; 194 FunctionEvaluationsResultParameter.ExecutionContext = null; 195 GradientEvaluationsResultParameter.ExecutionContext = null; 139 196 140 197 return r2; 141 198 } 142 199 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)) 178 222 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]; 187 230 c[0] = 0.0; 188 231 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 201 237 double originalQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 238 239 if (counter == null) counter = new EvaluationsCounter(); 240 var rowEvaluationsCounter = new EvaluationsCounter(); 202 241 203 242 alglib.lsfitstate state; 204 243 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]; 209 248 int row = 0; 210 249 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++; 213 258 } 214 259 row++; … … 219 264 int k = c.Length; 220 265 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); 223 269 224 270 try { 225 271 alglib.lsfitcreatefg(x, y, c, n, m, k, false, out state); 226 272 alglib.lsfitsetcond(state, 0.0, 0.0, maxIterations); 273 alglib.lsfitsetxrep(state, iterationCallback != null); 227 274 //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) { 232 278 return originalQuality; 233 } 234 catch (alglib.alglibexception) { 279 } catch (alglib.alglibexception) { 235 280 return originalQuality; 236 281 } 237 282 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 } 240 294 var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, tree, lowerEstimationLimit, upperEstimationLimit, problemData, rows, applyLinearScaling); 241 295 242 if (!updateConstantsInTree) UpdateConstants(tree, originalConstants.Skip(2).ToArray()); 296 if (!updateConstantsInTree) UpdateConstants(tree, initialConstants, updateVariableWeights); 297 243 298 if (originalQuality - quality > 0.001 || double.IsNaN(quality)) { 244 UpdateConstants(tree, originalConstants.Skip(2).ToArray());299 UpdateConstants(tree, initialConstants, updateVariableWeights); 245 300 return originalQuality; 246 301 } … … 248 303 } 249 304 250 private static void UpdateConstants(ISymbolicExpressionTree tree, double[] constants ) {305 private static void UpdateConstants(ISymbolicExpressionTree tree, double[] constants, bool updateVariableWeights) { 251 306 int i = 0; 252 307 foreach (var node in tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>()) { 253 308 ConstantTreeNode constantTreeNode = node as ConstantTreeNode; 254 VariableTreeNode variableTreeNode = node as VariableTreeNode; 309 VariableTreeNodeBase variableTreeNodeBase = node as VariableTreeNodeBase; 310 FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode; 255 311 if (constantTreeNode != null) 256 312 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++; 265 327 }; 266 328 } 267 329 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++; 273 337 }; 274 338 } 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 subtrees342 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 454 339 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); 476 341 } 477 342 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionLogResidualEvaluator.cs
r10486 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;29 using HEAL.Attic; 30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 38 38 "This effects GP convergence because functional fragments which are necessary to explain small variations are also more likely" + 39 39 " to stay in the population. This is useful even when the actual objective function is mean of squared errors.")] 40 [Storable Class]40 [StorableType("8CEA1A56-167D-481B-9167-C1DED8E06680")] 41 41 public class SymbolicRegressionLogResidualEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 42 42 [StorableConstructor] 43 protected SymbolicRegressionLogResidualEvaluator( bool deserializing) : base(deserializing) { }43 protected SymbolicRegressionLogResidualEvaluator(StorableConstructorFlag _) : base(_) { } 44 44 protected SymbolicRegressionLogResidualEvaluator(SymbolicRegressionLogResidualEvaluator original, Cloner cloner) 45 45 : base(original, cloner) { -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionMeanRelativeErrorEvaluator.cs
r10432 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;29 using HEAL.Attic; 30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 33 33 "The +1 is necessary to handle data with the value of 0.0 correctly. " + 34 34 "Notice: Linear scaling is ignored for this evaluator.")] 35 [Storable Class]35 [StorableType("8A5AAF93-5338-4E11-B3B2-3D9274329E5F")] 36 36 public class SymbolicRegressionMeanRelativeErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 37 37 public override bool Maximization { get { return false; } } 38 38 [StorableConstructor] 39 protected SymbolicRegressionMeanRelativeErrorEvaluator( bool deserializing) : base(deserializing) { }39 protected SymbolicRegressionMeanRelativeErrorEvaluator(StorableConstructorFlag _) : base(_) { } 40 40 protected SymbolicRegressionMeanRelativeErrorEvaluator(SymbolicRegressionMeanRelativeErrorEvaluator original, Cloner cloner) 41 41 : base(original, cloner) { -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r9456 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 22 using HeuristicLab.Common; 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 23 using HEAL.Attic; 30 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 31 [Storable Class]25 [StorableType("7EB90F03-4385-474F-BDE7-3B133E8FEAAB")] 32 26 public abstract class SymbolicRegressionSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<IRegressionProblemData>, ISymbolicRegressionSingleObjectiveEvaluator { 33 27 [StorableConstructor] 34 protected SymbolicRegressionSingleObjectiveEvaluator( bool deserializing) : base(deserializing) { }28 protected SymbolicRegressionSingleObjectiveEvaluator(StorableConstructorFlag _) : base(_) { } 35 29 protected SymbolicRegressionSingleObjectiveEvaluator(SymbolicRegressionSingleObjectiveEvaluator original, Cloner cloner) : base(original, cloner) { } 36 30 protected SymbolicRegressionSingleObjectiveEvaluator(): base() {} -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs
r10291 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;27 using HEAL.Attic; 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 30 [Item("Maximum absolute error Evaluator", "Calculates the maximum squared error of a symbolic regression solution.")] 31 [Storable Class]31 [StorableType("256A6405-D1EE-4D8D-963A-42C56FEE8571")] 32 32 public class SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 33 33 public override bool Maximization { get { return false; } } 34 34 [StorableConstructor] 35 protected SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator( bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator(StorableConstructorFlag _) : base(_) { } 36 36 protected SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator(SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator original, Cloner cloner) 37 37 : base(original, cloner) { -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs
r10291 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;27 using HEAL.Attic; 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 30 [Item("Mean absolute error Evaluator", "Calculates the mean absolute error of a symbolic regression solution.")] 31 [Storable Class]31 [StorableType("8ABB1AC3-0ACE-43AB-8E6B-B0FC925429DC")] 32 32 public class SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 33 33 public override bool Maximization { get { return false; } } 34 34 [StorableConstructor] 35 protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator( bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(StorableConstructorFlag _) : base(_) { } 36 36 protected SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator(SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator original, Cloner cloner) 37 37 : base(original, cloner) { -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r10291 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;27 using HEAL.Attic; 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 30 [Item("Mean squared error Evaluator", "Calculates the mean squared error of a symbolic regression solution.")] 31 [Storable Class]31 [StorableType("8D4B5243-1635-46A6-AEF9-18C9BCB725DD")] 32 32 public class SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 33 33 public override bool Maximization { get { return false; } } 34 34 [StorableConstructor] 35 protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator( bool deserializing) : base(deserializing) { }35 protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(StorableConstructorFlag _) : base(_) { } 36 36 protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator original, Cloner cloner) 37 37 : base(original, cloner) { -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r10291 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;27 using HEAL.Attic; 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 30 [Item("Pearson R² Evaluator", "Calculates the square of the pearson correlation coefficient (also known as coefficient of determination) of a symbolic regression solution.")] 31 [Storable Class]31 [StorableType("6FAEC6C2-C747-452A-A60D-29AE37898A90")] 32 32 public class SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 33 33 [StorableConstructor] 34 protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator( bool deserializing) : base(deserializing) { }34 protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(StorableConstructorFlag _) : base(_) { } 35 35 protected SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator(SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator original, Cloner cloner) 36 36 : base(original, cloner) { … … 59 59 OnlineCalculatorError errorState; 60 60 61 double r 2;61 double r; 62 62 if (applyLinearScaling) { 63 var r 2Calculator = new OnlinePearsonsRSquaredCalculator();64 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r 2Calculator, problemData.Dataset.Rows);65 errorState = r 2Calculator.ErrorState;66 r 2 = 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; 67 67 } else { 68 68 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 69 r 2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);69 r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 70 70 } 71 71 if (errorState != OnlineCalculatorError.None) return double.NaN; 72 return r 2;72 return r*r; 73 73 } 74 74 -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs
r10576 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Parameters; 30 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;30 using HEAL.Attic; 31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 33 33 [Item("SymbolicRegressionSingleObjectiveOverfittingAnalyzer", "Calculates and tracks correlation of training and validation fitness of symbolic regression models.")] 34 [Storable Class]34 [StorableType("AE1F0A23-BEB1-47AF-8ECF-DBCFD32AA5A9")] 35 35 public sealed class SymbolicRegressionSingleObjectiveOverfittingAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> { 36 36 private const string TrainingValidationCorrelationParameterName = "Training and validation fitness correlation"; … … 59 59 60 60 [StorableConstructor] 61 private SymbolicRegressionSingleObjectiveOverfittingAnalyzer( bool deserializing) : base(deserializing) { }61 private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(StorableConstructorFlag _) : base(_) { } 62 62 private SymbolicRegressionSingleObjectiveOverfittingAnalyzer(SymbolicRegressionSingleObjectiveOverfittingAnalyzer original, Cloner cloner) : base(original, cloner) { } 63 63 public SymbolicRegressionSingleObjectiveOverfittingAnalyzer() -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r10596 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Parameters; 26 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;27 using HEAL.Attic; 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 29 [Item("Symbolic Regression Problem (single 30 [Storable Class]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)] 32 33 public class SymbolicRegressionSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IRegressionProblemData, ISymbolicRegressionSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem { 33 34 private const double PunishmentFactor = 10; … … 48 49 #endregion 49 50 [StorableConstructor] 50 protected SymbolicRegressionSingleObjectiveProblem( bool deserializing) : base(deserializing) { }51 protected SymbolicRegressionSingleObjectiveProblem(StorableConstructorFlag _) : base(_) { } 51 52 protected SymbolicRegressionSingleObjectiveProblem(SymbolicRegressionSingleObjectiveProblem original, Cloner cloner) 52 53 : base(original, cloner) { … … 111 112 Operators.Add(new SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer()); 112 113 Operators.Add(new SymbolicRegressionSolutionsAnalyzer()); 113 114 Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator()); 115 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Diversity" }); 114 116 ParameterizeOperators(); 115 117 } … … 141 143 } 142 144 } 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 } 143 156 } 144 157 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs
r9456 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Parameters; 26 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;26 using HEAL.Attic; 27 27 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 31 31 /// </summary> 32 32 [Item("SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic regression solution for single objective symbolic regression problems.")] 33 [Storable Class]33 [StorableType("85786F8E-F84D-4909-9A66-620668B0C7FB")] 34 34 public sealed class SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicRegressionSolution>, 35 35 ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator { … … 50 50 51 51 [StorableConstructor] 52 private SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer( bool deserializing) : base(deserializing) { }52 private SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { } 53 53 private SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 54 54 public SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer() … … 63 63 64 64 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); 66 66 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 67 67 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 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;25 using HEAL.Attic; 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 30 30 /// </summary> 31 31 [Item("SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer", "An operator that collects the training Pareto-best symbolic regression solutions for single objective symbolic regression problems.")] 32 [Storable Class]32 [StorableType("8FDF5528-8E95-44D6-AFFD-433B4AA55559")] 33 33 public sealed class SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<IRegressionProblemData, ISymbolicRegressionSolution> { 34 34 35 35 [StorableConstructor] 36 private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer( bool deserializing) : base(deserializing) { }36 private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { } 37 37 private SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 38 38 public SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer() : base() { } … … 42 42 43 43 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); 45 45 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 46 46 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 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Parameters; 26 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;26 using HEAL.Attic; 27 27 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 31 31 /// </summary> 32 32 [Item("SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer", "An operator that analyzes the validation best symbolic regression solution for single objective symbolic regression problems.")] 33 [Storable Class]33 [StorableType("75E2AFFF-95B2-4FA4-8544-CF2025B65820")] 34 34 public sealed class SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData>, 35 35 ISymbolicDataAnalysisBoundedOperator { … … 43 43 44 44 [StorableConstructor] 45 private SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer( bool deserializing) : base(deserializing) { }45 private SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { } 46 46 private SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 47 47 public SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer() … … 55 55 56 56 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); 58 58 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 59 59 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 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;25 using HEAL.Attic; 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 30 30 /// </summary> 31 31 [Item("SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer", "An operator that collects the validation Pareto-best symbolic regression solutions for single objective symbolic regression problems.")] 32 [Storable Class]32 [StorableType("B58782FE-FAC0-4B03-9210-CAE5CF74357B")] 33 33 public sealed class SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer<ISymbolicRegressionSolution, ISymbolicRegressionSingleObjectiveEvaluator, IRegressionProblemData> { 34 34 [StorableConstructor] 35 private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer( bool deserializing) : base(deserializing) { }35 private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(StorableConstructorFlag _) : base(_) { } 36 36 private SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer(SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { } 37 37 public SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer() : base() { } … … 42 42 43 43 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); 45 45 if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue); 46 46 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 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-2014Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. … … 22 22 #endregion 23 23 24 using System;25 24 using System.Linq; 26 25 using HeuristicLab.Analysis; 27 26 using HeuristicLab.Common; 28 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Operators; 30 30 using HeuristicLab.Optimization; 31 31 using HeuristicLab.Parameters; 32 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;32 using HEAL.Attic; 33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 35 [StorableType("789E0217-6DDC-44E8-85CC-A51A976A8FB8")] 35 36 public class SymbolicRegressionSolutionsAnalyzer : SingleSuccessorOperator, IAnalyzer { 36 37 private const string ResultCollectionParameterName = "Results"; 37 38 private const string RegressionSolutionQualitiesResultName = "Regression Solution Qualities"; 39 private const string TrainingQualityParameterName = "TrainingRSquared"; 40 private const string TestQualityParameterName = "TestRSquared"; 38 41 39 42 public ILookupParameter<ResultCollection> ResultCollectionParameter { 40 43 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]; } 41 50 } 42 51 … … 46 55 47 56 [StorableConstructor] 48 protected SymbolicRegressionSolutionsAnalyzer( bool deserializing) : base(deserializing) { }57 protected SymbolicRegressionSolutionsAnalyzer(StorableConstructorFlag _) : base(_) { } 49 58 protected SymbolicRegressionSolutionsAnalyzer(SymbolicRegressionSolutionsAnalyzer original, Cloner cloner) 50 59 : base(original, cloner) { } … … 55 64 public SymbolicRegressionSolutionsAnalyzer() { 56 65 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 57 80 } 58 81 … … 66 89 67 90 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; 68 100 foreach (var result in results.Where(r => r.Value is IRegressionSolution)) { 69 101 var solution = (IRegressionSolution)result.Value; 70 102 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)); 74 106 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)); 78 110 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); 81 120 } 121 122 trainingQualityParam.ActualName = prevTrainingQualityParamName; 123 testQualityParam.ActualName = prevTestQualityParamName; 82 124 83 125 return base.Apply(); -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SlidingWindow/GenerationalRegressionSlidingWindowAnalyzer.cs
r10720 r17687 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Optimization; 25 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;25 using HEAL.Attic; 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 28 [StorableClass]29 28 [Item("Generational Regression Sliding Window Analyzer", "")] 29 [StorableType("9157AEF9-838B-48EC-9E0B-CE75F8A1FF8D")] 30 30 public class GenerationalRegressionSlidingWindowAnalyzer : GenerationalSlidingWindowAnalyzer { 31 31 [StorableConstructor] 32 protected GenerationalRegressionSlidingWindowAnalyzer( bool deserializing) : base(deserializing) { }32 protected GenerationalRegressionSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { } 33 33 [StorableHook(HookType.AfterDeserialization)] 34 34 private void AfterDeserialization() { } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SlidingWindow/OffspringSelectionRegressionSlidingWindowAnalyzer.cs
r10720 r17687 24 24 using HeuristicLab.Optimization; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HEAL.Attic; 26 27 27 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 28 [StorableClass]29 29 [Item("OffspringSelectionRegressionSlidingWindowAnalyzer", "")] 30 [StorableType("821B7755-1914-416A-AF83-55B0BF74E26A")] 30 31 public class OffspringSelectionRegressionSlidingWindowAnalyzer : OffspringSelectionSlidingWindowAnalyzer { 31 32 [StorableConstructor] 32 protected OffspringSelectionRegressionSlidingWindowAnalyzer( bool deserializing) : base(deserializing) { }33 protected OffspringSelectionRegressionSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { } 33 34 [StorableHook(HookType.AfterDeserialization)] 34 35 private void AfterDeserialization() { } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SlidingWindow/SlidingWindowBestRegressionSolutionsCollection.cs
r10681 r17687 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HEAL.Attic; 26 27 27 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 28 [StorableClass]29 29 [Item("SlidingWindowBestRegressionSolutionsCollection", "A collection of best sliding window solutions for symbolic regression.")] 30 [StorableType("8F78030E-16F3-42CD-ABE7-0526E4738676")] 30 31 public class SlidingWindowBestRegressionSolutionsCollection : SlidingWindowBestSolutionsCollection { 31 32 public new IRegressionProblemData ProblemData { … … 34 35 } 35 36 [StorableConstructor] 36 protected SlidingWindowBestRegressionSolutionsCollection( bool deserializing) : base(deserializing) { }37 protected SlidingWindowBestRegressionSolutionsCollection(StorableConstructorFlag _) : base(_) { } 37 38 [StorableHook(HookType.AfterDeserialization)] 38 39 private void AfterDeserialization() { } … … 46 47 public override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 47 48 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); 49 50 } 50 51 public override ISymbolicDataAnalysisSolution CreateSolution(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData) { -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs
r9587 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;27 using HEAL.Attic; 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 30 31 /// Represents a symbolic regression model 31 32 /// </summary> 32 [Storable Class]33 [StorableType("2739C33E-4DDB-4285-9DFB-C056D900B2F2")] 33 34 [Item(Name = "Symbolic Regression Model", Description = "Represents a symbolic regression model.")] 34 35 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 } 36 46 37 47 [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 } 40 51 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, 42 59 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 } 44 63 45 64 public override IDeepCloneable Clone(Cloner cloner) { … … 47 66 } 48 67 49 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {68 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 50 69 return Interpreter.GetSymbolicExpressionTreeValues(SymbolicExpressionTree, dataset, rows) 51 70 .LimitToRange(LowerEstimationLimit, UpperEstimationLimit); … … 62 81 Scale(problemData, problemData.TargetVariable); 63 82 } 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 64 104 } 65 105 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs
r10469 r17687 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-2014Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. … … 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 26 27 using HeuristicLab.Parameters; 27 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;28 using HEAL.Attic; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 31 [Item("SymbolicRegressionPruningAnalyzer", "An analyzer that prunes introns from the population.")] 31 [Storable Class]32 [StorableType("F1180389-1393-4102-9EEC-E4F183A017F2")] 32 33 public sealed class SymbolicRegressionPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer { 33 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";34 34 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]; } 40 37 } 41 38 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 42 46 [StorableConstructor] 43 private SymbolicRegressionPruningAnalyzer( bool deserializing) : base(deserializing) { }47 private SymbolicRegressionPruningAnalyzer(StorableConstructorFlag _) : base(_) { } 44 48 45 49 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 48 84 } 49 85 } -
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 24 using System.Collections.Generic; 25 using System.Linq; 2 26 using HeuristicLab.Common; 3 27 using HeuristicLab.Core; 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 4 29 using HeuristicLab.Parameters; 5 using H euristicLab.Persistence.Default.CompositeSerializers.Storable;30 using HEAL.Attic; 6 31 7 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 8 [Storable Class]33 [StorableType("75843B4E-C69C-423A-87BD-A64619D380BB")] 9 34 [Item("SymbolicRegressionPruningOperator", "An operator which prunes symbolic regression trees.")] 10 35 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 14 36 private const string EvaluatorParameterName = "Evaluator"; 15 37 38 #region parameter properties 16 39 public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter { 17 40 get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; } 18 41 } 42 #endregion 19 43 20 44 protected SymbolicRegressionPruningOperator(SymbolicRegressionPruningOperator original, Cloner cloner) … … 26 50 27 51 [StorableConstructor] 28 protected SymbolicRegressionPruningOperator( bool deserializing) : base(deserializing) { }52 protected SymbolicRegressionPruningOperator(StorableConstructorFlag _) : base(_) { } 29 53 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) { 33 56 Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName)); 34 57 } 35 58 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); 38 73 } 39 74 40 75 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; 50 111 } 51 112 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r9456 r17687 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System.Linq; 23 using HEAL.Attic; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 28 using HeuristicLab.Optimization; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 31 32 /// Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity 32 33 /// </summary> 33 [Storable Class]34 [StorableType("88E56AF9-AD72-47E4-A613-8875703BD927")] 34 35 [Item(Name = "SymbolicRegressionSolution", Description = "Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity.")] 35 36 public sealed class SymbolicRegressionSolution : RegressionSolution, ISymbolicRegressionSolution { … … 46 47 private const string TestNaNEvaluationsResultName = "Test NaN Evaluations"; 47 48 49 private const string ModelBoundsResultName = "Model Bounds"; 50 48 51 public new ISymbolicRegressionModel Model { 49 52 get { return (ISymbolicRegressionModel)base.Model; } … … 95 98 } 96 99 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 97 117 [StorableConstructor] 98 private SymbolicRegressionSolution( bool deserializing) : base(deserializing) { }118 private SymbolicRegressionSolution(StorableConstructorFlag _) : base(_) { } 99 119 private SymbolicRegressionSolution(SymbolicRegressionSolution original, Cloner cloner) 100 120 : base(original, cloner) { … … 102 122 public SymbolicRegressionSolution(ISymbolicRegressionModel model, IRegressionProblemData problemData) 103 123 : base(model, problemData) { 124 foreach (var node in model.SymbolicExpressionTree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTopLevelNode>()) 125 node.SetGrammar(null); 126 104 127 Add(new Result(ModelLengthResultName, "Length of the symbolic regression model.", new IntValue())); 105 128 Add(new Result(ModelDepthResultName, "Depth of the symbolic regression model.", new IntValue())); … … 114 137 estimationLimitResults.Add(new Result(TestNaNEvaluationsResultName, "", new IntValue())); 115 138 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())); 116 142 117 143 RecalculateResults(); … … 136 162 CalculateResults(); 137 163 } 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 } 138 171 } 139 172 … … 156 189 TrainingNaNEvaluations = Model.Interpreter.GetSymbolicExpressionTreeValues(Model.SymbolicExpressionTree, ProblemData.Dataset, ProblemData.TrainingIndices).Count(double.IsNaN); 157 190 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; 158 217 } 159 218 } -
branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs
r10469 r17687 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2013Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using HEAL.Attic; 28 26 29 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 [Storable Class]28 [StorableType("927C21BD-8913-406F-ADEA-DA4FED3FE4A2")] 31 29 [Item("SymbolicRegressionSolutionImpactValuesCalculator", "Calculate symbolic expression tree node impact values for regression problems.")] 32 30 public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator { 33 31 public SymbolicRegressionSolutionImpactValuesCalculator() { } 34 35 32 protected SymbolicRegressionSolutionImpactValuesCalculator(SymbolicRegressionSolutionImpactValuesCalculator original, Cloner cloner) 36 33 : base(original, cloner) { } … … 38 35 return new SymbolicRegressionSolutionImpactValuesCalculator(this, cloner); 39 36 } 37 [StorableConstructor] 38 protected SymbolicRegressionSolutionImpactValuesCalculator(StorableConstructorFlag _) : base(_) { } 40 39 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) { 44 41 var regressionModel = (ISymbolicRegressionModel)model; 45 42 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); 65 45 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; 89 50 } 90 51 }
Note: See TracChangeset
for help on using the changeset viewer.