- Timestamp:
- 11/02/08 22:42:40 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.Classification/CrossValidation.cs
r668 r708 28 28 using HeuristicLab.DataAnalysis; 29 29 30 namespace HeuristicLab.GP.StructureIdentification.Classification { 31 public class CrossValidation : OperatorBase { 30 namespace HeuristicLab.GP.StructureIdentification.Classification 31 { 32 public class CrossValidation : OperatorBase 33 { 32 34 33 private const string DATASET = "Dataset";34 private const string NFOLD = "n-Fold";35 private const string TRAININGSAMPLESSTART = "TrainingSamplesStart";36 private const string TRAININGSAMPLESEND = "TrainingSamplesEnd";37 private const string VALIDATIONSAMPLESSTART = "ValidationSamplesStart";38 private const string VALIDATIONSAMPLESEND = "ValidationSamplesEnd";39 private const string TESTSAMPLESSTART = "TestSamplesStart";40 private const string TESTSAMPLESEND = "TestSamplesEnd";35 private const string DATASET = "Dataset"; 36 private const string NFOLD = "n-Fold"; 37 private const string TRAININGSAMPLESSTART = "TrainingSamplesStart"; 38 private const string TRAININGSAMPLESEND = "TrainingSamplesEnd"; 39 private const string VALIDATIONSAMPLESSTART = "ValidationSamplesStart"; 40 private const string VALIDATIONSAMPLESEND = "ValidationSamplesEnd"; 41 private const string TESTSAMPLESSTART = "TestSamplesStart"; 42 private const string TESTSAMPLESEND = "TestSamplesEnd"; 41 43 42 public override string Description { 43 get { return @"TASK"; } 44 } 44 public override string Description 45 { 46 get { return @"TASK"; } 47 } 45 48 46 public CrossValidation() 47 : base() { 48 AddVariableInfo(new VariableInfo(DATASET, "The original dataset and the new datasets in the newly created subscopes", typeof(Dataset), VariableKind.In)); 49 AddVariableInfo(new VariableInfo(NFOLD, "Number of folds for the cross-validation", typeof(IntData), VariableKind.In)); 50 AddVariableInfo(new VariableInfo(TRAININGSAMPLESSTART, "The start of training samples in the original dataset and starts of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 51 AddVariableInfo(new VariableInfo(TRAININGSAMPLESEND, "The end of training samples in the original dataset and ends of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 52 AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESSTART, "The start of validation samples in the original dataset and starts of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 53 AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESEND, "The end of validation samples in the original dataset and ends of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 54 AddVariableInfo(new VariableInfo(TESTSAMPLESSTART, "The start of the test samples in the new datasets", typeof(IntData), VariableKind.New)); 55 AddVariableInfo(new VariableInfo(TESTSAMPLESEND, "The end of the test samples in the new datasets", typeof(IntData), VariableKind.New)); 56 } 49 public CrossValidation() 50 : base() 51 { 52 AddVariableInfo(new VariableInfo(DATASET, "The original dataset and the new datasets in the newly created subscopes", typeof(Dataset), VariableKind.In)); 53 AddVariableInfo(new VariableInfo(NFOLD, "Number of folds for the cross-validation", typeof(IntData), VariableKind.In)); 54 AddVariableInfo(new VariableInfo(TRAININGSAMPLESSTART, "The start of training samples in the original dataset and starts of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 55 AddVariableInfo(new VariableInfo(TRAININGSAMPLESEND, "The end of training samples in the original dataset and ends of training samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 56 AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESSTART, "The start of validation samples in the original dataset and starts of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 57 AddVariableInfo(new VariableInfo(VALIDATIONSAMPLESEND, "The end of validation samples in the original dataset and ends of validation samples in the new datasets", typeof(IntData), VariableKind.In | VariableKind.New)); 58 AddVariableInfo(new VariableInfo(TESTSAMPLESSTART, "The start of the test samples in the new datasets", typeof(IntData), VariableKind.New)); 59 AddVariableInfo(new VariableInfo(TESTSAMPLESEND, "The end of the test samples in the new datasets", typeof(IntData), VariableKind.New)); 60 } 57 61 58 public override IOperation Apply(IScope scope) {62 public override IOperation Apply(IScope scope) { 59 63 Dataset origDataset = GetVariableValue<Dataset>(DATASET, scope, true); 60 64 int nFolds = GetVariableValue<IntData>(NFOLD, scope, true).Data; 65 if (nFolds < 2) throw new ArgumentException("The number of folds (nFolds) has to be >=2 for cross validation"); 61 66 int origTrainingSamplesStart = GetVariableValue<IntData>(TRAININGSAMPLESSTART, scope, true).Data; 62 67 int origTrainingSamplesEnd = GetVariableValue<IntData>(TRAININGSAMPLESEND, scope, true).Data; … … 101 106 } 102 107 103 private void RotateArray(double[] samples, int p) { 104 Array.Reverse(samples, 0, p); 105 Array.Reverse(samples, p, samples.Length - p); 106 Array.Reverse(samples); 108 private void RotateArray(double[] samples, int p) 109 { 110 Array.Reverse(samples, 0, p); 111 Array.Reverse(samples, p, samples.Length - p); 112 Array.Reverse(samples); 113 } 107 114 } 108 }109 115 }
Note: See TracChangeset
for help on using the changeset viewer.