- Timestamp:
- 05/11/11 15:56:17 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
/branches/DataAnalysis SolutionEnsembles (added) merged: 5815-5816
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis (added) merged: 5816
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r6180 r6184 75 75 throw new ArgumentException(); 76 76 } 77 78 RecalculateResults(); 79 } 80 81 private void RecalculateResults() { 82 double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values 83 var trainingIndizes = Enumerable.Range(ProblemData.TrainingPartition.Start, 84 ProblemData.TrainingPartition.End - ProblemData.TrainingPartition.Start); 85 IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, trainingIndizes); 86 double[] estimatedTestValues = EstimatedTestValues.ToArray(); // cache values 87 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 88 89 OnlineCalculatorError errorState; 90 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 91 TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN; 92 double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 93 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 94 95 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 96 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN; 97 double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 98 TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 99 100 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 101 TrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN; 102 double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 103 TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; 104 105 double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 106 TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNMSE : double.NaN; 107 double testNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 108 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN; 77 109 } 78 110 … … 83 115 public override IEnumerable<double> EstimatedTrainingValues { 84 116 get { 117 var rows = Enumerable.Range(ProblemData.TrainingPartition.Start, ProblemData.TrainingPartition.End - ProblemData.TrainingPartition.Start); 85 118 var estimatedValuesEnumerators = (from model in Model.Models 86 select new { Model = model, EstimatedValuesEnumerator = model.GetEstimatedValues(ProblemData.Dataset, ProblemData.TestIndizes).GetEnumerator() })119 select new { Model = model, EstimatedValuesEnumerator = model.GetEstimatedValues(ProblemData.Dataset, rows).GetEnumerator() }) 87 120 .ToList(); 88 var rowsEnumerator = ProblemData.TestIndizes.GetEnumerator();89 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators. All(en => en.EstimatedValuesEnumerator.MoveNext())) {121 var rowsEnumerator = rows.GetEnumerator(); 122 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators.Select(en => en.EstimatedValuesEnumerator.MoveNext()).Aggregate(true, (acc, b) => acc & b)) { 90 123 int currentRow = rowsEnumerator.Current; 91 124 92 125 var selectedEnumerators = from pair in estimatedValuesEnumerators 93 126 where trainingPartitions == null || !trainingPartitions.ContainsKey(pair.Model) || 94 (trainingPartitions[pair.Model].Start >= currentRow && trainingPartitions[pair.Model].End < currentRow)127 (trainingPartitions[pair.Model].Start <= currentRow && currentRow < trainingPartitions[pair.Model].End) 95 128 select pair.EstimatedValuesEnumerator; 96 129 yield return AggregateEstimatedValues(selectedEnumerators.Select(x => x.Current)); … … 105 138 .ToList(); 106 139 var rowsEnumerator = ProblemData.TestIndizes.GetEnumerator(); 107 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators. All(en => en.EstimatedValuesEnumerator.MoveNext())) {140 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators.Select(en => en.EstimatedValuesEnumerator.MoveNext()).Aggregate(true, (acc, b) => acc & b)) { 108 141 int currentRow = rowsEnumerator.Current; 109 142 110 143 var selectedEnumerators = from pair in estimatedValuesEnumerators 111 144 where testPartitions == null || !testPartitions.ContainsKey(pair.Model) || 112 (testPartitions[pair.Model].Start >= currentRow && testPartitions[pair.Model].End < currentRow)145 (testPartitions[pair.Model].Start <= currentRow && currentRow < testPartitions[pair.Model].End) 113 146 select pair.EstimatedValuesEnumerator; 114 147 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r5962 r6184 30 30 namespace HeuristicLab.Problems.DataAnalysis { 31 31 /// <summary> 32 /// Abstract base class for regression data analysis solutions32 /// Represents a regression data analysis solution 33 33 /// </summary> 34 34 [StorableClass] 35 public abstractclass RegressionSolution : DataAnalysisSolution, IRegressionSolution {35 public class RegressionSolution : DataAnalysisSolution, IRegressionSolution { 36 36 private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)"; 37 37 private const string TestMeanSquaredErrorResultName = "Mean squared error (test)"; … … 55 55 public double TrainingMeanSquaredError { 56 56 get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; } 57 pr ivateset { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; }57 protected set { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; } 58 58 } 59 59 60 60 public double TestMeanSquaredError { 61 61 get { return ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value; } 62 pr ivateset { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }62 protected set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; } 63 63 } 64 64 65 65 public double TrainingRSquared { 66 66 get { return ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value; } 67 pr ivateset { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; }67 protected set { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; } 68 68 } 69 69 70 70 public double TestRSquared { 71 71 get { return ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value; } 72 pr ivateset { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; }72 protected set { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; } 73 73 } 74 74 75 75 public double TrainingRelativeError { 76 76 get { return ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value; } 77 pr ivateset { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; }77 protected set { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; } 78 78 } 79 79 80 80 public double TestRelativeError { 81 81 get { return ((DoubleValue)this[TestRelativeErrorResultName].Value).Value; } 82 pr ivateset { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; }82 protected set { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; } 83 83 } 84 84 85 85 public double TrainingNormalizedMeanSquaredError { 86 86 get { return ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value; } 87 pr ivateset { ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value = value; }87 protected set { ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value = value; } 88 88 } 89 89 90 90 public double TestNormalizedMeanSquaredError { 91 91 get { return ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value; } 92 pr ivateset { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; }92 protected set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; } 93 93 } 94 94 … … 113 113 } 114 114 115 public override IDeepCloneable Clone(Cloner cloner) { 116 return new RegressionSolution(this, cloner); 117 } 118 115 119 protected override void OnProblemDataChanged(EventArgs e) { 116 120 base.OnProblemDataChanged(e); … … 122 126 } 123 127 124 pr otectedvoid RecalculateResults() {128 private void RecalculateResults() { 125 129 double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values 126 130 IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
Note: See TracChangeset
for help on using the changeset viewer.