Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/SymbolicVectorRegressionGrammar.cs @ 4866

Last change on this file since 4866 was 4401, checked in by gkronber, 14 years ago

Added model and solution classes for time series prognosis and added views for time series prognosis solutions. #1142

File size: 4.6 KB
Line 
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
22using System.Collections.Generic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Problems.DataAnalysis.MultiVariate.Symbolic;
28using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
29
30namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic {
31  [StorableClass]
32  [Item("SymbolicVectorRegressionGrammar", "Represents a grammar for symbolic vector regression using all available functions.")]
33  public class SymbolicVectorRegressionGrammar : MultiVariateExpressionGrammar {
34    public SymbolicVectorRegressionGrammar() : this(1) { }
35
36    public SymbolicVectorRegressionGrammar(int dimension)
37      : base(dimension) {
38      Initialize();
39    }
40
41    protected SymbolicVectorRegressionGrammar(SymbolicVectorRegressionGrammar original) : base(original.Dimension) {
42    // fill ???
43    }
44
45    private void Initialize() {
46      var add = new Addition();
47      var sub = new Subtraction();
48      var mul = new Multiplication();
49      var div = new Division();
50      var mean = new Average();
51      var sin = new Sine();
52      var cos = new Cosine();
53      var tan = new Tangent();
54      var log = new Logarithm();
55      var exp = new Exponential();
56      var @if = new IfThenElse();
57      var gt = new GreaterThan();
58      var lt = new LessThan();
59      var and = new And();
60      var or = new Or();
61      var not = new Not();
62      var constant = new Constant();
63      constant.MinValue = -20;
64      constant.MaxValue = 20;
65      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable();
66
67      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol };
68      var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not };
69      var binaryFunctionSymbols = new List<Symbol>() { gt, lt };
70      var functionSymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or };
71
72      foreach (var symb in allSymbols)
73        AddSymbol(symb);
74
75      foreach (var funSymb in functionSymbols) {
76        SetMinSubtreeCount(funSymb, 1);
77        SetMaxSubtreeCount(funSymb, 3);
78      }
79      foreach (var funSymb in unaryFunctionSymbols) {
80        SetMinSubtreeCount(funSymb, 1);
81        SetMaxSubtreeCount(funSymb, 1);
82      }
83      foreach (var funSymb in binaryFunctionSymbols) {
84        SetMinSubtreeCount(funSymb, 2);
85        SetMaxSubtreeCount(funSymb, 2);
86      }
87
88      SetMinSubtreeCount(@if, 3);
89      SetMaxSubtreeCount(@if, 3);
90      SetMinSubtreeCount(constant, 0);
91      SetMaxSubtreeCount(constant, 0);
92      SetMinSubtreeCount(variableSymbol, 0);
93      SetMaxSubtreeCount(variableSymbol, 0);
94
95      SetMinSubtreeCount(StartSymbol, Dimension);
96      SetMaxSubtreeCount(StartSymbol, Dimension);
97
98      SetMinSubtreeCount(constant, 0);
99      SetMaxSubtreeCount(constant, 0);
100      SetMinSubtreeCount(variableSymbol, 0);
101      SetMaxSubtreeCount(variableSymbol, 0);
102
103      // allow all symbols as children of the start-symbol
104      foreach (Symbol symb in allSymbols) {
105        for (int i = 0; i < GetMaxSubtreeCount(StartSymbol); i++)
106          SetAllowedChild(StartSymbol, symb, i);
107      }
108
109      // allow all symbols as children of all symbols
110      foreach (var parent in allSymbols) {
111        for (int i = 0; i < GetMaxSubtreeCount(parent); i++)
112          foreach (var child in allSymbols) {
113            SetAllowedChild(parent, child, i);
114          }
115      }
116    }
117
118    public override IDeepCloneable Clone(Cloner cloner) {
119      var clone = new SymbolicVectorRegressionGrammar(this);
120      cloner.RegisterClonedObject(this, clone);
121      return clone;
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.