Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs @ 7370

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

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

File size: 3.9 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;
[5275]26using HeuristicLab.Common;
[3442]27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[4341]29using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
[3442]30
31namespace 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]
[5275]37  public class SymbolicRegressionSolution : DataAnalysisSolution {
[3884]38    public override Image ItemImage {
39      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; }
[3462]40    }
41
[3884]42    public new SymbolicRegressionModel Model {
43      get { return (SymbolicRegressionModel)base.Model; }
44      set { base.Model = value; }
[3462]45    }
46
[5275]47    protected List<double> estimatedValues;
48    public override IEnumerable<double> EstimatedValues {
49      get {
50        if (estimatedValues == null) RecalculateEstimatedValues();
51        return estimatedValues;
52      }
53    }
54
55    public override IEnumerable<double> EstimatedTrainingValues {
56      get { return GetEstimatedValues(ProblemData.TrainingIndizes); }
57    }
58
59    public override IEnumerable<double> EstimatedTestValues {
60      get { return GetEstimatedValues(ProblemData.TestIndizes); }
61    }
62
63    [StorableConstructor]
64    protected SymbolicRegressionSolution(bool deserializing) : base(deserializing) { }
65    protected SymbolicRegressionSolution(SymbolicRegressionSolution original, Cloner cloner)
66      : base(original, cloner) {
67    }
68    public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model, double lowerEstimationLimit, double upperEstimationLimit)
69      : base(problemData, lowerEstimationLimit, upperEstimationLimit) {
70      this.Model = model;
71    }
72
73    public override IDeepCloneable Clone(Cloner cloner) {
74      return new SymbolicRegressionSolution(this, cloner);
75    }
76
[3884]77    protected override void RecalculateEstimatedValues() {
[4341]78      int minLag = 0;
79      var laggedTreeNodes = Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>();
80      if (laggedTreeNodes.Any())
81        minLag = laggedTreeNodes.Min(node => node.Lag);
82      IEnumerable<double> calculatedValues =
83          from x in Model.GetEstimatedValues(ProblemData, 0 - minLag, ProblemData.Dataset.Rows)
84          let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x))
85          select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX;
[5010]86      estimatedValues = Enumerable.Repeat(UpperEstimationLimit, Math.Abs(minLag)).Concat(calculatedValues).ToList();
[3884]87      OnEstimatedValuesChanged();
[3462]88    }
89
[5275]90    public virtual IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) {
91      if (estimatedValues == null) RecalculateEstimatedValues();
92      foreach (int row in rows)
93        yield return estimatedValues[row];
[3462]94    }
[3442]95  }
96}
Note: See TracBrowser for help on using the repository browser.