Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/15/09 16:23:29 (15 years ago)
Author:
gkronber
Message:

Implemented #704 (Shuffling of training data (only) in (non-timeseries) modeling algorithms)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs

    r1856 r2161  
    5656      AddVariable(new Variable("TrainingSamplesEnd", new IntData()));
    5757
     58      AddVariableInfo(new VariableInfo("ActualTrainingSamplesStart", "ActualTrainingSamplesStart", typeof(IntData), VariableKind.New));
     59      AddVariableInfo(new VariableInfo("ActualTrainingSamplesEnd", "ActualTrainingSamplesEnd", typeof(IntData), VariableKind.New));
     60
    5861      AddVariableInfo(new VariableInfo("ValidationSamplesStart", "ValidationSamplesStart", typeof(IntData), VariableKind.New));
    5962      GetVariableInfo("ValidationSamplesStart").Local = true;
     
    7174      GetVariableInfo("TestSamplesEnd").Local = true;
    7275      AddVariable(new Variable("TestSamplesEnd", new IntData()));
     76
     77      AddVariableInfo(new VariableInfo("MaxNumberOfTrainingSamples", "Maximal number of training samples to use (optional)", typeof(IntData), VariableKind.In));
    7378    }
    7479
     
    7883
    7984    public override IOperation Apply(IScope scope) {
    80       foreach(VariableInfo info in VariableInfos) {
    81         if(info.Local) {
    82           IVariable var = GetVariable(info.FormalName);
    83           if(var != null) scope.AddVariable(new Variable(info.ActualName, (IItem)var.Value.Clone()));
    84         }
     85      AddVariableToScope("Dataset", scope);
     86      AddVariableToScope("TargetVariable", scope);
     87      AddVariableToScope("AllowedFeatures", scope);
     88      AddVariableToScope("TrainingSamplesStart", scope);
     89      AddVariableToScope("TrainingSamplesEnd", scope);
     90      AddVariableToScope("ValidationSamplesStart", scope);
     91      AddVariableToScope("ValidationSamplesEnd", scope);
     92      AddVariableToScope("TestSamplesStart", scope);
     93      AddVariableToScope("TestSamplesEnd", scope);
     94
     95      int trainingStart = GetVariableValue<IntData>("TrainingSamplesStart", scope, true).Data;
     96      int trainingEnd = GetVariableValue<IntData>("TrainingSamplesEnd", scope, true).Data;
     97
     98      var maxTraining = GetVariableValue<IntData>("MaxNumberOfTrainingSamples", scope, true, false);
     99      int nTrainingSamples;
     100      if (maxTraining != null) {
     101        nTrainingSamples = Math.Min(maxTraining.Data, trainingEnd - trainingStart);
     102        if (nTrainingSamples <= 0)
     103          throw new ArgumentException("Maximal number of training samples must be larger than 0", "MaxNumberOfTrainingSamples");
     104      } else {
     105        nTrainingSamples = trainingEnd - trainingStart;
    85106      }
     107      scope.AddVariable(new Variable(scope.TranslateName("ActualTrainingSamplesStart"), new IntData(trainingStart)));
     108      scope.AddVariable(new Variable(scope.TranslateName("ActualTrainingSamplesEnd"), new IntData(trainingStart + nTrainingSamples)));
    86109      return null;
     110    }
     111
     112    private void AddVariableToScope(string variableName, IScope scope) {
     113      scope.AddVariable(new Variable(variableName, (IItem)GetVariable(variableName).Value.Clone()));     
    87114    }
    88115  }
Note: See TracChangeset for help on using the changeset viewer.