[645] | 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 |
|
---|
[2212] | 22 | using HeuristicLab.GP.Interfaces;
|
---|
| 23 | using HeuristicLab.Operators;
|
---|
[645] | 24 | using HeuristicLab.Random;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.GP.StructureIdentification {
|
---|
[2202] | 27 | public class Variable : Terminal {
|
---|
[645] | 28 | public const string WEIGHT = "Weight";
|
---|
| 29 | public const string OFFSET = "SampleOffset";
|
---|
[2210] | 30 | public const string VARIABLENAME = "Variable";
|
---|
[645] | 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 |
|
---|
[2218] | 43 |
|
---|
[2202] | 44 | public override IFunctionTree GetTreeNode() {
|
---|
[2210] | 45 | return new VariableFunctionTree(this);
|
---|
[2202] | 46 | }
|
---|
| 47 |
|
---|
[645] | 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();
|
---|
[2174] | 57 | UniformItemChooser variableRandomizer = new UniformItemChooser();
|
---|
[2210] | 58 | variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
|
---|
[2174] | 59 | variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
|
---|
| 60 | variableRandomizer.Name = "Variable randomizer";
|
---|
[645] | 61 | NormalRandomizer weightRandomizer = new NormalRandomizer();
|
---|
[1618] | 62 | weightRandomizer.Mu = 0.0;
|
---|
[645] | 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);
|
---|
[2174] | 73 | combinedOp.OperatorGraph.AddOperator(variableRandomizer);
|
---|
[645] | 74 | combinedOp.OperatorGraph.AddOperator(weightRandomizer);
|
---|
| 75 | combinedOp.OperatorGraph.AddOperator(offsetRandomizer);
|
---|
| 76 | combinedOp.OperatorGraph.InitialOperator = seq;
|
---|
[2174] | 77 | seq.AddSubOperator(variableRandomizer);
|
---|
[645] | 78 | seq.AddSubOperator(weightRandomizer);
|
---|
| 79 | seq.AddSubOperator(offsetRandomizer);
|
---|
[2202] | 80 | Initializer = combinedOp;
|
---|
[645] | 81 | }
|
---|
| 82 |
|
---|
| 83 | private void SetupManipulation() {
|
---|
| 84 | // manipulation operator
|
---|
| 85 | CombinedOperator combinedOp = new CombinedOperator();
|
---|
| 86 | SequentialProcessor seq = new SequentialProcessor();
|
---|
[2174] | 87 | UniformItemChooser variableRandomizer = new UniformItemChooser();
|
---|
[2210] | 88 | variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
|
---|
[2174] | 89 | variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
|
---|
| 90 | variableRandomizer.Name = "Variable randomizer";
|
---|
[645] | 91 | NormalRandomAdder weightRandomAdder = new NormalRandomAdder();
|
---|
| 92 | weightRandomAdder.Mu = 0.0;
|
---|
[1618] | 93 | weightRandomAdder.Sigma = 1.0;
|
---|
[645] | 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);
|
---|
[2174] | 103 | combinedOp.OperatorGraph.AddOperator(variableRandomizer);
|
---|
[645] | 104 | combinedOp.OperatorGraph.AddOperator(weightRandomAdder);
|
---|
| 105 | combinedOp.OperatorGraph.AddOperator(offsetRandomAdder);
|
---|
| 106 | combinedOp.OperatorGraph.InitialOperator = seq;
|
---|
[2174] | 107 | seq.AddSubOperator(variableRandomizer);
|
---|
[645] | 108 | seq.AddSubOperator(weightRandomAdder);
|
---|
| 109 | seq.AddSubOperator(offsetRandomAdder);
|
---|
[2202] | 110 | Manipulator = combinedOp;
|
---|
[645] | 111 | }
|
---|
| 112 |
|
---|
[2174] | 113 | public void SetConstraints(int minSampleOffset, int maxSampleOffset) {
|
---|
[645] | 114 | this.minOffset = minSampleOffset;
|
---|
| 115 | this.maxOffset = maxSampleOffset;
|
---|
| 116 | SetupInitialization();
|
---|
| 117 | SetupManipulation();
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|