Changeset 4128
- Timestamp:
- 08/02/10 15:21:07 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 8 added
- 1 deleted
- 3 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionNormalizedMeanSquaredErrorEvaluator.cs
r4112 r4128 33 33 [Item("SymbolicRegressionNormalizedMeanSquaredErrorEvaluator", "Calculates the normalized mean squared error of a symbolic regression solution.")] 34 34 [StorableClass] 35 public class SymbolicRegressionNormalizedMeanSquaredErrorEvaluator : S ymbolicRegressionEvaluator {35 public class SymbolicRegressionNormalizedMeanSquaredErrorEvaluator : SingleObjectiveSymbolicRegressionEvaluator { 36 36 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 37 37 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj
r4127 r4128 129 129 <Compile Include="Symbolic\Analyzers\SymbolicRegressionVariableFrequencyAnalyzer.cs" /> 130 130 <Compile Include="Symbolic\Analyzers\ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs" /> 131 <Compile Include="Symbolic\SymbolicRegressionPearsonsRSquaredEvaluator.cs" /> 132 <Compile Include="Symbolic\SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs" /> 131 <Compile Include="Symbolic\Evaluators\MultiObjectiveSymbolicRegressionEvaluator.cs" /> 132 <Compile Include="Symbolic\Evaluators\MultiObjectiveSymbolicRegressionPearsonsRSquaredEvaluator.cs" /> 133 <Compile Include="Symbolic\Evaluators\SingleObjectiveSymbolicRegressionEvaluator.cs" /> 134 <Compile Include="Symbolic\Evaluators\SymbolicRegressionMeanSquaredErrorEvaluator.cs" /> 135 <Compile Include="Symbolic\Evaluators\SymbolicRegressionPearsonsRSquaredEvaluator.cs" /> 136 <Compile Include="Symbolic\Evaluators\SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs" /> 137 <Compile Include="Symbolic\Evaluators\SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs" /> 138 <Compile Include="Symbolic\Interfaces\IMultiObjectiveSymbolicRegressionEvaluator.cs" /> 139 <Compile Include="Symbolic\Interfaces\ISymbolicRegressionEvaluator.cs" /> 140 <Compile Include="Symbolic\SymbolicRegressionProblem.cs" /> 141 <Compile Include="Symbolic\MultiObjectiveSymbolicRegressionProblem.cs" /> 133 142 <Compile Include="Symbolic\SimpleSymbolicRegressionEvaluator.cs" /> 134 <Compile Include="Symbolic\SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs" />135 143 <Compile Include="Symbolic\SymbolicRegressionSolution.cs" /> 136 144 <Compile Include="Symbolic\SymbolicRegressionModel.cs" /> 137 <Compile Include="Symbolic\ISymbolicRegressionEvaluator.cs"> 138 <SubType>Code</SubType> 139 </Compile> 140 <Compile Include="Symbolic\SymbolicRegressionEvaluator.cs"> 141 <SubType>Code</SubType> 142 </Compile> 143 <Compile Include="Symbolic\SymbolicRegressionMeanSquaredErrorEvaluator.cs"> 144 <SubType>Code</SubType> 145 </Compile> 146 <Compile Include="Symbolic\SymbolicRegressionProblem.cs"> 145 <Compile Include="Symbolic\SymbolicRegressionProblemBase.cs"> 147 146 <SubType>Code</SubType> 148 147 </Compile> … … 251 250 </BootstrapperPackage> 252 251 </ItemGroup> 252 <ItemGroup /> 253 253 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 254 254 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionMeanSquaredErrorEvaluator.cs
r4127 r4128 33 33 [Item("SymbolicRegressionMeanSquaredErrorEvaluator", "Calculates the mean squared error of a symbolic regression solution.")] 34 34 [StorableClass] 35 public class SymbolicRegressionMeanSquaredErrorEvaluator : S ymbolicRegressionEvaluator {35 public class SymbolicRegressionMeanSquaredErrorEvaluator : SingleObjectiveSymbolicRegressionEvaluator { 36 36 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 37 37 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionPearsonsRSquaredEvaluator.cs
r4127 r4128 33 33 [Item("SymbolicRegressionPearsonsRSquaredEvaluator", "Calculates the pearson r² correlation coefficient of a symbolic regression solution.")] 34 34 [StorableClass] 35 public class SymbolicRegressionPearsonsRSquaredEvaluator : S ymbolicRegressionEvaluator {35 public class SymbolicRegressionPearsonsRSquaredEvaluator : SingleObjectiveSymbolicRegressionEvaluator { 36 36 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 37 37 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs
r4127 r4128 37 37 private const string QualityVarianceParameterName = "QualityVariance"; 38 38 private const string QualitySamplesParameterName = "QualitySamples"; 39 private const string DecompositionBiasParameterName = "QualityDecompositionBias"; 40 private const string DecompositionVarianceParameterName = "QualityDecompositionVariance"; 41 private const string DecompositionCovarianceParameterName = "QualityDecompositionCovariance"; 42 private const string ApplyScalingParameterName = "ApplyScaling"; 39 43 40 44 #region parameter properties 45 public IValueLookupParameter<BoolValue> ApplyScalingParameter { 46 get { return (IValueLookupParameter<BoolValue>)Parameters[ApplyScalingParameterName]; } 47 } 41 48 public ILookupParameter<DoubleValue> AlphaParameter { 42 49 get { return (ILookupParameter<DoubleValue>)Parameters["Alpha"]; } … … 51 58 get { return (ILookupParameter<IntValue>)Parameters[QualitySamplesParameterName]; } 52 59 } 60 public ILookupParameter<DoubleValue> DecompositionBiasParameter { 61 get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionBiasParameterName]; } 62 } 63 public ILookupParameter<DoubleValue> DecompositionVarianceParameter { 64 get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionVarianceParameterName]; } 65 } 66 public ILookupParameter<DoubleValue> DecompositionCovarianceParameter { 67 get { return (ILookupParameter<DoubleValue>)Parameters[DecompositionCovarianceParameterName]; } 68 } 53 69 54 70 #endregion 55 71 #region properties 72 public BoolValue ApplyScaling { 73 get { return ApplyScalingParameter.ActualValue; } 74 } 56 75 public DoubleValue Alpha { 57 76 get { return AlphaParameter.ActualValue; } … … 73 92 public SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator() 74 93 : base() { 94 Parameters.Add(new ValueLookupParameter<BoolValue>(ApplyScalingParameterName, "Determines if the estimated values should be scaled.", new BoolValue(true))); 75 95 Parameters.Add(new LookupParameter<DoubleValue>("Alpha", "Alpha parameter for linear scaling of the estimated values.")); 76 96 Parameters.Add(new LookupParameter<DoubleValue>("Beta", "Beta parameter for linear scaling of the estimated values.")); 77 97 Parameters.Add(new LookupParameter<DoubleValue>(QualityVarianceParameterName, "A parameter which stores the variance of the squared errors.")); 78 98 Parameters.Add(new LookupParameter<IntValue>(QualitySamplesParameterName, " The number of evaluated samples.")); 99 Parameters.Add(new LookupParameter<DoubleValue>(DecompositionBiasParameterName, "A parameter which stores the relativ bias of the MSE.")); 100 Parameters.Add(new LookupParameter<DoubleValue>(DecompositionVarianceParameterName, "A parameter which stores the relativ bias of the MSE.")); 101 Parameters.Add(new LookupParameter<DoubleValue>(DecompositionCovarianceParameterName, "A parameter which stores the relativ bias of the MSE.")); 79 102 } 80 103 … … 83 106 double meanSE, varianceSE; 84 107 int count; 85 double mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count); 86 Alpha = new DoubleValue(alpha); 87 Beta = new DoubleValue(beta); 108 double bias, variance, covariance; 109 double mse; 110 if (ApplyScaling.Value) { 111 mse = Calculate(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, out beta, out alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); 112 Alpha = new DoubleValue(alpha); 113 Beta = new DoubleValue(beta); 114 } else { 115 mse = CalculateWithScaling(interpreter, solution, LowerEstimationLimit.Value, UpperEstimationLimit.Value, dataset, targetVariable.Value, rows, 1, 0, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); 116 } 88 117 QualityVariance = new DoubleValue(varianceSE); 89 118 QualitySamples = new IntValue(count); 119 DecompositionBiasParameter.ActualValue = new DoubleValue(bias / meanSE); 120 DecompositionVarianceParameter.ActualValue = new DoubleValue(variance / meanSE); 121 DecompositionCovarianceParameter.ActualValue = new DoubleValue(covariance / meanSE); 90 122 return mse; 91 123 } 92 124 93 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count ) {125 public static double Calculate(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, out double beta, out double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) { 94 126 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 95 127 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 96 128 CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha); 97 129 98 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count );99 } 100 101 public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count ) {130 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); 131 } 132 133 public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, IEnumerable<int> rows, double beta, double alpha, out double meanSE, out double varianceSE, out int count, out double bias, out double variance, out double covariance) { 102 134 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 103 135 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); … … 105 137 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 106 138 OnlineMeanAndVarianceCalculator seEvaluator = new OnlineMeanAndVarianceCalculator(); 139 OnlineMeanAndVarianceCalculator originalMeanEvaluator = new OnlineMeanAndVarianceCalculator(); 140 OnlineMeanAndVarianceCalculator estimatedMeanEvaluator = new OnlineMeanAndVarianceCalculator(); 141 OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator(); 107 142 108 143 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { … … 116 151 error *= error; 117 152 seEvaluator.Add(error); 153 originalMeanEvaluator.Add(original); 154 estimatedMeanEvaluator.Add(estimated); 155 r2Evaluator.Add(original, estimated); 118 156 } 119 157 … … 124 162 varianceSE = seEvaluator.Variance; 125 163 count = seEvaluator.Count; 164 bias = (originalMeanEvaluator.Mean - estimatedMeanEvaluator.Mean); 165 bias *= bias; 166 167 double sO = Math.Sqrt(originalMeanEvaluator.Variance); 168 double sE = Math.Sqrt(estimatedMeanEvaluator.Variance); 169 variance = sO - sE; 170 variance *= variance; 171 double r = Math.Sqrt(r2Evaluator.RSquared); 172 covariance = 2 * sO * sE * (1 - r); 126 173 return seEvaluator.Mean; 127 174 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r4127 r4128 38 38 39 39 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic { 40 [Item("Symbolic Regression Problem ", "Represents asymbolic regression problem.")]40 [Item("Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem.")] 41 41 [Creatable("Problems")] 42 42 [StorableClass] 43 public class SymbolicRegressionProblem : DataAnalysisProblem, ISingleObjectiveProblem {43 public class SymbolicRegressionProblem : SymbolicRegressionProblemBase, ISingleObjectiveProblem { 44 44 45 45 #region Parameter Properties … … 50 50 get { return MaximizationParameter; } 51 51 } 52 public new ValueParameter<SymbolicExpressionTreeCreator> SolutionCreatorParameter {53 get { return (ValueParameter<SymbolicExpressionTreeCreator>)Parameters["SolutionCreator"]; }54 }55 IParameter IProblem.SolutionCreatorParameter {56 get { return SolutionCreatorParameter; }57 }58 public ValueParameter<DoubleValue> LowerEstimationLimitParameter {59 get { return (ValueParameter<DoubleValue>)Parameters["LowerEstimationLimit"]; }60 }61 public ValueParameter<DoubleValue> UpperEstimationLimitParameter {62 get { return (ValueParameter<DoubleValue>)Parameters["UpperEstimationLimit"]; }63 }64 public ValueParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {65 get { return (ValueParameter<ISymbolicExpressionTreeInterpreter>)Parameters["SymbolicExpressionTreeInterpreter"]; }66 }67 52 public new ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter { 68 53 get { return (ValueParameter<ISymbolicRegressionEvaluator>)Parameters["Evaluator"]; } … … 70 55 IParameter IProblem.EvaluatorParameter { 71 56 get { return EvaluatorParameter; } 72 }73 public ValueParameter<ISymbolicExpressionGrammar> FunctionTreeGrammarParameter {74 get { return (ValueParameter<ISymbolicExpressionGrammar>)Parameters["FunctionTreeGrammar"]; }75 }76 public ValueParameter<IntValue> MaxExpressionLengthParameter {77 get { return (ValueParameter<IntValue>)Parameters["MaxExpressionLength"]; }78 }79 public ValueParameter<IntValue> MaxExpressionDepthParameter {80 get { return (ValueParameter<IntValue>)Parameters["MaxExpressionDepth"]; }81 }82 public ValueParameter<IntValue> MaxFunctionDefiningBranchesParameter {83 get { return (ValueParameter<IntValue>)Parameters["MaxFunctionDefiningBranches"]; }84 }85 public ValueParameter<IntValue> MaxFunctionArgumentsParameter {86 get { return (ValueParameter<IntValue>)Parameters["MaxFunctionArguments"]; }87 57 } 88 58 public OptionalValueParameter<DoubleValue> BestKnownQualityParameter { … … 95 65 96 66 #region Properties 97 public IntValue MaxExpressionLength {98 get { return MaxExpressionLengthParameter.Value; }99 set { MaxExpressionLengthParameter.Value = value; }100 }101 public IntValue MaxExpressionDepth {102 get { return MaxExpressionDepthParameter.Value; }103 set { MaxExpressionDepthParameter.Value = value; }104 }105 public IntValue MaxFunctionDefiningBranches {106 get { return MaxFunctionDefiningBranchesParameter.Value; }107 set { MaxFunctionDefiningBranchesParameter.Value = value; }108 }109 public IntValue MaxFunctionArguments {110 get { return MaxFunctionArgumentsParameter.Value; }111 set { MaxFunctionArgumentsParameter.Value = value; }112 }113 public new SymbolicExpressionTreeCreator SolutionCreator {114 get { return SolutionCreatorParameter.Value; }115 set { SolutionCreatorParameter.Value = value; }116 }117 ISolutionCreator IProblem.SolutionCreator {118 get { return SolutionCreatorParameter.Value; }119 }120 public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {121 get { return SymbolicExpressionTreeInterpreterParameter.Value; }122 set { SymbolicExpressionTreeInterpreterParameter.Value = value; }123 }124 public DoubleValue LowerEstimationLimit {125 get { return LowerEstimationLimitParameter.Value; }126 set { LowerEstimationLimitParameter.Value = value; }127 }128 public DoubleValue UpperEstimationLimit {129 get { return UpperEstimationLimitParameter.Value; }130 set { UpperEstimationLimitParameter.Value = value; }131 }132 133 67 public new ISymbolicRegressionEvaluator Evaluator { 134 68 get { return EvaluatorParameter.Value; } … … 141 75 get { return EvaluatorParameter.Value; } 142 76 } 143 public ISymbolicExpressionGrammar FunctionTreeGrammar {144 get { return (ISymbolicExpressionGrammar)FunctionTreeGrammarParameter.Value; }145 }146 77 public DoubleValue BestKnownQuality { 147 78 get { return BestKnownQualityParameter.Value; } 148 79 } 149 public override IEnumerable<IOperator> Operators {150 get { return operators; }151 }152 public IEnumerable<ISymbolicRegressionAnalyzer> Analyzers {153 get { return operators.OfType<ISymbolicRegressionAnalyzer>(); }154 }155 public DoubleValue PunishmentFactor {156 get { return new DoubleValue(10.0); }157 }158 public IntValue TrainingSamplesStart {159 get { return new IntValue(DataAnalysisProblemData.TrainingSamplesStart.Value); }160 }161 public IntValue TrainingSamplesEnd {162 get {163 return new IntValue((DataAnalysisProblemData.TrainingSamplesStart.Value +164 DataAnalysisProblemData.TrainingSamplesEnd.Value) / 2);165 }166 }167 public IntValue ValidationSamplesStart {168 get { return TrainingSamplesEnd; }169 }170 public IntValue ValidationSamplesEnd {171 get { return new IntValue(DataAnalysisProblemData.TrainingSamplesEnd.Value); }172 }173 public IntValue TestSamplesStart {174 get { return DataAnalysisProblemData.TestSamplesStart; }175 }176 public IntValue TestSamplesEnd {177 get { return DataAnalysisProblemData.TestSamplesEnd; }178 }179 80 #endregion 180 181 [Storable]182 private List<IOperator> operators;183 81 184 82 [StorableConstructor] … … 186 84 public SymbolicRegressionProblem() 187 85 : base() { 188 SymbolicExpressionTreeCreator creator = new ProbabilisticTreeCreator();189 86 var evaluator = new SymbolicRegressionScaledMeanSquaredErrorEvaluator(); 190 var grammar = new FullFunctionalExpressionGrammar();191 var globalGrammar = new GlobalSymbolicExpressionGrammar(grammar);192 var interpreter = new SimpleArithmeticExpressionInterpreter();193 87 Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(false).AsReadOnly())); 194 Parameters.Add(new ValueParameter<SymbolicExpressionTreeCreator>("SolutionCreator", "The operator which should be used to create new symbolic regression solutions.", creator));195 Parameters.Add(new ValueParameter<ISymbolicExpressionTreeInterpreter>("SymbolicExpressionTreeInterpreter", "The interpreter that should be used to evaluate the symbolic expression tree.", interpreter));196 88 Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator)); 197 Parameters.Add(new ValueParameter<DoubleValue>("LowerEstimationLimit", "The lower limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.NegativeInfinity)));198 Parameters.Add(new ValueParameter<DoubleValue>("UpperEstimationLimit", "The upper limit for the estimated value that can be returned by the symbolic regression model.", new DoubleValue(double.PositiveInfinity)));199 89 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem.")); 200 Parameters.Add(new ValueParameter<ISymbolicExpressionGrammar>("FunctionTreeGrammar", "The grammar that should be used for symbolic regression models.", globalGrammar));201 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionLength", "Maximal length of the symbolic expression.", new IntValue(100)));202 Parameters.Add(new ValueParameter<IntValue>("MaxExpressionDepth", "Maximal depth of the symbolic expression.", new IntValue(10)));203 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionDefiningBranches", "Maximal number of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));204 Parameters.Add(new ValueParameter<IntValue>("MaxFunctionArguments", "Maximal number of arguments of automatically defined functions.", (IntValue)new IntValue(0).AsReadOnly()));205 90 206 creator.SymbolicExpressionTreeParameter.ActualName = "SymbolicRegressionModel";207 91 evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError"; 208 92 209 ParameterizeSolutionCreator();93 InitializeOperators(); 210 94 ParameterizeEvaluator(); 211 95 212 UpdateGrammar();213 UpdateEstimationLimits();214 InitializeOperators();215 96 RegisterParameterEvents(); 216 97 RegisterParameterValueEvents(); … … 219 100 public override IDeepCloneable Clone(Cloner cloner) { 220 101 SymbolicRegressionProblem clone = (SymbolicRegressionProblem)base.Clone(cloner); 221 clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();222 102 clone.RegisterParameterEvents(); 223 103 clone.RegisterParameterValueEvents(); … … 226 106 227 107 private void RegisterParameterValueEvents() { 228 MaxFunctionArgumentsParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);229 MaxFunctionDefiningBranchesParameter.ValueChanged += new EventHandler(ArchitectureParameter_ValueChanged);230 SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);231 108 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 232 109 } 233 110 234 private void RegisterParameterEvents() { 235 MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged); 236 MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged); 237 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged); 238 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 239 } 111 private void RegisterParameterEvents() { } 240 112 241 113 #region event handling … … 246 118 ParameterizeEvaluator(); 247 119 ParameterizeAnalyzers(); 248 // input variables could have been changed249 UpdateGrammar();250 // estimation limits have to be recalculated251 UpdateEstimationLimits();252 }253 protected virtual void OnArchitectureParameterChanged(EventArgs e) {254 UpdateGrammar();255 }256 protected virtual void OnGrammarChanged(EventArgs e) { }257 protected virtual void OnOperatorsChanged(EventArgs e) { RaiseOperatorsChanged(e); }258 protected virtual void OnSolutionCreatorChanged(EventArgs e) {259 SolutionCreator.SymbolicExpressionTreeParameter.ActualNameChanged += new EventHandler(SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged);260 ParameterizeSolutionCreator();261 OnSolutionParameterNameChanged(e);262 RaiseSolutionCreatorChanged(e);263 120 } 264 121 265 protected virtual void OnSolutionParameterNameChanged(EventArgs e) { 122 protected override void OnSolutionParameterNameChanged(EventArgs e) { 123 base.OnSolutionParameterNameChanged(e); 266 124 ParameterizeEvaluator(); 267 125 ParameterizeAnalyzers(); 268 ParameterizeOperators();269 126 } 270 127 271 protected virtualvoid OnEvaluatorChanged(EventArgs e) {272 Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);128 protected override void OnEvaluatorChanged(EventArgs e) { 129 base.OnEvaluatorChanged(e); 273 130 ParameterizeEvaluator(); 274 131 ParameterizeAnalyzers(); 275 132 RaiseEvaluatorChanged(e); 276 133 } 277 protected virtual void OnQualityParameterNameChanged(EventArgs e) {278 ParameterizeAnalyzers();279 }280 134 #endregion 281 135 282 136 #region event handlers 283 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {284 OnSolutionCreatorChanged(e);285 }286 private void SolutionCreator_SymbolicExpressionTreeParameter_ActualNameChanged(object sender, EventArgs e) {287 OnSolutionParameterNameChanged(e);288 }289 137 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 290 138 OnEvaluatorChanged(e); 291 }292 private void ArchitectureParameter_ValueChanged(object sender, EventArgs e) {293 MaxFunctionArgumentsParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);294 MaxFunctionDefiningBranchesParameter.Value.ValueChanged += new EventHandler(ArchitectureParameterValue_ValueChanged);295 OnArchitectureParameterChanged(e);296 }297 private void ArchitectureParameterValue_ValueChanged(object sender, EventArgs e) {298 OnArchitectureParameterChanged(e);299 }300 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {301 OnQualityParameterNameChanged(e);302 139 } 303 140 #endregion … … 308 145 // BackwardsCompatibility3.3 309 146 #region Backwards compatible code (remove with 3.4) 310 if ( operators == null) InitializeOperators();147 if (Operators == null || Operators.Count() == 0) InitializeOperators(); 311 148 #endregion 312 149 RegisterParameterEvents(); … … 314 151 } 315 152 316 private void UpdateGrammar() {317 foreach (var varSymbol in FunctionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable>()) {318 varSymbol.VariableNames = DataAnalysisProblemData.InputVariables.CheckedItems.Select(x => x.Value.Value);319 }320 var globalGrammar = FunctionTreeGrammar as GlobalSymbolicExpressionGrammar;321 if (globalGrammar != null) {322 globalGrammar.MaxFunctionArguments = MaxFunctionArguments.Value;323 globalGrammar.MaxFunctionDefinitions = MaxFunctionDefiningBranches.Value;324 }325 }326 327 private void UpdateEstimationLimits() {328 if (TrainingSamplesStart.Value < TrainingSamplesEnd.Value &&329 DataAnalysisProblemData.Dataset.VariableNames.Contains(DataAnalysisProblemData.TargetVariable.Value)) {330 var targetValues = DataAnalysisProblemData.Dataset.GetVariableValues(DataAnalysisProblemData.TargetVariable.Value, TrainingSamplesStart.Value, TrainingSamplesEnd.Value);331 var mean = targetValues.Average();332 var range = targetValues.Max() - targetValues.Min();333 UpperEstimationLimit = new DoubleValue(mean + PunishmentFactor.Value * range);334 LowerEstimationLimit = new DoubleValue(mean - PunishmentFactor.Value * range);335 }336 }337 338 153 private void InitializeOperators() { 339 operators = new List<IOperator>(); 340 operators.AddRange(ApplicationManager.Manager.GetInstances<ISymbolicExpressionTreeOperator>().OfType<IOperator>()); 341 operators.Add(new SymbolicRegressionTournamentPruning()); 342 operators.Add(new SymbolicRegressionVariableFrequencyAnalyzer()); 343 operators.Add(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer()); 344 operators.Add(new MinAverageMaxSymbolicExpressionTreeSizeAnalyzer()); 345 operators.Add(new SymbolicRegressionModelQualityAnalyzer()); 346 ParameterizeOperators(); 154 AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer()); 347 155 ParameterizeAnalyzers(); 348 }349 350 private void ParameterizeSolutionCreator() {351 SolutionCreator.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;352 SolutionCreator.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;353 SolutionCreator.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;354 SolutionCreator.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;355 SolutionCreator.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;356 156 } 357 157 … … 389 189 bestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 390 190 } 391 var symbolicRegressionModelQualityAnalyzer = analyzer as SymbolicRegressionModelQualityAnalyzer;392 if (symbolicRegressionModelQualityAnalyzer != null) {393 symbolicRegressionModelQualityAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;394 symbolicRegressionModelQualityAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;395 symbolicRegressionModelQualityAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;396 symbolicRegressionModelQualityAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;397 symbolicRegressionModelQualityAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;398 }399 var varFreqAnalyzer = analyzer as SymbolicRegressionVariableFrequencyAnalyzer;400 if (varFreqAnalyzer != null) {401 varFreqAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;402 }403 var pruningOperator = analyzer as SymbolicRegressionTournamentPruning;404 if (pruningOperator != null) {405 pruningOperator.SamplesStartParameter.Value = TrainingSamplesStart;406 pruningOperator.SamplesEndParameter.Value = TrainingSamplesEnd;407 pruningOperator.DataAnalysisProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;408 pruningOperator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;409 pruningOperator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;410 pruningOperator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;411 pruningOperator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;412 }413 }414 foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {415 analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;416 }417 }418 419 private void ParameterizeOperators() {420 foreach (ISymbolicExpressionTreeOperator op in Operators.OfType<ISymbolicExpressionTreeOperator>()) {421 op.MaxTreeHeightParameter.ActualName = MaxExpressionDepthParameter.Name;422 op.MaxTreeSizeParameter.ActualName = MaxExpressionLengthParameter.Name;423 op.SymbolicExpressionGrammarParameter.ActualName = FunctionTreeGrammarParameter.Name;424 }425 foreach (ISymbolicExpressionTreeCrossover op in Operators.OfType<ISymbolicExpressionTreeCrossover>()) {426 op.ParentsParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;427 op.ChildParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;428 }429 foreach (ISymbolicExpressionTreeManipulator op in Operators.OfType<ISymbolicExpressionTreeManipulator>()) {430 op.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;431 }432 foreach (ISymbolicExpressionTreeArchitectureManipulator op in Operators.OfType<ISymbolicExpressionTreeArchitectureManipulator>()) {433 op.MaxFunctionArgumentsParameter.ActualName = MaxFunctionArgumentsParameter.Name;434 op.MaxFunctionDefinitionsParameter.ActualName = MaxFunctionDefiningBranchesParameter.Name;435 191 } 436 192 }
Note: See TracChangeset
for help on using the changeset viewer.