[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 |
|
---|
| 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;
|
---|
[2210] | 32 | using HeuristicLab.GP.Interfaces;
|
---|
[645] | 33 |
|
---|
| 34 | namespace HeuristicLab.GP.StructureIdentification {
|
---|
[2202] | 35 | public class Variable : Terminal {
|
---|
[645] | 36 | public const string WEIGHT = "Weight";
|
---|
| 37 | public const string OFFSET = "SampleOffset";
|
---|
[2210] | 38 | public const string VARIABLENAME = "Variable";
|
---|
[645] | 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 |
|
---|
[2202] | 51 | public override IFunctionTree GetTreeNode() {
|
---|
[2210] | 52 | return new VariableFunctionTree(this);
|
---|
[2202] | 53 | }
|
---|
| 54 |
|
---|
[645] | 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();
|
---|
[2174] | 64 | UniformItemChooser variableRandomizer = new UniformItemChooser();
|
---|
[2210] | 65 | variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
|
---|
[2174] | 66 | variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
|
---|
| 67 | variableRandomizer.Name = "Variable randomizer";
|
---|
[645] | 68 | NormalRandomizer weightRandomizer = new NormalRandomizer();
|
---|
[1618] | 69 | weightRandomizer.Mu = 0.0;
|
---|
[645] | 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);
|
---|
[2174] | 80 | combinedOp.OperatorGraph.AddOperator(variableRandomizer);
|
---|
[645] | 81 | combinedOp.OperatorGraph.AddOperator(weightRandomizer);
|
---|
| 82 | combinedOp.OperatorGraph.AddOperator(offsetRandomizer);
|
---|
| 83 | combinedOp.OperatorGraph.InitialOperator = seq;
|
---|
[2174] | 84 | seq.AddSubOperator(variableRandomizer);
|
---|
[645] | 85 | seq.AddSubOperator(weightRandomizer);
|
---|
| 86 | seq.AddSubOperator(offsetRandomizer);
|
---|
[2202] | 87 | Initializer = combinedOp;
|
---|
[645] | 88 | }
|
---|
| 89 |
|
---|
| 90 | private void SetupManipulation() {
|
---|
| 91 | // manipulation operator
|
---|
| 92 | CombinedOperator combinedOp = new CombinedOperator();
|
---|
| 93 | SequentialProcessor seq = new SequentialProcessor();
|
---|
[2174] | 94 | UniformItemChooser variableRandomizer = new UniformItemChooser();
|
---|
[2210] | 95 | variableRandomizer.GetVariableInfo("Value").ActualName = VARIABLENAME;
|
---|
[2174] | 96 | variableRandomizer.GetVariableInfo("Values").ActualName = "InputVariables";
|
---|
| 97 | variableRandomizer.Name = "Variable randomizer";
|
---|
[645] | 98 | NormalRandomAdder weightRandomAdder = new NormalRandomAdder();
|
---|
| 99 | weightRandomAdder.Mu = 0.0;
|
---|
[1618] | 100 | weightRandomAdder.Sigma = 1.0;
|
---|
[645] | 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);
|
---|
[2174] | 110 | combinedOp.OperatorGraph.AddOperator(variableRandomizer);
|
---|
[645] | 111 | combinedOp.OperatorGraph.AddOperator(weightRandomAdder);
|
---|
| 112 | combinedOp.OperatorGraph.AddOperator(offsetRandomAdder);
|
---|
| 113 | combinedOp.OperatorGraph.InitialOperator = seq;
|
---|
[2174] | 114 | seq.AddSubOperator(variableRandomizer);
|
---|
[645] | 115 | seq.AddSubOperator(weightRandomAdder);
|
---|
| 116 | seq.AddSubOperator(offsetRandomAdder);
|
---|
[2202] | 117 | Manipulator = combinedOp;
|
---|
[645] | 118 | }
|
---|
| 119 |
|
---|
[2174] | 120 | public void SetConstraints(int minSampleOffset, int maxSampleOffset) {
|
---|
[645] | 121 | this.minOffset = minSampleOffset;
|
---|
| 122 | this.maxOffset = maxSampleOffset;
|
---|
| 123 | SetupInitialization();
|
---|
| 124 | SetupManipulation();
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | }
|
---|