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.Linq;
|
---|
25 | using System.Drawing;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 | using HeuristicLab.PluginInfrastructure;
|
---|
33 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
34 | using HeuristicLab.Problems.DataAnalysis;
|
---|
35 | using HeuristicLab.Operators;
|
---|
36 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
37 |
|
---|
38 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
39 | [StorableClass]
|
---|
40 | public class SymbolicRegressionModel : DeepCloneable, IModel {
|
---|
41 | [Storable]
|
---|
42 | private SymbolicExpressionTree tree;
|
---|
43 | public SymbolicExpressionTree SymbolicExpressionTree {
|
---|
44 | get { return tree; }
|
---|
45 | }
|
---|
46 | [Storable]
|
---|
47 | private SimpleArithmeticExpressionEvaluator evaluator;
|
---|
48 | public SimpleArithmeticExpressionEvaluator Evaluator {
|
---|
49 | get { return evaluator; }
|
---|
50 | }
|
---|
51 | private Dataset emptyDataset;
|
---|
52 | private IEnumerable<int> firstRow = new int[] { 0 };
|
---|
53 |
|
---|
54 | public SymbolicRegressionModel() : base() { } // for cloning
|
---|
55 |
|
---|
56 | public SymbolicRegressionModel(SymbolicExpressionTree tree, IEnumerable<string> inputVariables)
|
---|
57 | : base() {
|
---|
58 | this.tree = tree;
|
---|
59 | this.evaluator = new SimpleArithmeticExpressionEvaluator();
|
---|
60 | emptyDataset = new Dataset(inputVariables, new double[1, inputVariables.Count()]);
|
---|
61 | }
|
---|
62 |
|
---|
63 | #region IModel Members
|
---|
64 |
|
---|
65 | public double GetValue(double[] xs) {
|
---|
66 | if (xs.Length != emptyDataset.Columns) throw new ArgumentException("Length of input vector doesn't match model");
|
---|
67 | for (int i = 0; i < xs.Length; i++) {
|
---|
68 | emptyDataset[0, i] = xs[i];
|
---|
69 | }
|
---|
70 | return evaluator.EstimatedValues(tree, emptyDataset, firstRow).First();
|
---|
71 | }
|
---|
72 |
|
---|
73 | #endregion
|
---|
74 | }
|
---|
75 | }
|
---|