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