- Timestamp:
- 09/22/10 11:22:49 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Analyzers/RegressionSolutionAnalyzer.cs
r4068 r4468 121 121 var solution = bestSolution; 122 122 #region update R2,MSE, Rel Error 123 IEnumerable<double> trainingValues = problemData.Dataset.GetEnumeratedVariableValues( 124 problemData.TargetVariable.Value, 125 problemData.TrainingSamplesStart.Value, 126 problemData.TrainingSamplesEnd.Value); 127 IEnumerable<double> testValues = problemData.Dataset.GetEnumeratedVariableValues( 128 problemData.TargetVariable.Value, 129 problemData.TestSamplesStart.Value, 130 problemData.TestSamplesEnd.Value); 123 IEnumerable<double> trainingValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, problemData.TrainingIndizes); 124 IEnumerable<double> testValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, problemData.TestIndizes); 131 125 OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator(); 132 126 OnlineMeanAbsolutePercentageErrorEvaluator relErrorEvaluator = new OnlineMeanAbsolutePercentageErrorEvaluator(); 133 127 OnlinePearsonsRSquaredEvaluator r2Evaluator = new OnlinePearsonsRSquaredEvaluator(); 128 134 129 #region training 135 130 var originalEnumerator = trainingValues.GetEnumerator(); … … 144 139 double trainingRelError = relErrorEvaluator.MeanAbsolutePercentageError; 145 140 #endregion 141 146 142 mseEvaluator.Reset(); 147 143 relErrorEvaluator.Reset(); 148 144 r2Evaluator.Reset(); 145 149 146 #region test 150 147 originalEnumerator = testValues.GetEnumerator(); … … 159 156 double testRelError = relErrorEvaluator.MeanAbsolutePercentageError; 160 157 #endregion 158 161 159 if (results.ContainsKey(BestSolutionResultName)) { 162 160 results[BestSolutionResultName].Value = solution; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/BestSymbolicRegressionSolutionAnalyzer.cs
r4125 r4468 91 91 var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(), 92 92 SymbolicExpressionTree[i]); 93 var solution = new SymbolicRegressionSolution(ProblemData, model, lowerEstimationLimit, upperEstimationLimit); 93 DataAnalysisProblemData problemDataClone = (DataAnalysisProblemData)ProblemData.Clone(); 94 var solution = new SymbolicRegressionSolution(problemDataClone, model, lowerEstimationLimit, upperEstimationLimit); 94 95 solution.Name = BestSolutionParameterName; 95 96 solution.Description = "Best solution on validation partition found over the whole run."; 96 97 BestSolutionParameter.ActualValue = solution; 97 98 BestSolutionQualityParameter.ActualValue = Quality[i]; 98 BestSymbolicRegressionSolutionAnalyzer.UpdateSymbolicRegressionBestSolutionResults(solution, ProblemData, Results, VariableFrequencies);99 BestSymbolicRegressionSolutionAnalyzer.UpdateSymbolicRegressionBestSolutionResults(solution, problemDataClone, Results, VariableFrequencies); 99 100 } 100 101 return BestSolutionParameter.ActualValue; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs
r4415 r4468 212 212 int count = (int)((validationEnd - validationStart) * RelativeNumberOfEvaluatedSamples.Value); 213 213 if (count == 0) count = 1; 214 IEnumerable<int> rows = RandomEnumerable.SampleRandomNumbers(seed, validationStart, validationEnd, count); 214 IEnumerable<int> rows = RandomEnumerable.SampleRandomNumbers(seed, validationStart, validationEnd, count) 215 .Where(row => row < ProblemData.TestSamplesStart.Value || ProblemData.TestSamplesEnd.Value <= row); 215 216 216 217 double upperEstimationLimit = UpperEstimationLimit != null ? UpperEstimationLimit.Value : double.PositiveInfinity; … … 241 242 // calculate scaling parameters and only for the best tree using the full training set 242 243 double alpha, beta; 243 int trainingStart = ProblemData.TrainingSamplesStart.Value;244 int trainingEnd = ProblemData.TrainingSamplesEnd.Value;245 IEnumerable<int> trainingRows = Enumerable.Range(trainingStart, trainingEnd - trainingStart);246 244 SymbolicRegressionScaledMeanSquaredErrorEvaluator.Calculate(SymbolicExpressionTreeInterpreter, bestTree, 247 245 lowerEstimationLimit, upperEstimationLimit, 248 246 ProblemData.Dataset, targetVariable, 249 trainingRows, out beta, out alpha);247 ProblemData.TrainingIndizes, out beta, out alpha); 250 248 251 249 // scale tree for solution … … 253 251 var model = new SymbolicRegressionModel((ISymbolicExpressionTreeInterpreter)SymbolicExpressionTreeInterpreter.Clone(), 254 252 scaledTree); 255 var solution = new SymbolicRegressionSolution( ProblemData, model, lowerEstimationLimit, upperEstimationLimit);253 var solution = new SymbolicRegressionSolution((DataAnalysisProblemData)ProblemData.Clone(), model, lowerEstimationLimit, upperEstimationLimit); 256 254 solution.Name = BestSolutionParameterName; 257 255 solution.Description = "Best solution on validation partition found over the whole run."; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityAnalyzer.cs
r4068 r4468 137 137 Analyze(SymbolicExpressionTreeParameter.ActualValue, SymbolicExpressionTreeInterpreterParameter.ActualValue, 138 138 UpperEstimationLimit.Value, LowerEstimationLimit.Value, ProblemDataParameter.ActualValue, 139 ProblemDataParameter.ActualValue.TrainingSamplesStart.Value, ProblemDataParameter.ActualValue.TrainingSamplesEnd.Value,140 ProblemDataParameter.ActualValue.TestSamplesStart.Value, ProblemDataParameter.ActualValue.TestSamplesEnd.Value,141 139 ResultsParameter.ActualValue); 142 140 return base.Apply(); … … 145 143 public static void Analyze(IEnumerable<SymbolicExpressionTree> trees, ISymbolicExpressionTreeInterpreter interpreter, 146 144 double upperEstimationLimit, double lowerEstimationLimit, 147 DataAnalysisProblemData problemData, int trainingStart, int trainingEnd, int testStart, int testEnd,ResultCollection results) {145 DataAnalysisProblemData problemData, ResultCollection results) { 148 146 int targetVariableIndex = problemData.Dataset.GetVariableIndex(problemData.TargetVariable.Value); 149 IEnumerable<double> originalTrainingValues = problemData.Dataset.GetEnumeratedVariableValues(targetVariableIndex, trainingStart, trainingEnd);150 IEnumerable<double> originalTestValues = problemData.Dataset.GetEnumeratedVariableValues(targetVariableIndex, testStart, testEnd);147 IEnumerable<double> originalTrainingValues = problemData.Dataset.GetEnumeratedVariableValues(targetVariableIndex, problemData.TrainingIndizes); 148 IEnumerable<double> originalTestValues = problemData.Dataset.GetEnumeratedVariableValues(targetVariableIndex, problemData.TestIndizes); 151 149 List<double> trainingMse = new List<double>(); 152 150 List<double> trainingR2 = new List<double>(); … … 162 160 foreach (var tree in trees) { 163 161 #region training 164 var estimatedTrainingValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, Enumerable.Range(trainingStart, trainingEnd - trainingStart));162 var estimatedTrainingValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, problemData.TrainingIndizes); 165 163 mseEvaluator.Reset(); 166 164 r2Evaluator.Reset(); … … 184 182 #endregion 185 183 #region test 186 var estimatedTestValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, Enumerable.Range(testStart, testEnd - testStart));184 var estimatedTestValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, problemData.TestIndizes); 187 185 188 186 mseEvaluator.Reset(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityCalculator.cs
r4068 r4468 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Data; … … 35 36 [Item("SymbolicRegressionModelQualityCalculator", "An operator to calculate the quality values of a symbolic regression solution symbolic expression tree encoding.")] 36 37 [StorableClass] 38 [Obsolete("This class should not be used anymore because of performance reasons and will therefore not be updated.")] 37 39 public sealed class SymbolicRegressionModelQualityCalculator : AlgorithmOperator { 38 40 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionTournamentPruning.cs
r4191 r4468 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Parameters; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 using HeuristicLab.Problems.DataAnalysis.Symbolic; 31 32 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols; 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers { … … 241 241 double lowerEstimationLimit, double upperEstimationLimit, 242 242 double maxPruningRatio, double qualityGainWeight) { 243 IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart); 243 IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart) 244 .Where(i => i < problemData.TestSamplesStart.Value || problemData.TestSamplesEnd.Value <= i); 244 245 int originalSize = tree.Size; 245 246 double originalQuality = evaluator.Evaluate(interpreter, tree, -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/ValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs
r4068 r4468 39 39 [Item("ValidationBestScaledSymbolicRegressionSolutionAnalyzer", "An operator that analyzes the validation best scaled symbolic regression solution.")] 40 40 [StorableClass] 41 [Obsolete("This class should not be used anymore because of performance reasons and will therefore not be updated.")] 41 42 public sealed class ValidationBestScaledSymbolicRegressionSolutionAnalyzer : AlgorithmOperator, ISymbolicRegressionAnalyzer { 42 43 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/MultiObjectiveSymbolicRegressionEvaluator.cs
r4246 r4468 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 23 using System.Linq; 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; … … 122 122 public override IOperation Apply() { 123 123 int seed = Random.Next(); 124 IEnumerable<int> rows = SingleObjectiveSymbolicRegressionEvaluator.GenerateRowsToEvaluate(seed, RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value); 124 IEnumerable<int> rows = SingleObjectiveSymbolicRegressionEvaluator.GenerateRowsToEvaluate(seed, RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value) 125 .Where(i => i < RegressionProblemData.TestSamplesStart.Value || RegressionProblemData.TestSamplesEnd.Value <= i); 125 126 double[] qualities = Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset, 126 127 RegressionProblemData.TargetVariable, rows); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SingleObjectiveSymbolicRegressionEvaluator.cs
r4246 r4468 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; … … 140 141 public override IOperation Apply() { 141 142 int seed = Random.Next(); 142 IEnumerable<int> rows = GenerateRowsToEvaluate(seed, RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value); 143 IEnumerable<int> rows = GenerateRowsToEvaluate(seed, RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value) 144 .Where(i => i < RegressionProblemData.TestSamplesStart.Value || RegressionProblemData.TestSamplesEnd.Value <= i); 143 145 double quality = Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, LowerEstimationLimit.Value, UpperEstimationLimit.Value, 144 146 RegressionProblemData.Dataset, -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionModel.cs
r4415 r4468 68 68 69 69 public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, int start, int end) { 70 return interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, Enumerable.Range(start, end - start)); 70 return GetEstimatedValues(problemData, Enumerable.Range(start, end - start)); 71 } 72 public IEnumerable<double> GetEstimatedValues(DataAnalysisProblemData problemData, IEnumerable<int> rows) { 73 return interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 71 74 } 72 75 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs
r4250 r4468 170 170 fixedBestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 171 171 } 172 172 173 var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicRegressionSolutionAnalyzer; 173 174 if (bestValidationSolutionAnalyzer != null) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblemBase.cs
r4251 r4468 125 125 } 126 126 public IntValue TrainingSamplesStart { 127 get { return new IntValue(DataAnalysisProblemData.Training SamplesStart.Value); }127 get { return new IntValue(DataAnalysisProblemData.TrainingIndizes.First()); } 128 128 } 129 129 public IntValue TrainingSamplesEnd { 130 130 get { 131 return new IntValue((DataAnalysisProblemData.TrainingSamplesStart.Value +132 DataAnalysisProblemData.TrainingSamplesEnd.Value) / 2);131 int endIndex = (int)(DataAnalysisProblemData.TrainingIndizes.Count() * (1.0 - DataAnalysisProblemData.ValidationPercentage.Value)); 132 return new IntValue(DataAnalysisProblemData.TrainingIndizes.ElementAt(endIndex)); 133 133 } 134 134 } … … 137 137 } 138 138 public IntValue ValidationSamplesEnd { 139 get { return new IntValue(DataAnalysisProblemData.Training SamplesEnd.Value); }139 get { return new IntValue(DataAnalysisProblemData.TrainingIndizes.Last() + 1); } 140 140 } 141 141 public IntValue TestSamplesStart { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionSolution.cs
r4415 r4468 67 67 get { 68 68 if (estimatedValues == null) RecalculateEstimatedValues(); 69 return estimatedValues .AsEnumerable();69 return estimatedValues; 70 70 } 71 71 } 72 72 73 73 public override IEnumerable<double> EstimatedTrainingValues { 74 get { 75 if (estimatedValues == null) RecalculateEstimatedValues(); 76 int start = ProblemData.TrainingSamplesStart.Value; 77 int n = ProblemData.TrainingSamplesEnd.Value - start; 78 return estimatedValues.Skip(start).Take(n).ToList(); 79 } 74 get { return GetEstimatedValues(ProblemData.TrainingIndizes); } 80 75 } 81 76 82 77 public override IEnumerable<double> EstimatedTestValues { 83 get { 84 if (estimatedValues == null) RecalculateEstimatedValues(); 85 int start = ProblemData.TestSamplesStart.Value; 86 int n = ProblemData.TestSamplesEnd.Value - start; 87 return estimatedValues.Skip(start).Take(n).ToList(); 88 } 78 get { return GetEstimatedValues(ProblemData.TestIndizes); } 79 } 80 81 public virtual IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 82 if (estimatedValues == null) RecalculateEstimatedValues(); 83 foreach (int row in rows) 84 yield return estimatedValues[row]; 89 85 } 90 86 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ResultsView.cs
r4068 r4468 77 77 matrix.SortableView = false; 78 78 79 IEnumerable<double> originalTrainingValues = Content.ProblemData.Dataset.Get VariableValues(Content.ProblemData.TargetVariable.Value, Content.ProblemData.TrainingSamplesStart.Value, Content.ProblemData.TrainingSamplesEnd.Value);80 IEnumerable<double> originalTestValues = Content.ProblemData.Dataset.Get VariableValues(Content.ProblemData.TargetVariable.Value, Content.ProblemData.TestSamplesStart.Value, Content.ProblemData.TestSamplesEnd.Value);79 IEnumerable<double> originalTrainingValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable.Value, Content.ProblemData.TrainingIndizes); 80 IEnumerable<double> originalTestValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable.Value, Content.ProblemData.TestIndizes); 81 81 matrix[0, 0] = SimpleMSEEvaluator.Calculate(originalTrainingValues, Content.EstimatedTrainingValues); 82 82 matrix[0, 1] = SimpleMSEEvaluator.Calculate(originalTestValues, Content.EstimatedTestValues); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ScatterPlotView.cs
r4068 r4468 127 127 string targetVariableName = Content.ProblemData.TargetVariable.Value; 128 128 Dataset dataset = Content.ProblemData.Dataset; 129 int trainingStart = Content.ProblemData.TrainingSamplesStart.Value;130 int trainingEnd = Content.ProblemData.TrainingSamplesEnd.Value;131 int testStart = Content.ProblemData.TestSamplesStart.Value;132 int testEnd = Content.ProblemData.TestSamplesEnd.Value;133 129 if (this.chart.Series[ALL_SERIES].Points.Count > 0) 134 130 this.chart.Series[ALL_SERIES].Points.DataBindXY(Content.EstimatedValues.ToArray(), "", … … 136 132 if (this.chart.Series[TRAINING_SERIES].Points.Count > 0) 137 133 this.chart.Series[TRAINING_SERIES].Points.DataBindXY(Content.EstimatedTrainingValues.ToArray(), "", 138 dataset.Get VariableValues(targetVariableName, trainingStart, trainingEnd), "");134 dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray(), ""); 139 135 if (this.chart.Series[TEST_SERIES].Points.Count > 0) 140 136 this.chart.Series[TEST_SERIES].Points.DataBindXY(Content.EstimatedTestValues.ToArray(), "", 141 dataset.GetVariableValues(targetVariableName, testStart, testEnd), "");137 dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray(), ""); 142 138 143 139 double max = Math.Max(Content.EstimatedValues.Max(), dataset.GetVariableValues(targetVariableName).Max()); … … 168 164 } else if (Content != null) { 169 165 string targetVariableName = Content.ProblemData.TargetVariable.Value; 170 Dataset dataset = Content.ProblemData.Dataset;171 int trainingStart = Content.ProblemData.TrainingSamplesStart.Value;172 int trainingEnd = Content.ProblemData.TrainingSamplesEnd.Value;173 int testStart = Content.ProblemData.TestSamplesStart.Value;174 int testEnd = Content.ProblemData.TestSamplesEnd.Value;175 166 176 167 IEnumerable<double> predictedValues = null; … … 178 169 switch (series.Name) { 179 170 case ALL_SERIES: 180 predictedValues = Content.EstimatedValues ;181 targetValues = dataset.GetVariableValues(targetVariableName);171 predictedValues = Content.EstimatedValues.ToArray(); 172 targetValues = Content.ProblemData.Dataset.GetVariableValues(targetVariableName); 182 173 break; 183 174 case TRAINING_SERIES: 184 predictedValues = Content.EstimatedTrainingValues ;185 targetValues = dataset.GetVariableValues(targetVariableName, trainingStart, trainingEnd);175 predictedValues = Content.EstimatedTrainingValues.ToArray(); 176 targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray(); 186 177 break; 187 178 case TEST_SERIES: 188 predictedValues = Content.EstimatedTestValues ;189 targetValues = dataset.GetVariableValues(targetVariableName, testStart, testEnd);179 predictedValues = Content.EstimatedTestValues.ToArray(); 180 targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray(); 190 181 break; 191 182 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/DataAnalysisProblemData.cs
r4451 r4468 35 35 public class DataAnalysisProblemData : ParameterizedNamedItem, IStorableContent { 36 36 protected bool suppressEvents = false; 37 #region IStorableContent Members 38 public string Filename { get; set; } 39 #endregion 37 40 #region default data 38 41 // y = x^4 + x^3 + x^2 + x … … 87 90 get { return (IValueParameter<IntValue>)Parameters["TestSamplesEnd"]; } 88 91 } 92 public IValueParameter<PercentValue> ValidationPercentageParameter { 93 get { return (IValueParameter<PercentValue>)Parameters["ValidationPercentage"]; } 94 } 89 95 #endregion 90 96 91 97 #region properties 92 98 public Dataset Dataset { 93 get { return (Dataset)DatasetParameter.Value; }99 get { return DatasetParameter.Value; } 94 100 set { 95 101 if (value != Dataset) { … … 100 106 } 101 107 public StringValue TargetVariable { 102 get { return (StringValue)TargetVariableParameter.Value; }108 get { return TargetVariableParameter.Value; } 103 109 set { 104 110 if (value != TargetVariableParameter.Value) { … … 110 116 } 111 117 public ICheckedItemList<StringValue> InputVariables { 112 get { return (ICheckedItemList<StringValue>)InputVariablesParameter.Value; }118 get { return InputVariablesParameter.Value; } 113 119 set { 114 120 if (value != InputVariables) { … … 120 126 } 121 127 public IntValue TrainingSamplesStart { 122 get { return (IntValue)TrainingSamplesStartParameter.Value; }128 get { return TrainingSamplesStartParameter.Value; } 123 129 set { 124 130 if (value != TrainingSamplesStart) { … … 130 136 } 131 137 public IntValue TrainingSamplesEnd { 132 get { return (IntValue)TrainingSamplesEndParameter.Value; }138 get { return TrainingSamplesEndParameter.Value; } 133 139 set { 134 140 if (value != TrainingSamplesEnd) { … … 140 146 } 141 147 public IntValue TestSamplesStart { 142 get { return (IntValue)TestSamplesStartParameter.Value; }148 get { return TestSamplesStartParameter.Value; } 143 149 set { 144 150 if (value != TestSamplesStart) { … … 150 156 } 151 157 public IntValue TestSamplesEnd { 152 get { return (IntValue)TestSamplesEndParameter.Value; }158 get { return TestSamplesEndParameter.Value; } 153 159 set { 154 160 if (value != TestSamplesEnd) { … … 159 165 } 160 166 } 161 #endregion 162 163 #region IStorableContent Members 164 public string Filename { get; set; } 165 #endregion 167 public PercentValue ValidationPercentage { 168 get { return ValidationPercentageParameter.Value; } 169 set { 170 if (value != ValidationPercentage) { 171 if (value == null) throw new ArgumentNullException(); 172 if (value.Value < 0 || value.Value > 1) throw new ArgumentException("ValidationPercentage must be between 0 and 1."); 173 if (ValidationPercentage != null) DeregisterValueTypeEventHandlers(ValidationPercentage); 174 ValidationPercentageParameter.Value = value; 175 } 176 } 177 } 178 179 public IEnumerable<int> TrainingIndizes { 180 get { 181 return Enumerable.Range(TrainingSamplesStart.Value, TrainingSamplesEnd.Value - TrainingSamplesStart.Value) 182 .Where(i => i > 0 && i < Dataset.Rows && (i < TestSamplesStart.Value || TestSamplesEnd.Value <= i)); 183 } 184 } 185 public IEnumerable<int> TestIndizes { 186 get { 187 return Enumerable.Range(TestSamplesStart.Value, TestSamplesEnd.Value - TestSamplesStart.Value) 188 .Where(i => i > 0 && i < Dataset.Rows); 189 } 190 } 191 #endregion 192 166 193 167 194 public DataAnalysisProblemData() … … 180 207 Parameters.Add(new ValueParameter<IntValue>("TestSamplesStart", new IntValue(15))); 181 208 Parameters.Add(new ValueParameter<IntValue>("TestSamplesEnd", new IntValue(25))); 209 Parameters.Add(new ValueParameter<PercentValue>("ValidationPercentage", "The relative amount of the training samples that should be used as validation set.", new PercentValue(0.5))); 182 210 RegisterParameterEventHandlers(); 183 211 RegisterParameterValueEventHandlers(); … … 200 228 Parameters.Add(new ValueParameter<IntValue>("TestSamplesStart", new IntValue(testSamplesStart))); 201 229 Parameters.Add(new ValueParameter<IntValue>("TestSamplesEnd", new IntValue(testSamplesEnd))); 230 Parameters.Add(new ValueParameter<PercentValue>("ValidationPercentage", "The relative amount of the training samples that should be used as validation set.", new PercentValue(0.5))); 202 231 RegisterParameterEventHandlers(); 203 232 RegisterParameterValueEventHandlers(); … … 209 238 [StorableHook(HookType.AfterDeserialization)] 210 239 private void AfterDeserializationHook() { 240 if (!Parameters.ContainsKey("ValidationPercentage")) 241 Parameters.Add(new ValueParameter<PercentValue>("ValidationPercentage", "The relative amount of the training samples that should be used as validation set.", new PercentValue(0.5))); 242 211 243 RegisterParameterEventHandlers(); 212 244 RegisterParameterValueEventHandlers(); … … 230 262 TestSamplesStartParameter.ValueChanged += new EventHandler(TestSamplesStartParameter_ValueChanged); 231 263 TestSamplesEndParameter.ValueChanged += new EventHandler(TestSamplesEndParameter_ValueChanged); 264 ValidationPercentageParameter.ValueChanged += new EventHandler(ValidationPercentageParameter_ValueChanged); 232 265 } 233 266 … … 239 272 RegisterValueTypeEventHandlers(TestSamplesStart); 240 273 RegisterValueTypeEventHandlers(TestSamplesEnd); 274 RegisterValueTypeEventHandlers(ValidationPercentage); 241 275 } 242 276 … … 270 304 private void TestSamplesEndParameter_ValueChanged(object sender, EventArgs e) { 271 305 RegisterValueTypeEventHandlers(TestSamplesEnd); 306 OnProblemDataChanged(EventArgs.Empty); 307 } 308 private void ValidationPercentageParameter_ValueChanged(object sender, EventArgs e) { 309 RegisterValueTypeEventHandlers(ValidationPercentage); 272 310 OnProblemDataChanged(EventArgs.Empty); 273 311 }
Note: See TracChangeset
for help on using the changeset viewer.