- Timestamp:
- 05/20/11 15:07:45 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r6184 r6238 51 51 } 52 52 public RegressionEnsembleSolution(IEnumerable<IRegressionModel> models, IRegressionProblemData problemData) 53 : base(new RegressionEnsembleModel(models), problemData) {53 : base(new RegressionEnsembleModel(models), new RegressionEnsembleProblemData(problemData)) { 54 54 trainingPartitions = new Dictionary<IRegressionModel, IntRange>(); 55 55 testPartitions = new Dictionary<IRegressionModel, IntRange>(); … … 62 62 63 63 public RegressionEnsembleSolution(IEnumerable<IRegressionModel> models, IRegressionProblemData problemData, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions) 64 : base(new RegressionEnsembleModel(models), problemData) {64 : base(new RegressionEnsembleModel(models), new RegressionEnsembleProblemData(problemData)) { 65 65 this.trainingPartitions = new Dictionary<IRegressionModel, IntRange>(); 66 66 this.testPartitions = new Dictionary<IRegressionModel, IntRange>(); … … 75 75 throw new ArgumentException(); 76 76 } 77 78 77 RecalculateResults(); 79 }80 81 private void RecalculateResults() {82 double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values83 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 values87 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;109 78 } 110 79 … … 115 84 public override IEnumerable<double> EstimatedTrainingValues { 116 85 get { 117 var rows = Enumerable.Range(ProblemData.TrainingPartition.Start, ProblemData.TrainingPartition.End - ProblemData.TrainingPartition.Start);86 var rows = ProblemData.TrainingIndizes; 118 87 var estimatedValuesEnumerators = (from model in Model.Models 119 88 select new { Model = model, EstimatedValuesEnumerator = model.GetEstimatedValues(ProblemData.Dataset, rows).GetEnumerator() }) 120 89 .ToList(); 121 90 var rowsEnumerator = rows.GetEnumerator(); 91 // aggregate to make sure that MoveNext is called for all enumerators 122 92 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators.Select(en => en.EstimatedValuesEnumerator.MoveNext()).Aggregate(true, (acc, b) => acc & b)) { 123 93 int currentRow = rowsEnumerator.Current; … … 134 104 public override IEnumerable<double> EstimatedTestValues { 135 105 get { 106 var rows = ProblemData.TestIndizes; 136 107 var estimatedValuesEnumerators = (from model in Model.Models 137 select new { Model = model, EstimatedValuesEnumerator = model.GetEstimatedValues(ProblemData.Dataset, ProblemData.TestIndizes).GetEnumerator() })108 select new { Model = model, EstimatedValuesEnumerator = model.GetEstimatedValues(ProblemData.Dataset, rows).GetEnumerator() }) 138 109 .ToList(); 139 110 var rowsEnumerator = ProblemData.TestIndizes.GetEnumerator(); 111 // aggregate to make sure that MoveNext is called for all enumerators 140 112 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators.Select(en => en.EstimatedValuesEnumerator.MoveNext()).Aggregate(true, (acc, b) => acc & b)) { 141 113 int currentRow = rowsEnumerator.Current; … … 168 140 169 141 private double AggregateEstimatedValues(IEnumerable<double> estimatedValues) { 170 return estimatedValues. Average();142 return estimatedValues.DefaultIfEmpty(double.NaN).Average(); 171 143 } 172 144 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r5809 r6238 33 33 [StorableClass] 34 34 [Item("RegressionProblemData", "Represents an item containing all data defining a regression problem.")] 35 public sealedclass RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData {35 public class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData { 36 36 private const string TargetVariableParameterName = "TargetVariable"; 37 37 … … 85 85 86 86 [StorableConstructor] 87 pr ivateRegressionProblemData(bool deserializing) : base(deserializing) { }87 protected RegressionProblemData(bool deserializing) : base(deserializing) { } 88 88 [StorableHook(HookType.AfterDeserialization)] 89 89 private void AfterDeserialization() { … … 92 92 93 93 94 pr ivateRegressionProblemData(RegressionProblemData original, Cloner cloner)94 protected RegressionProblemData(RegressionProblemData original, Cloner cloner) 95 95 : base(original, cloner) { 96 96 RegisterParameterEvents(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r6184 r6238 55 55 public double TrainingMeanSquaredError { 56 56 get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; } 57 pr otectedset { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; }57 private 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 otectedset { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }62 private 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 otectedset { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; }67 private 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 otectedset { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; }72 private 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 otectedset { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; }77 private 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 otectedset { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; }82 private 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 otectedset { ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value = value; }87 private 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 otectedset { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; }92 private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; } 93 93 } 94 94 … … 126 126 } 127 127 128 pr ivatevoid RecalculateResults() {128 protected void RecalculateResults() { 129 129 double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values 130 130 IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
Note: See TracChangeset
for help on using the changeset viewer.