Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Symbols/Variable.cs @ 2365

Last change on this file since 2365 was 2365, checked in by gkronber, 15 years ago

Fixed #747 (GP engines create model with non-zero time-offsets).

File size: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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 HeuristicLab.GP.Interfaces;
23using HeuristicLab.Operators;
24using HeuristicLab.Random;
25using HeuristicLab.Data;
26
27namespace HeuristicLab.GP.StructureIdentification {
28  public class Variable : Terminal {
29    public const string WEIGHT = "Weight";
30    public const string OFFSET = "SampleOffset";
31    public const string VARIABLENAME = "Variable";
32
33    private int minOffset;
34    private int maxOffset;
35
36    public override string Description {
37      get {
38        return @"Variable reads a value from a dataset, multiplies that value with a given factor and returns the result.
39The variable 'SampleOffset' can be used to read a value from previous or following rows.
40The index of the row that is actually read is SampleIndex+SampleOffset).";
41      }
42    }
43
44
45    public override IFunctionTree GetTreeNode() {
46      return new VariableFunctionTree(this);
47    }
48
49    public Variable()
50      : base() {
51      SetupInitialization();
52      SetupManipulation();
53    }
54
55    private void SetupInitialization() {
56      CombinedOperator combinedOp = new CombinedOperator();
57      SequentialProcessor seq = new SequentialProcessor();
58      UniformItemChooser variableRandomizer = new UniformItemChooser();
59      variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
60      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
61      variableRandomizer.Name = "Variable randomizer";
62      NormalRandomizer weightRandomizer = new NormalRandomizer();
63      weightRandomizer.Mu = 0.0;
64      weightRandomizer.Sigma = 1.0;
65      weightRandomizer.GetVariableInfo("Value").ActualName = WEIGHT;
66      weightRandomizer.Name = "Weight Randomizer";
67      UniformRandomizer offsetRandomizer = new UniformRandomizer();
68      offsetRandomizer.Min = minOffset;
69      offsetRandomizer.Max = maxOffset + 1;
70      offsetRandomizer.GetVariableInfo("Value").ActualName = OFFSET;
71      offsetRandomizer.Name = "Offset Randomizer";
72
73      combinedOp.OperatorGraph.AddOperator(seq);
74      combinedOp.OperatorGraph.AddOperator(variableRandomizer);
75      combinedOp.OperatorGraph.AddOperator(weightRandomizer);
76      combinedOp.OperatorGraph.AddOperator(offsetRandomizer);
77      combinedOp.OperatorGraph.InitialOperator = seq;
78      seq.AddSubOperator(variableRandomizer);
79      seq.AddSubOperator(weightRandomizer);
80      seq.AddSubOperator(offsetRandomizer);
81      Initializer = combinedOp;
82    }
83
84    private void SetupManipulation() {
85      // manipulation operator
86      CombinedOperator combinedOp = new CombinedOperator();
87      SequentialProcessor seq = new SequentialProcessor();
88      UniformItemChooser variableRandomizer = new UniformItemChooser();
89      variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
90      variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
91      variableRandomizer.Name = "Variable randomizer";
92      NormalRandomAdder weightRandomAdder = new NormalRandomAdder();
93      weightRandomAdder.Mu = 0.0;
94      weightRandomAdder.Sigma = 1.0;
95      weightRandomAdder.GetVariableInfo("Value").ActualName = WEIGHT;
96      weightRandomAdder.Name = "Weight Adder";
97      NormalRandomAdder offsetRandomAdder = new NormalRandomAdder();
98      offsetRandomAdder.Mu = 0.0;
99      offsetRandomAdder.Sigma = 1.0;
100      offsetRandomAdder.GetVariableInfo("Value").ActualName = OFFSET;
101      offsetRandomAdder.Name = "Offset Adder";
102      offsetRandomAdder.GetVariableInfo("MinValue").Local = true;
103      offsetRandomAdder.AddVariable(new HeuristicLab.Core.Variable("MinValue", new DoubleData(minOffset)));
104      offsetRandomAdder.GetVariableInfo("MaxValue").Local = true;
105      offsetRandomAdder.AddVariable(new HeuristicLab.Core.Variable("MaxValue", new DoubleData(maxOffset + 1)));
106
107      combinedOp.OperatorGraph.AddOperator(seq);
108      combinedOp.OperatorGraph.AddOperator(variableRandomizer);
109      combinedOp.OperatorGraph.AddOperator(weightRandomAdder);
110      combinedOp.OperatorGraph.AddOperator(offsetRandomAdder);
111      combinedOp.OperatorGraph.InitialOperator = seq;
112      seq.AddSubOperator(variableRandomizer);
113      seq.AddSubOperator(weightRandomAdder);
114      seq.AddSubOperator(offsetRandomAdder);
115      Manipulator = combinedOp;
116    }
117
118    public void SetConstraints(int minSampleOffset, int maxSampleOffset) {
119      this.minOffset = minSampleOffset;
120      this.maxOffset = maxSampleOffset;
121      SetupInitialization();
122      SetupManipulation();
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.