[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.Collections.Generic;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
[3915] | 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[3442] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
[3915] | 29 | using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
|
---|
[3442] | 30 |
|
---|
| 31 | namespace 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.")]
|
---|
[3884] | 34 | public class SymbolicRegressionModel : NamedItem, IDataAnalysisModel {
|
---|
| 35 | private SymbolicRegressionModel() : base() { } // for cloning
|
---|
| 36 | [StorableConstructor]
|
---|
| 37 | protected SymbolicRegressionModel(bool deserializing)
|
---|
| 38 | : base(deserializing) {
|
---|
| 39 | }
|
---|
[3915] | 40 | public SymbolicRegressionModel(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree tree)
|
---|
[3884] | 41 | : base() {
|
---|
| 42 | this.tree = tree;
|
---|
| 43 | this.interpreter = interpreter;
|
---|
[3915] | 44 | this.inputVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(var => var.VariableName).Distinct().ToList();
|
---|
[3884] | 45 | }
|
---|
| 46 |
|
---|
[4415] | 47 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 48 | private void AfterDeserializationHook() {
|
---|
| 49 | if (inputVariables == null)
|
---|
| 50 | this.inputVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(var => var.VariableName).Distinct().ToList();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[3442] | 53 | [Storable]
|
---|
| 54 | private SymbolicExpressionTree tree;
|
---|
| 55 | public SymbolicExpressionTree SymbolicExpressionTree {
|
---|
| 56 | get { return tree; }
|
---|
| 57 | }
|
---|
| 58 | [Storable]
|
---|
[3462] | 59 | private ISymbolicExpressionTreeInterpreter interpreter;
|
---|
| 60 | public ISymbolicExpressionTreeInterpreter Interpreter {
|
---|
| 61 | get { return interpreter; }
|
---|
[3442] | 62 | }
|
---|
[3884] | 63 | [Storable]
|
---|
[3541] | 64 | private List<string> inputVariables;
|
---|
[3462] | 65 | public IEnumerable<string> InputVariables {
|
---|
| 66 | get { return inputVariables.AsEnumerable(); }
|
---|
| 67 | }
|
---|
[3442] | 68 |
|
---|
[3884] | 69 | public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, int start, int end) {
|
---|
[4468] | 70 | return GetEstimatedValues(problemData, Enumerable.Range(start, end - start));
|
---|
[3442] | 71 | }
|
---|
[4468] | 72 | public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, IEnumerable<int> rows) {
|
---|
| 73 | return interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows);
|
---|
| 74 | }
|
---|
[3442] | 75 |
|
---|
[3462] | 76 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 77 | var clone = (SymbolicRegressionModel)base.Clone(cloner);
|
---|
[3493] | 78 | clone.tree = (SymbolicExpressionTree)cloner.Clone(tree);
|
---|
| 79 | clone.interpreter = (ISymbolicExpressionTreeInterpreter)cloner.Clone(interpreter);
|
---|
[3462] | 80 | clone.inputVariables = new List<string>(inputVariables);
|
---|
| 81 | return clone;
|
---|
[3442] | 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|