Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4308 was 4250, checked in by mkommend, 14 years ago

Adapted SymbolicRegression classes to new grammars (ticket #1028).

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