Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Functions/Variable.cs @ 370

Last change on this file since 370 was 229, checked in by gkronber, 17 years ago

merged changes (r201 r203 r206 r208 r220 r223 r224 r225 r226 r227) from branch ExperimentalFunctionsBaking into the trunk. (ticket #139)

File size: 3.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;
30
31namespace HeuristicLab.Functions {
32  public sealed class Variable : FunctionBase {
33
34    public const string WEIGHT = "Weight";
35    public const string OFFSET = "SampleOffset";
36    public const string INDEX = "Variable";
37
38    public override string Description {
39      get {
40        return @"Variable reads a value from a dataset, multiplies that value with a given factor and returns the result.
41The variable 'SampleOffset' can be used to read a value from previous or following rows.
42The index of the row that is actually read is SampleIndex+SampleOffset).";
43      }
44    }
45
46    public Variable()
47      : base() {
48      AddVariableInfo(new VariableInfo(INDEX, "Index of the variable in the dataset representing this feature", typeof(ConstrainedIntData), VariableKind.None));
49      GetVariableInfo(INDEX).Local = true;
50      AddVariableInfo(new VariableInfo(WEIGHT, "Weight is multiplied to the feature value", typeof(ConstrainedDoubleData), VariableKind.None));
51      GetVariableInfo(WEIGHT).Local = true;
52      AddVariableInfo(new VariableInfo(OFFSET, "SampleOffset is added to the sample index", typeof(ConstrainedIntData), VariableKind.None));
53      GetVariableInfo(OFFSET).Local = true;
54
55      ConstrainedDoubleData weight = new ConstrainedDoubleData();
56      // initialize a totally arbitrary range for the weight = [-20.0, 20.0]
57      weight.AddConstraint(new DoubleBoundedConstraint(-20.0, 20.0));
58      AddVariable(new HeuristicLab.Core.Variable(WEIGHT, weight));
59
60      ConstrainedIntData variable = new ConstrainedIntData();
61      AddVariable(new HeuristicLab.Core.Variable(INDEX, variable));
62
63      ConstrainedIntData sampleOffset = new ConstrainedIntData();
64      // initialize a totally arbitrary default range for sampleoffset = [-10, 10]
65      sampleOffset.AddConstraint(new IntBoundedConstraint(0, 0));
66      AddVariable(new HeuristicLab.Core.Variable(OFFSET, sampleOffset));
67
68      // variable can't have suboperators
69      AddConstraint(new NumberOfSubOperatorsConstraint(0, 0));
70    }
71
72    public override void Accept(IFunctionVisitor visitor) {
73      visitor.Visit(this);
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.