Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs @ 5467

Last change on this file since 5467 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.6 KB
RevLine 
[3442]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3442]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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
[3915]26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
[3442]27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.DataAnalysis.Symbolic;
[3915]29using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
[3442]30
31namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
32  [StorableClass]
[3462]33  [Item("SymbolicRegressionModel", "A symbolic regression model represents an entity that provides estimated values based on input values.")]
[4722]34  public sealed class SymbolicRegressionModel : NamedItem, IDataAnalysisModel {
[3884]35    [StorableConstructor]
[4722]36    private SymbolicRegressionModel(bool deserializing) : base(deserializing) { }
37    private SymbolicRegressionModel(SymbolicRegressionModel original, Cloner cloner)
38      : base(original, cloner) {
39      tree = (SymbolicExpressionTree)cloner.Clone(original.tree);
40      interpreter = (ISymbolicExpressionTreeInterpreter)cloner.Clone(original.interpreter);
41      inputVariables = new List<string>(original.inputVariables);
[3884]42    }
[4722]43
[3915]44    public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree)
[3884]45      : base() {
46      this.tree = tree;
47      this.interpreter = interpreter;
[3915]48      this.inputVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(var => var.VariableName).Distinct().ToList();
[3884]49    }
50
[4722]51    public override IDeepCloneable Clone(Cloner cloner) {
52      return new SymbolicRegressionModel(this, cloner);
53    }
54
[4415]55    [StorableHook(HookType.AfterDeserialization)]
[4722]56    private void AfterDeserialization() {
[4415]57      if (inputVariables == null)
58        this.inputVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(var => var.VariableName).Distinct().ToList();
59    }
60
[3442]61    [Storable]
62    private SymbolicExpressionTree tree;
63    public SymbolicExpressionTree SymbolicExpressionTree {
64      get { return tree; }
65    }
66    [Storable]
[3462]67    private ISymbolicExpressionTreeInterpreter interpreter;
68    public ISymbolicExpressionTreeInterpreter Interpreter {
69      get { return interpreter; }
[3442]70    }
[3884]71    [Storable]
[3541]72    private List<string> inputVariables;
[3462]73    public IEnumerable<string> InputVariables {
74      get { return inputVariables.AsEnumerable(); }
75    }
[3442]76
[3884]77    public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, int start, int end) {
[4468]78      return GetEstimatedValues(problemData, Enumerable.Range(start, end - start));
[3442]79    }
[4468]80    public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, IEnumerable<int> rows) {
81      return interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
82    }
[3442]83  }
84}
Note: See TracBrowser for help on using the repository browser.