Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Variable.cs @ 2210

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

GP Refactoring #713

  • introduced a plugin for GP interfaces
  • created a new interface IGeneticProgrammingModel which represents GP models in HL scopes instead of IFunctionTree
  • changed interfaces IFunction and IFunctionTree
  • moved some files to new directories (general housekeeping)
  • changed all GP operators and engines to work with IGeneticProgrammingModels
  • removed parameters TreeSize and TreeHeight in all GP operators
  • changed parameter OperatorLibrary to FunctionLibrary in all GP operators
File size: 5.1 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 System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using System.Diagnostics;
27using HeuristicLab.Data;
28using HeuristicLab.Constraints;
29using HeuristicLab.DataAnalysis;
30using HeuristicLab.Random;
31using HeuristicLab.Operators;
32using HeuristicLab.GP.Interfaces;
33
34namespace 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.
46The variable 'SampleOffset' can be used to read a value from previous or following rows.
47The 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}
Note: See TracBrowser for help on using the repository browser.