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 HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
28 | using System.Collections.Generic;
|
---|
29 | using System.Linq;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
32 | /// <summary>
|
---|
33 | /// Represents a solution for a symbolic regression problem which can be visualized in the GUI.
|
---|
34 | /// </summary>
|
---|
35 | [Item("SymbolicRegressionSolution", "Represents a solution for a symbolic regression problem which can be visualized in the GUI.")]
|
---|
36 | [StorableClass]
|
---|
37 | public sealed class SymbolicRegressionSolution : DataAnalysisSolution {
|
---|
38 | private SymbolicRegressionModel model;
|
---|
39 | public SymbolicRegressionModel Model {
|
---|
40 | get { return model; }
|
---|
41 | set {
|
---|
42 | if (model != value) {
|
---|
43 | if (value == null) throw new ArgumentNullException();
|
---|
44 | model = value;
|
---|
45 | OnModelChanged(EventArgs.Empty);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public SymbolicRegressionSolution() : base() { }
|
---|
51 | public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model)
|
---|
52 | : base(problemData) {
|
---|
53 | this.model = model;
|
---|
54 | RecalculateEstimatedValues();
|
---|
55 | }
|
---|
56 |
|
---|
57 | public event EventHandler ModelChanged;
|
---|
58 | private void OnModelChanged(EventArgs e) {
|
---|
59 | RecalculateEstimatedValues();
|
---|
60 | var listeners = ModelChanged;
|
---|
61 | if (listeners != null)
|
---|
62 | listeners(this, e);
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void OnProblemDataChanged(EventArgs e) {
|
---|
66 | RecalculateEstimatedValues();
|
---|
67 | }
|
---|
68 |
|
---|
69 | private void RecalculateEstimatedValues() {
|
---|
70 | estimatedValues = model.GetEstimatedValues(ProblemData.Dataset, 0, ProblemData.Dataset.Rows).ToList();
|
---|
71 | OnEstimatedValuesChanged(EventArgs.Empty);
|
---|
72 | }
|
---|
73 |
|
---|
74 | private List<double> estimatedValues;
|
---|
75 | public override IEnumerable<double> EstimatedValues {
|
---|
76 | get {
|
---|
77 | return estimatedValues.AsEnumerable();
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public override IEnumerable<double> EstimatedTrainingValues {
|
---|
82 | get {
|
---|
83 | int start = ProblemData.TrainingSamplesStart.Value;
|
---|
84 | int n = ProblemData.TrainingSamplesEnd.Value - start;
|
---|
85 | return estimatedValues.Skip(start).Take(n).ToList();
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | public override IEnumerable<double> EstimatedTestValues {
|
---|
90 | get {
|
---|
91 | int start = ProblemData.TestSamplesStart.Value;
|
---|
92 | int n = ProblemData.TestSamplesEnd.Value - start;
|
---|
93 | return estimatedValues.Skip(start).Take(n).ToList();
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|