Free cookie consent management tool by TermsFeed Policy Generator

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

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

Merged changes from GP-refactoring branch back into the trunk #713.

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