1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;
|
---|
30 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
|
---|
31 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
|
---|
32 | using HeuristicLab.Optimization;
|
---|
33 | using HeuristicLab.Parameters;
|
---|
34 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
35 | using HeuristicLab.PluginInfrastructure;
|
---|
36 | using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
|
---|
37 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
38 |
|
---|
39 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
40 | [Item("Symbolic Regression Problem (multi objective)", "Represents a multi objective symbolic regression problem.")]
|
---|
41 | [Creatable("Problems")]
|
---|
42 | [StorableClass]
|
---|
43 | public class MultiObjectiveSymbolicRegressionProblem : SymbolicRegressionProblemBase, IMultiObjectiveProblem {
|
---|
44 |
|
---|
45 | #region Parameter Properties
|
---|
46 | public ValueParameter<BoolArray> MaximizationParameter {
|
---|
47 | get { return (ValueParameter<BoolArray>)Parameters["Maximization"]; }
|
---|
48 | }
|
---|
49 | IParameter IMultiObjectiveProblem.MaximizationParameter {
|
---|
50 | get { return MaximizationParameter; }
|
---|
51 | }
|
---|
52 | public new ValueParameter<IMultiObjectiveSymbolicRegressionEvaluator> EvaluatorParameter {
|
---|
53 | get { return (ValueParameter<IMultiObjectiveSymbolicRegressionEvaluator>)Parameters["Evaluator"]; }
|
---|
54 | }
|
---|
55 | IParameter IProblem.EvaluatorParameter {
|
---|
56 | get { return EvaluatorParameter; }
|
---|
57 | }
|
---|
58 | #endregion
|
---|
59 |
|
---|
60 | #region Properties
|
---|
61 | public new IMultiObjectiveSymbolicRegressionEvaluator Evaluator {
|
---|
62 | get { return EvaluatorParameter.Value; }
|
---|
63 | set { EvaluatorParameter.Value = value; }
|
---|
64 | }
|
---|
65 | IMultiObjectiveEvaluator IMultiObjectiveProblem.Evaluator {
|
---|
66 | get { return EvaluatorParameter.Value; }
|
---|
67 | }
|
---|
68 | IEvaluator IProblem.Evaluator {
|
---|
69 | get { return EvaluatorParameter.Value; }
|
---|
70 | }
|
---|
71 | #endregion
|
---|
72 |
|
---|
73 |
|
---|
74 | [StorableConstructor]
|
---|
75 | protected MultiObjectiveSymbolicRegressionProblem(bool deserializing) : base(deserializing) { }
|
---|
76 | public MultiObjectiveSymbolicRegressionProblem()
|
---|
77 | : base() {
|
---|
78 | var evaluator = new MultiObjectiveSymbolicRegressionMeanSquaredErrorEvaluator();
|
---|
79 | Parameters.Add(new ValueParameter<BoolArray>("Maximization", "Set to false as the error of the regression model should be minimized.", new BoolArray(new bool[] { false, false })));
|
---|
80 | Parameters.Add(new ValueParameter<IMultiObjectiveSymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
|
---|
81 |
|
---|
82 | evaluator.QualitiesParameter.ActualName = "TrainingRSquared/Size";
|
---|
83 |
|
---|
84 | ParameterizeEvaluator();
|
---|
85 |
|
---|
86 | RegisterParameterEvents();
|
---|
87 | RegisterParameterValueEvents();
|
---|
88 | }
|
---|
89 |
|
---|
90 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
91 | MultiObjectiveSymbolicRegressionProblem clone = (MultiObjectiveSymbolicRegressionProblem)base.Clone(cloner);
|
---|
92 | clone.RegisterParameterEvents();
|
---|
93 | clone.RegisterParameterValueEvents();
|
---|
94 | return clone;
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void RegisterParameterValueEvents() {
|
---|
98 | EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
|
---|
99 | }
|
---|
100 |
|
---|
101 | private void RegisterParameterEvents() {
|
---|
102 | }
|
---|
103 |
|
---|
104 | #region event handling
|
---|
105 | protected override void OnDataAnalysisProblemChanged(EventArgs e) {
|
---|
106 | base.OnDataAnalysisProblemChanged(e);
|
---|
107 | // paritions could be changed
|
---|
108 | ParameterizeEvaluator();
|
---|
109 | }
|
---|
110 | protected override void OnSolutionParameterNameChanged(EventArgs e) {
|
---|
111 | ParameterizeEvaluator();
|
---|
112 | }
|
---|
113 |
|
---|
114 | protected override void OnEvaluatorChanged(EventArgs e) {
|
---|
115 | base.OnEvaluatorChanged(e);
|
---|
116 | ParameterizeEvaluator();
|
---|
117 | RaiseEvaluatorChanged(e);
|
---|
118 | }
|
---|
119 | #endregion
|
---|
120 |
|
---|
121 | #region event handlers
|
---|
122 | private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
123 | OnEvaluatorChanged(e);
|
---|
124 | }
|
---|
125 | #endregion
|
---|
126 |
|
---|
127 | #region Helpers
|
---|
128 | [StorableHook(HookType.AfterDeserialization)]
|
---|
129 | private void AfterDeserializationHook() {
|
---|
130 | RegisterParameterEvents();
|
---|
131 | RegisterParameterValueEvents();
|
---|
132 | }
|
---|
133 |
|
---|
134 | private void ParameterizeEvaluator() {
|
---|
135 | Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
|
---|
136 | Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
|
---|
137 | Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
|
---|
138 | Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
|
---|
139 | }
|
---|
140 | #endregion
|
---|
141 | }
|
---|
142 | }
|
---|