Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.GP.Operators/3.3/TrainingWindowSlider.cs @ 3528

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

Merged changes from GP-refactoring branch back into the trunk #713.

File size: 3.0 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 HeuristicLab.Core;
23using HeuristicLab.Data;
24
25namespace HeuristicLab.GP.Operators {
26  public class TrainingWindowSlider : OperatorBase {
27
28    private const string TRAINING_SAMPLES_START = "TrainingSamplesStart";
29    private const string TRAINING_SAMPLES_END = "TrainingSamplesEnd";
30    private const string TRAINING_WINDOW_START = "TrainingWindowStart";
31    private const string TRAINING_WINDOW_END = "TrainingWindowEnd";
32    private const string STEP_SIZE = "SlidingStepSize";
33
34    public override string Description {
35      get { return @"Modifies variables TrainingSamplesStart and TrainingSamplesEnd to have a continually sliding window over the whole training data set."; }
36    }
37
38    public TrainingWindowSlider() {
39      AddVariableInfo(new VariableInfo(TRAINING_SAMPLES_START, "Start of whole training set", typeof(IntData), VariableKind.In));
40      AddVariableInfo(new VariableInfo(TRAINING_SAMPLES_END, "End of whole training set", typeof(IntData), VariableKind.In));
41      AddVariableInfo(new VariableInfo(TRAINING_WINDOW_START, "Start of training set window", typeof(IntData), VariableKind.In | VariableKind.Out));
42      AddVariableInfo(new VariableInfo(TRAINING_WINDOW_END, "End of training set window", typeof(IntData), VariableKind.In | VariableKind.Out));
43      AddVariableInfo(new VariableInfo(STEP_SIZE, "Number of samples to slide the window forward", typeof(IntData), VariableKind.In));
44    }
45
46    public override IOperation Apply(IScope scope) {
47      int trainingSamplesStart = GetVariableValue<IntData>(TRAINING_SAMPLES_START, scope, true).Data;
48      int trainingSamplesEnd = GetVariableValue<IntData>(TRAINING_SAMPLES_END, scope, true).Data;
49      IntData trainingWindowStart = GetVariableValue<IntData>(TRAINING_WINDOW_START, scope, true);
50      IntData trainingWindowEnd = GetVariableValue<IntData>(TRAINING_WINDOW_END, scope, true);
51      int stepSize = GetVariableValue<IntData>(STEP_SIZE, scope, true).Data;
52
53      if (trainingWindowEnd.Data + stepSize <= trainingSamplesEnd) {
54        trainingWindowStart.Data = trainingWindowStart.Data + stepSize;
55        trainingWindowEnd.Data = trainingWindowEnd.Data + stepSize;
56      }
57
58      return null;
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.