Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/MultiObjectiveSymbolicRegressionProblem.cs @ 4857

Last change on this file since 4857 was 4166, checked in by gkronber, 14 years ago

Added MSE evaluator for multi-objective symb reg problems. #1118

File size: 5.5 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;
30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
31using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
32using HeuristicLab.Optimization;
33using HeuristicLab.Parameters;
34using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
35using HeuristicLab.PluginInfrastructure;
36using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
37using HeuristicLab.Problems.DataAnalysis.Symbolic;
38
39namespace 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 virtual void OnEvaluatorChanged(EventArgs e) {
115      ParameterizeEvaluator();
116      RaiseEvaluatorChanged(e);
117    }
118    #endregion
119
120    #region event handlers
121    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
122      OnEvaluatorChanged(e);
123    }
124    #endregion
125
126    #region Helpers
127    [StorableHook(HookType.AfterDeserialization)]
128    private void AfterDeserializationHook() {
129      RegisterParameterEvents();
130      RegisterParameterValueEvents();
131    }
132
133    private void ParameterizeEvaluator() {
134      Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
135      Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
136      Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
137      Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
138    }
139    #endregion
140  }
141}
Note: See TracBrowser for help on using the repository browser.