Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs @ 4058

Last change on this file since 4058 was 3979, checked in by mkommend, 14 years ago

corrected DataAnalysis.Views.ResultsView to use an internal DoubleMatrix (ticket #1020)

File size: 3.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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using System.Collections.Generic;
29using System.Linq;
30using System.Drawing;
31
32namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
33  /// <summary>
34  /// Represents a solution for a symbolic regression problem which can be visualized in the GUI.
35  /// </summary>
36  [Item("SymbolicRegressionSolution", "Represents a solution for a symbolic regression problem which can be visualized in the GUI.")]
37  [StorableClass]
38  public sealed class SymbolicRegressionSolution : DataAnalysisSolution {
39    public SymbolicRegressionSolution() : base() { }
40    public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model, double lowerEstimationLimit, double upperEstimationLimit)
41      : base(problemData, lowerEstimationLimit, upperEstimationLimit) {
42      this.Model = model;
43    }
44
45    public override Image ItemImage {
46      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; }
47    }
48
49    public new SymbolicRegressionModel Model {
50      get { return (SymbolicRegressionModel)base.Model; }
51      set { base.Model = value; }
52    }
53
54    protected override void RecalculateEstimatedValues() {
55      estimatedValues = (from x in Model.GetEstimatedValues(ProblemData, 0, ProblemData.Dataset.Rows)
56                         let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x))
57                         select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX).ToList();
58      OnEstimatedValuesChanged();
59    }
60
61    private List<double> estimatedValues;
62    public override IEnumerable<double> EstimatedValues {
63      get {
64        if (estimatedValues == null) RecalculateEstimatedValues();
65        return estimatedValues.AsEnumerable();
66      }
67    }
68
69    public override IEnumerable<double> EstimatedTrainingValues {
70      get {
71        if (estimatedValues == null) RecalculateEstimatedValues();
72        int start = ProblemData.TrainingSamplesStart.Value;
73        int n = ProblemData.TrainingSamplesEnd.Value - start;
74        return estimatedValues.Skip(start).Take(n).ToList();
75      }
76    }
77
78    public override IEnumerable<double> EstimatedTestValues {
79      get {
80        if (estimatedValues == null) RecalculateEstimatedValues();
81        int start = ProblemData.TestSamplesStart.Value;
82        int n = ProblemData.TestSamplesEnd.Value - start;
83        return estimatedValues.Skip(start).Take(n).ToList();
84      }
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.