Changeset 8534 for branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Timestamp:
- 08/28/12 16:13:02 (12 years ago)
- Location:
- branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis merged: 8528,8531
- Property svn:mergeinfo changed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r7259 r8534 95 95 96 96 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) { 97 return new ClassificationEnsembleSolution(models, problemData);97 return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData)); 98 98 } 99 99 #endregion -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r8508 r8534 114 114 } 115 115 116 public ClassificationEnsembleSolution(IClassificationProblemData problemData) : 117 this(Enumerable.Empty<IClassificationModel>(), problemData) { } 118 116 119 public ClassificationEnsembleSolution(IEnumerable<IClassificationModel> models, IClassificationProblemData problemData) 117 120 : this(models, problemData, -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r8508 r8534 277 277 278 278 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { } 279 280 public ClassificationProblemData(IClassificationProblemData classificationProblemData) 281 : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) { 282 TrainingPartition.Start = classificationProblemData.TrainingPartition.Start; 283 TrainingPartition.End = classificationProblemData.TrainingPartition.End; 284 TestPartition.Start = classificationProblemData.TestPartition.Start; 285 TestPartition.End = classificationProblemData.TestPartition.End; 286 } 287 279 288 public ClassificationProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable) 280 289 : base(dataset, allowedInputVariables) { -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs
r8508 r8534 51 51 valueEvaluationCache = new Dictionary<int, double>(); 52 52 classValueEvaluationCache = new Dictionary<int, double>(); 53 54 SetAccuracyMaximizingThresholds();55 53 } 56 54 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r8508 r8534 96 96 protected override void OnModelChanged() { 97 97 DeregisterEventHandler(); 98 SetAccuracyMaximizingThresholds();99 98 RegisterEventHandler(); 100 99 base.OnModelChanged(); … … 137 136 } 138 137 139 public void SetAccuracyMaximizingThresholds() {140 double[] classValues;141 double[] thresholds;142 var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);143 AccuracyMaximizationThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);144 145 Model.SetThresholdsAndClassValues(thresholds, classValues);146 }147 148 public void SetClassDistibutionCutPointThresholds() {149 double[] classValues;150 double[] thresholds;151 var targetClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices);152 NormalDistributionCutPointsThresholdCalculator.CalculateThresholds(ProblemData, EstimatedTrainingValues, targetClassValues, out classValues, out thresholds);153 154 Model.SetThresholdsAndClassValues(thresholds, classValues);155 }156 157 138 protected virtual void OnModelThresholdsChanged(EventArgs e) { 158 139 CalculateResults(); -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/AverageThresholdCalculator.cs
r8297 r8534 58 58 59 59 protected override double GetDiscriminantConfidence(IEnumerable<IDiscriminantFunctionClassificationSolution> solutions, int index, double estimatedClassValue) { 60 // only works with binary classification61 if (!classValues.Count().Equals(2))62 return double.NaN;63 60 Dataset dataset = solutions.First().ProblemData.Dataset; 64 61 IList<double> values = solutions.Select(s => s.Model.GetEstimatedValues(dataset, Enumerable.Repeat(index, 1)).First()).ToList(); … … 70 67 71 68 public override IEnumerable<double> GetDiscriminantConfidence(IEnumerable<IDiscriminantFunctionClassificationSolution> solutions, IEnumerable<int> indices, IEnumerable<double> estimatedClassValue) { 72 if (!classValues.Count().Equals(2))73 return Enumerable.Repeat(double.NaN, indices.Count());74 75 69 Dataset dataset = solutions.First().ProblemData.Dataset; 76 70 double[][] values = solutions.Select(s => s.Model.GetEstimatedValues(dataset, indices).ToArray()).ToArray(); … … 87 81 88 82 protected double GetAverageConfidence(double avg, double estimatedClassValue) { 89 if (estimatedClassValue.Equals(classValues[0])) { 90 if (avg < estimatedClassValue) 91 return 1; 92 else if (avg >= threshold[1]) 93 return 0; 94 else { 95 double distance = threshold[1] - classValues[0]; 96 return (1 / distance) * (threshold[1] - avg); 83 for (int i = 0; i < classValues.Length; i++) { 84 if (estimatedClassValue.Equals(classValues[i])) { 85 //special case: avgerage is higher than value of highest class 86 if (i == classValues.Length - 1 && avg > estimatedClassValue) { 87 return 1; 88 } 89 //special case: average is lower than value of lowest class 90 if (i == 0 && avg < estimatedClassValue) { 91 return 1; 92 } 93 //special case: average is not between threshold of estimated class value 94 if ((i < classValues.Length - 1 && avg >= threshold[i + 1]) || avg <= threshold[i]) { 95 return 0; 96 } 97 98 double thresholdToClassDistance, thresholdToAverageValueDistance; 99 if (avg >= classValues[i]) { 100 thresholdToClassDistance = threshold[i + 1] - classValues[i]; 101 thresholdToAverageValueDistance = threshold[i + 1] - avg; 102 } else { 103 thresholdToClassDistance = classValues[i] - threshold[i]; 104 thresholdToAverageValueDistance = avg - threshold[i]; 105 } 106 return (1 / thresholdToClassDistance) * thresholdToAverageValueDistance; 97 107 } 98 } else if (estimatedClassValue.Equals(classValues[1])) { 99 if (avg > estimatedClassValue) 100 return 1; 101 else if (avg <= threshold[1]) 102 return 0; 103 else { 104 double distance = classValues[1] - threshold[1]; 105 return (1 / distance) * (avg - threshold[1]); 106 } 107 } else 108 return double.NaN; 108 } 109 return double.NaN; 109 110 } 110 111 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/MedianThresholdCalculator.cs
r8297 r8534 58 58 59 59 protected override double GetDiscriminantConfidence(IEnumerable<IDiscriminantFunctionClassificationSolution> solutions, int index, double estimatedClassValue) { 60 // only works with binary classification 61 if (!classValues.Count().Equals(2)) 62 return double.NaN; 60 63 61 Dataset dataset = solutions.First().ProblemData.Dataset; 64 62 IList<double> values = solutions.Select(s => s.Model.GetEstimatedValues(dataset, Enumerable.Repeat(index, 1)).First()).ToList(); … … 70 68 71 69 public override IEnumerable<double> GetDiscriminantConfidence(IEnumerable<IDiscriminantFunctionClassificationSolution> solutions, IEnumerable<int> indices, IEnumerable<double> estimatedClassValue) { 72 if (!classValues.Count().Equals(2))73 return Enumerable.Repeat(double.NaN, indices.Count());74 70 75 71 Dataset dataset = solutions.First().ProblemData.Dataset; … … 87 83 88 84 protected double GetMedianConfidence(double median, double estimatedClassValue) { 89 if (estimatedClassValue.Equals(classValues[0])) { 90 if (median < estimatedClassValue) 91 return 1; 92 else if (median >= threshold[1]) 93 return 0; 94 else { 95 double distance = threshold[1] - classValues[0]; 96 return (1 / distance) * (threshold[1] - median); 85 for (int i = 0; i < classValues.Length; i++) { 86 if (estimatedClassValue.Equals(classValues[i])) { 87 //special case: avgerage is higher than value of highest class 88 if (i == classValues.Length - 1 && median > estimatedClassValue) { 89 return 1; 90 } 91 //special case: average is lower than value of lowest class 92 if (i == 0 && median < estimatedClassValue) { 93 return 1; 94 } 95 //special case: average is not between threshold of estimated class value 96 if ((i < classValues.Length - 1 && median >= threshold[i + 1]) || median <= threshold[i]) { 97 return 0; 98 } 99 100 double thresholdToClassDistance, thresholdToAverageValueDistance; 101 if (median >= classValues[i]) { 102 thresholdToClassDistance = threshold[i + 1] - classValues[i]; 103 thresholdToAverageValueDistance = threshold[i + 1] - median; 104 } else { 105 thresholdToClassDistance = classValues[i] - threshold[i]; 106 thresholdToAverageValueDistance = median - threshold[i]; 107 } 108 return (1 / thresholdToClassDistance) * thresholdToAverageValueDistance; 97 109 } 98 } else if (estimatedClassValue.Equals(classValues[1])) { 99 if (median > estimatedClassValue) 100 return 1; 101 else if (median <= threshold[1]) 102 return 0; 103 else { 104 double distance = classValues[1] - threshold[1]; 105 return (1 / distance) * (median - threshold[1]); 106 } 107 } else 108 return double.NaN; 110 } 111 return double.NaN; 109 112 } 110 113 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r7259 r8534 55 55 56 56 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 57 return new ConstantRegressionSolution(this, problemData);57 return new ConstantRegressionSolution(this, new RegressionProblemData(problemData)); 58 58 } 59 59 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r7259 r8534 102 102 103 103 public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) { 104 return new RegressionEnsembleSolution(this.Models, problemData);104 return new RegressionEnsembleSolution(this.Models, new RegressionEnsembleProblemData(problemData)); 105 105 } 106 106 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) { -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r8508 r8534 121 121 : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { 122 122 } 123 public RegressionProblemData(IRegressionProblemData regressionProblemData) 124 : this(regressionProblemData.Dataset, regressionProblemData.AllowedInputVariables, regressionProblemData.TargetVariable) { 125 TrainingPartition.Start = regressionProblemData.TrainingPartition.Start; 126 TrainingPartition.End = regressionProblemData.TrainingPartition.End; 127 TestPartition.Start = regressionProblemData.TestPartition.Start; 128 TestPartition.End = regressionProblemData.TestPartition.End; 129 } 123 130 124 131 public RegressionProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable)
Note: See TracChangeset
for help on using the changeset viewer.