[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 |
|
---|
| 22 | using System;
|
---|
[4068] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
[3442] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[4341] | 28 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
|
---|
[3442] | 29 |
|
---|
| 30 | namespace 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 {
|
---|
[4443] | 37 | public SymbolicRegressionSolution() : base() { } // for cloning
|
---|
[4401] | 38 | [StorableConstructor]
|
---|
| 39 | public SymbolicRegressionSolution(bool deserializing) : base(deserializing) { }
|
---|
[3513] | 40 | public SymbolicRegressionSolution(DataAnalysisProblemData problemData, SymbolicRegressionModel model, double lowerEstimationLimit, double upperEstimationLimit)
|
---|
| 41 | : base(problemData, lowerEstimationLimit, upperEstimationLimit) {
|
---|
[3884] | 42 | this.Model = model;
|
---|
[3442] | 43 | }
|
---|
[3462] | 44 |
|
---|
[3884] | 45 | public override Image ItemImage {
|
---|
| 46 | get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Function; }
|
---|
[3462] | 47 | }
|
---|
| 48 |
|
---|
[3884] | 49 | public new SymbolicRegressionModel Model {
|
---|
| 50 | get { return (SymbolicRegressionModel)base.Model; }
|
---|
| 51 | set { base.Model = value; }
|
---|
[3462] | 52 | }
|
---|
| 53 |
|
---|
[3884] | 54 | protected override void RecalculateEstimatedValues() {
|
---|
[4341] | 55 | int minLag = 0;
|
---|
| 56 | var laggedTreeNodes = Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>();
|
---|
| 57 | if (laggedTreeNodes.Any())
|
---|
| 58 | minLag = laggedTreeNodes.Min(node => node.Lag);
|
---|
| 59 | IEnumerable<double> calculatedValues =
|
---|
| 60 | from x in Model.GetEstimatedValues(ProblemData, 0 - minLag, ProblemData.Dataset.Rows)
|
---|
| 61 | let boundedX = Math.Min(UpperEstimationLimit, Math.Max(LowerEstimationLimit, x))
|
---|
| 62 | select double.IsNaN(boundedX) ? UpperEstimationLimit : boundedX;
|
---|
| 63 | estimatedValues = Enumerable.Repeat(double.NaN, Math.Abs(minLag)).Concat(calculatedValues).ToList();
|
---|
[3884] | 64 | OnEstimatedValuesChanged();
|
---|
[3462] | 65 | }
|
---|
| 66 |
|
---|
| 67 | private List<double> estimatedValues;
|
---|
| 68 | public override IEnumerable<double> EstimatedValues {
|
---|
| 69 | get {
|
---|
[3485] | 70 | if (estimatedValues == null) RecalculateEstimatedValues();
|
---|
[3462] | 71 | return estimatedValues.AsEnumerable();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | public override IEnumerable<double> EstimatedTrainingValues {
|
---|
| 76 | get {
|
---|
[3485] | 77 | if (estimatedValues == null) RecalculateEstimatedValues();
|
---|
[3462] | 78 | int start = ProblemData.TrainingSamplesStart.Value;
|
---|
| 79 | int n = ProblemData.TrainingSamplesEnd.Value - start;
|
---|
| 80 | return estimatedValues.Skip(start).Take(n).ToList();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | public override IEnumerable<double> EstimatedTestValues {
|
---|
| 85 | get {
|
---|
[3485] | 86 | if (estimatedValues == null) RecalculateEstimatedValues();
|
---|
[3462] | 87 | int start = ProblemData.TestSamplesStart.Value;
|
---|
| 88 | int n = ProblemData.TestSamplesEnd.Value - start;
|
---|
| 89 | return estimatedValues.Skip(start).Take(n).ToList();
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
[3442] | 92 | }
|
---|
| 93 | }
|
---|