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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
30 | using HeuristicLab.Operators;
|
---|
31 | using HeuristicLab.Optimization;
|
---|
32 | using HeuristicLab.Parameters;
|
---|
33 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
34 | using HeuristicLab.PluginInfrastructure;
|
---|
35 | using HeuristicLab.Problems.DataAnalysis;
|
---|
36 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
37 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
|
---|
38 |
|
---|
39 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
40 | [StorableClass]
|
---|
41 | [Item("SymbolicRegressionModel", "A symbolic regression model represents an entity that provides estimated values based on input values.")]
|
---|
42 | public class SymbolicRegressionModel : NamedItem, IDataAnalysisModel {
|
---|
43 | private SymbolicRegressionModel() : base() { } // for cloning
|
---|
44 | [StorableConstructor]
|
---|
45 | protected SymbolicRegressionModel(bool deserializing)
|
---|
46 | : base(deserializing) {
|
---|
47 | }
|
---|
48 | public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree)
|
---|
49 | : base() {
|
---|
50 | this.tree = tree;
|
---|
51 | this.interpreter = interpreter;
|
---|
52 | this.inputVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(var => var.VariableName).Distinct().ToList();
|
---|
53 | }
|
---|
54 |
|
---|
55 | [Storable]
|
---|
56 | private SymbolicExpressionTree tree;
|
---|
57 | public SymbolicExpressionTree SymbolicExpressionTree {
|
---|
58 | get { return tree; }
|
---|
59 | }
|
---|
60 | [Storable]
|
---|
61 | private ISymbolicExpressionTreeInterpreter interpreter;
|
---|
62 | public ISymbolicExpressionTreeInterpreter Interpreter {
|
---|
63 | get { return interpreter; }
|
---|
64 | }
|
---|
65 | [Storable]
|
---|
66 | private List<string> inputVariables;
|
---|
67 | public IEnumerable<string> InputVariables {
|
---|
68 | get { return inputVariables.AsEnumerable(); }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, int start, int end) {
|
---|
72 | return interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, Enumerable.Range(start, end - start));
|
---|
73 | }
|
---|
74 |
|
---|
75 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
76 | var clone = (SymbolicRegressionModel)base.Clone(cloner);
|
---|
77 | clone.tree = (SymbolicExpressionTree)cloner.Clone(tree);
|
---|
78 | clone.interpreter = (ISymbolicExpressionTreeInterpreter)cloner.Clone(interpreter);
|
---|
79 | clone.inputVariables = new List<string>(inputVariables);
|
---|
80 | return clone;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|