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