Changeset 7562 for branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators
- Timestamp:
- 03/06/12 15:08:13 (13 years ago)
- Location:
- branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/ClassificationWeightCalculator.cs
r7559 r7562 113 113 } 114 114 115 public virtual double GetConfidence(IEnumerable<IClassificationSolution> solutions, int index, double estimatedClassValue) { 116 if (solutions.Count() < 1) 117 return double.NaN; 118 Dataset dataset = solutions.First().ProblemData.Dataset; 119 var correctSolutions = solutions.Select(s => new { Solution = s, Values = s.Model.GetEstimatedClassValues(dataset, Enumerable.Repeat(index, 1)).First() }) 120 .Where(a => a.Values.Equals(estimatedClassValue)) 121 .Select(a => a.Solution); 122 return (from sol in correctSolutions 123 select weights[sol]).Sum(); 124 } 125 115 126 #region Helper 116 127 protected IEnumerable<double> GetValues(IList<double> targetValues, IEnumerable<int> indizes) { -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/DiscriminantClassificationWeightCalculator.cs
r7559 r7562 82 82 } 83 83 } 84 85 public sealed override double GetConfidence(IEnumerable<IClassificationSolution> solutions, int index, double estimatedClassValue) { 86 if (solutions.Count() < 1 || !solutions.All(x => x is IDiscriminantFunctionClassificationSolution)) 87 return double.NaN; 88 89 IEnumerable<IDiscriminantFunctionClassificationSolution> discriminantSolutions = solutions.Cast<IDiscriminantFunctionClassificationSolution>(); 90 91 return GetDiscriminantConfidence(discriminantSolutions, index, estimatedClassValue); 92 } 93 94 protected virtual double GetDiscriminantConfidence(IEnumerable<IDiscriminantFunctionClassificationSolution> solutions, int index, double estimatedClassValue) { 95 return base.GetConfidence(solutions, index, estimatedClassValue); 96 } 84 97 } 85 98 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/MedianThresholdCalculator.cs
r7549 r7562 20 20 #endregion 21 21 22 using System.Collections; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 84 85 } 85 86 AccuracyMaximizationThresholdCalculator.CalculateThresholds(solutionProblemData[0], median, targetValues, out classValues, out threshold); 86 return median;87 return Enumerable.Repeat<double>(1, discriminantSolutions.Count()); 87 88 } 88 89 89 90 protected override double DiscriminantAggregateEstimatedClassValues(IDictionary<IClassificationSolution, double> estimatedClassValues, IDictionary<IClassificationSolution, double> estimatedValues) { 90 double classValue = classValues.First();91 91 IList<double> values = estimatedValues.Select(x => x.Value).ToList(); 92 92 if (values.Count <= 0) 93 93 return double.NaN; 94 94 double median = GetMedian(values); 95 return GetClassValueToMedian(median); 96 } 97 private double GetClassValueToMedian(double median) { 98 double classValue = classValues.First(); 95 99 for (int i = 0; i < classValues.Count(); i++) { 96 100 if (median > threshold[i]) … … 100 104 } 101 105 return classValue; 106 } 107 108 protected override double GetDiscriminantConfidence(IEnumerable<IDiscriminantFunctionClassificationSolution> solutions, int index, double estimatedClassValue) { 109 // only works with binary classification 110 if (!classValues.Count().Equals(2)) 111 return double.NaN; 112 Dataset dataset = solutions.First().ProblemData.Dataset; 113 IList<double> values = solutions.Select(s => s.Model.GetEstimatedValues(dataset, Enumerable.Repeat(index, 1)).First()).ToList(); 114 if (values.Count <= 0) 115 return double.NaN; 116 double median = GetMedian(values); 117 if (estimatedClassValue.Equals(classValues[0])) { 118 if (median < estimatedClassValue) 119 return 1; 120 else if (median >= threshold[1]) 121 return 0; 122 else { 123 double distance = threshold[1] - classValues[0]; 124 return (1 / distance) * (median - classValues[0]); 125 } 126 } else if (estimatedClassValue.Equals(classValues[1])) { 127 if (median > estimatedClassValue) 128 return 1; 129 else if (median <= threshold[1]) 130 return 0; 131 else { 132 double distance = classValues[1] - threshold[1]; 133 return (1 / distance) * (classValues[1] - median); 134 } 135 } else 136 return double.NaN; 102 137 } 103 138 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/NeighbourhoodWeightCalculator.cs
r7549 r7562 58 58 foreach (var solution in discriminantSolutions) { 59 59 estimatedValues.Add(solution.Model.GetEstimatedValues(dataSet, rows).ToList()); 60 estimatedClassValues.Add(solution.Model.GetEstimated Values(dataSet, rows).ToList());60 estimatedClassValues.Add(solution.Model.GetEstimatedClassValues(dataSet, rows).ToList()); 61 61 } 62 62
Note: See TracChangeset
for help on using the changeset viewer.