Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/MultiObjectiveSymbolicVectorRegressionProblem.cs @ 4056

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

Added new plugins for multi-variate regression. #1089

File size: 6.2 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.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.PluginInfrastructure;
32using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
33using HeuristicLab.Problems.DataAnalysis.Regression;
34using HeuristicLab.Problems.DataAnalysis.Symbolic;
35using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;
36using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
37using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
38using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
39using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
40using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
41using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;
42using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
43using HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Interfaces;
44using HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Evaluators;
45
46namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic {
47  [Item("Symbolic Vector Regression Problem (multi objective)", "Represents a multi objective symbolic vector regression problem.")]
48  [Creatable("Problems")]
49  [StorableClass]
50  public class MultiObjectiveSymbolicVectorRegressionProblem : SymbolicVectorRegressionProblem, IMultiObjectiveProblem {
51
52    #region Parameter Properties
53    public ValueParameter<BoolArray> MultiObjectiveMaximizationParameter {
54      get { return (ValueParameter<BoolArray>)Parameters["MultiObjectiveMaximization"]; }
55    }
56    IParameter IMultiObjectiveProblem.MaximizationParameter {
57      get { return MultiObjectiveMaximizationParameter; }
58    }
59
60    public new ValueParameter<IMultiObjectiveSymbolicVectorRegressionEvaluator> EvaluatorParameter {
61      get { return (ValueParameter<IMultiObjectiveSymbolicVectorRegressionEvaluator>)Parameters["Evaluator"]; }
62    }
63    IParameter IProblem.EvaluatorParameter {
64      get { return EvaluatorParameter; }
65    }
66    #endregion
67
68    #region Properties
69    public new IMultiObjectiveSymbolicVectorRegressionEvaluator Evaluator {
70      get { return EvaluatorParameter.Value; }
71      set { EvaluatorParameter.Value = value; }
72    }
73    IMultiObjectiveEvaluator IMultiObjectiveProblem.Evaluator {
74      get { return EvaluatorParameter.Value; }
75    }
76    IEvaluator IProblem.Evaluator {
77      get { return EvaluatorParameter.Value; }
78    }
79    #endregion
80
81    public MultiObjectiveSymbolicVectorRegressionProblem()
82      : base() {
83      var evaluator = new SymbolicVectorRegressionScaledMseEvaluator();
84      Parameters.Add(new ValueParameter<BoolArray>("MultiObjectiveMaximization", "Set to false as the error of the regression model should be minimized.", new BoolArray(MultiVariateDataAnalysisProblemData.TargetVariables.CheckedItems.Count())));
85      Parameters.Add(new ValueParameter<IMultiObjectiveSymbolicVectorRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
86
87      ParameterizeEvaluator();
88      Initialize();
89    }
90
91    [StorableConstructor]
92    private MultiObjectiveSymbolicVectorRegressionProblem(bool deserializing) : base() { }
93
94    [StorableHook(HookType.AfterDeserialization)]
95    private void AfterDeserializationHook() {
96      Initialize();
97    }
98
99    public override IDeepCloneable Clone(Cloner cloner) {
100      MultiObjectiveSymbolicVectorRegressionProblem clone = (MultiObjectiveSymbolicVectorRegressionProblem)base.Clone(cloner);
101      clone.Initialize();
102      return clone;
103    }
104
105    private void RegisterParameterValueEvents() {
106      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
107    }
108
109    #region event handling
110    protected override void OnMultiVariateDataAnalysisProblemChanged(EventArgs e) {
111      base.OnMultiVariateDataAnalysisProblemChanged(e);
112      MultiObjectiveMaximizationParameter.Value = new BoolArray(MultiVariateDataAnalysisProblemData.TargetVariables.CheckedItems.Count());
113      // paritions could be changed
114      ParameterizeEvaluator();
115    }
116
117    protected override void OnSolutionParameterNameChanged(EventArgs e) {
118      base.OnSolutionParameterNameChanged(e);
119      ParameterizeEvaluator();
120    }
121
122    protected virtual void OnEvaluatorChanged(EventArgs e) {
123      ParameterizeEvaluator();
124      RaiseEvaluatorChanged(e);
125    }
126    #endregion
127
128    #region event handlers
129    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
130      OnEvaluatorChanged(e);
131    }
132    #endregion
133
134    #region Helpers
135    private void Initialize() {
136      RegisterParameterValueEvents();
137    }
138
139
140    private void ParameterizeEvaluator() {
141      Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
142      Evaluator.MultiVariateDataAnalysisProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
143      Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
144      Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
145    }
146    #endregion
147  }
148}
Note: See TracBrowser for help on using the repository browser.