Changeset 2161 for trunk/sources/HeuristicLab.Modeling
- Timestamp:
- 07/15/09 16:23:29 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Modeling/3.2/ProblemInjector.cs
r1856 r2161 56 56 AddVariable(new Variable("TrainingSamplesEnd", new IntData())); 57 57 58 AddVariableInfo(new VariableInfo("ActualTrainingSamplesStart", "ActualTrainingSamplesStart", typeof(IntData), VariableKind.New)); 59 AddVariableInfo(new VariableInfo("ActualTrainingSamplesEnd", "ActualTrainingSamplesEnd", typeof(IntData), VariableKind.New)); 60 58 61 AddVariableInfo(new VariableInfo("ValidationSamplesStart", "ValidationSamplesStart", typeof(IntData), VariableKind.New)); 59 62 GetVariableInfo("ValidationSamplesStart").Local = true; … … 71 74 GetVariableInfo("TestSamplesEnd").Local = true; 72 75 AddVariable(new Variable("TestSamplesEnd", new IntData())); 76 77 AddVariableInfo(new VariableInfo("MaxNumberOfTrainingSamples", "Maximal number of training samples to use (optional)", typeof(IntData), VariableKind.In)); 73 78 } 74 79 … … 78 83 79 84 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; 85 106 } 107 scope.AddVariable(new Variable(scope.TranslateName("ActualTrainingSamplesStart"), new IntData(trainingStart))); 108 scope.AddVariable(new Variable(scope.TranslateName("ActualTrainingSamplesEnd"), new IntData(trainingStart + nTrainingSamples))); 86 109 return null; 110 } 111 112 private void AddVariableToScope(string variableName, IScope scope) { 113 scope.AddVariable(new Variable(variableName, (IItem)GetVariable(variableName).Value.Clone())); 87 114 } 88 115 }
Note: See TracChangeset
for help on using the changeset viewer.