- Timestamp:
- 02/21/12 16:44:20 (13 years ago)
- Location:
- branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r7491 r7504 129 129 <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" /> 130 130 <Compile Include="Implementation\Classification\WeightCalculators\AccuracyWeightCalculator.cs" /> 131 <Compile Include="Implementation\Classification\WeightCalculators\ContinuousPointCertaintyWeightCalculator.cs" /> 131 132 <Compile Include="Implementation\Classification\WeightCalculators\NeighbourhoodWeightCalculator.cs" /> 132 133 <Compile Include="Implementation\Classification\WeightCalculators\PointCertaintyWeightCalculator.cs" /> -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r7464 r7504 68 68 if (value != null) { 69 69 weightCalculator = value; 70 weights = weights = weightCalculator.Calculate Weights(classificationSolutions);70 weights = weights = weightCalculator.CalculateNormalizedWeights(classificationSolutions); 71 71 if (!ProblemData.IsEmpty) 72 72 RecalculateResults(); … … 316 316 trainingPartitions[solution.Model] = solution.ProblemData.TrainingPartition; 317 317 testPartitions[solution.Model] = solution.ProblemData.TestPartition; 318 weights = weightCalculator.Calculate Weights(classificationSolutions);318 weights = weightCalculator.CalculateNormalizedWeights(classificationSolutions); 319 319 } 320 320 … … 324 324 trainingPartitions.Remove(solution.Model); 325 325 testPartitions.Remove(solution.Model); 326 weights = weightCalculator.Calculate Weights(classificationSolutions);326 weights = weightCalculator.CalculateNormalizedWeights(classificationSolutions); 327 327 } 328 328 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/AccuracyWeightCalculator.cs
r7464 r7504 48 48 } 49 49 50 public override IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) { 51 double sum = classificationSolutions.Select(s => s.TestAccuracy).Sum(); 52 List<double> weights = new List<double>(); 53 foreach (var item in classificationSolutions) { 54 weights.Add(item.TestAccuracy / sum); 55 } 56 return weights; 50 protected override IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) { 51 return classificationSolutions.Select(s => s.TrainingAccuracy); 57 52 } 58 53 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/MajorityVoteWeightCalculator.cs
r7459 r7504 48 48 } 49 49 50 p ublicoverride IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) {50 protected override IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) { 51 51 return Enumerable.Repeat<double>(1, classificationSolutions.Count); 52 52 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/NeighbourhoodWeightCalculator.cs
r7491 r7504 49 49 } 50 50 51 p ublicoverride IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) {51 protected override IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) { 52 52 if (classificationSolutions.Count <= 0) 53 53 return new List<double>(); … … 56 56 return Enumerable.Repeat<double>(1, classificationSolutions.Count); 57 57 58 ItemCollection<IDiscriminantFunctionClassificationSolution> discriminantSolutions = new ItemCollection<IDiscriminantFunctionClassificationSolution>();59 List<List<double>> estimatedT estValEnumerators = new List<List<double>>();60 List<List<double>> estimatedTestClassValEnumerators = new List<List<double>>();58 List<List<double>> estimatedTrainingValEnumerators = new List<List<double>>(); 59 List<List<double>> estimatedTrainingClassValEnumerators = new List<List<double>>(); 60 IDiscriminantFunctionClassificationSolution discriminantSolution; 61 61 foreach (var solution in classificationSolutions) { 62 discriminantSolution s.Add((IDiscriminantFunctionClassificationSolution)solution);63 estimatedT estValEnumerators.Add(discriminantSolutions.Last().EstimatedTestValues.ToList());64 estimatedT estClassValEnumerators.Add(discriminantSolutions.Last().EstimatedTestClassValues.ToList());62 discriminantSolution = (IDiscriminantFunctionClassificationSolution)solution; 63 estimatedTrainingValEnumerators.Add(discriminantSolution.EstimatedTrainingValues.ToList()); 64 estimatedTrainingClassValEnumerators.Add(discriminantSolution.EstimatedTrainingClassValues.ToList()); 65 65 } 66 66 … … 68 68 69 69 IClassificationProblemData problemData = classificationSolutions.ElementAt(0).ProblemData; 70 IList<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList();71 List<double> t estVal = GetValues(targetValues, problemData.TestIndizes).ToList();70 List<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList(); 71 List<double> trainingVal = GetValues(targetValues, problemData.TrainingIndizes).ToList(); 72 72 73 73 double pointAvg, help; 74 74 int count; 75 for (int point = 0; point < estimatedT estClassValEnumerators.First().Count; point++) {75 for (int point = 0; point < estimatedTrainingClassValEnumerators.First().Count; point++) { 76 76 pointAvg = 0.0; 77 77 count = 0; 78 for (int solution = 0; solution < estimatedT estClassValEnumerators.Count; solution++) {79 if (estimatedT estClassValEnumerators[solution][point].Equals(testVal[point])) {80 pointAvg += estimatedT estValEnumerators[solution][point];78 for (int solution = 0; solution < estimatedTrainingClassValEnumerators.Count; solution++) { 79 if (estimatedTrainingClassValEnumerators[solution][point].Equals(targetValues[point])) { 80 pointAvg += estimatedTrainingValEnumerators[solution][point]; 81 81 count++; 82 82 } 83 83 } 84 84 pointAvg /= (double)count; 85 for (int solution = 0; solution < estimatedT estClassValEnumerators.Count; solution++) {86 if (estimatedT estClassValEnumerators[solution][point].Equals(testVal[point])) {85 for (int solution = 0; solution < estimatedTrainingClassValEnumerators.Count; solution++) { 86 if (estimatedTrainingClassValEnumerators[solution][point].Equals(targetValues[point])) { 87 87 weights[solution] += 0.5; 88 help = Math.Abs(estimatedT estValEnumerators[solution][point] - 0.5);88 help = Math.Abs(estimatedTrainingValEnumerators[solution][point] - 0.5); 89 89 weights[solution] += help < 0.5 ? 0.5 - help : 0.0; 90 90 } 91 91 } 92 92 } 93 return weights .Select(x => x / weights.Sum());93 return weights; 94 94 } 95 95 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/PointCertaintyWeightCalculator.cs
r7491 r7504 49 49 } 50 50 51 p ublicoverride IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) {51 protected override IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions) { 52 52 if (classificationSolutions.Count <= 0) 53 53 return new List<double>(); … … 62 62 63 63 List<double> weights = new List<double>(); 64 65 64 IClassificationProblemData problemData = classificationSolutions.ElementAt(0).ProblemData; 66 IList<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList(); 67 IEnumerator<double> testVal; 68 65 IEnumerable<double> targetValues = GetValues(problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList(), problemData.TrainingIndizes); 66 IEnumerator<double> trainingValues; 69 67 double avg = problemData.ClassValues.Average(); 70 68 71 69 foreach (var solution in discriminantSolutions) { 72 IEnumerator<double> estimatedT est = solution.EstimatedTestValues.GetEnumerator();73 IEnumerator<double> estimatedT estClass = solution.EstimatedTestClassValues.GetEnumerator();70 IEnumerator<double> estimatedTrainingVal = solution.EstimatedTrainingValues.GetEnumerator(); 71 IEnumerator<double> estimatedTrainingClassVal = solution.EstimatedTrainingClassValues.GetEnumerator(); 74 72 75 t estVal = GetValues(targetValues, problemData.TestIndizes).GetEnumerator();73 trainingValues = targetValues.GetEnumerator(); 76 74 double curWeight = 0.0; 77 while (estimatedT est.MoveNext() && estimatedTestClass.MoveNext() && testVal.MoveNext()) {78 if (estimatedT estClass.Current.Equals(testVal.Current)) {75 while (estimatedTrainingVal.MoveNext() && estimatedTrainingClassVal.MoveNext() && trainingValues.MoveNext()) { 76 if (estimatedTrainingClassVal.Current.Equals(trainingValues.Current)) { 79 77 curWeight += 0.5; 80 double distanceToPoint = Math.Abs(estimatedT est.Current - avg);81 double distanceToClass = Math.Abs(t estVal.Current - avg);82 if (t estVal.Current > avg && estimatedTest.Current > avg83 || t estVal.Current < avg && estimatedTest.Current < avg)78 double distanceToPoint = Math.Abs(estimatedTrainingVal.Current - avg); 79 double distanceToClass = Math.Abs(trainingValues.Current - avg); 80 if (trainingValues.Current > avg && estimatedTrainingVal.Current > avg 81 || trainingValues.Current < avg && estimatedTrainingVal.Current < avg) 84 82 curWeight += distanceToPoint < distanceToClass ? (0.5 / distanceToClass) * distanceToPoint : 0.5; 85 83 } … … 87 85 weights.Add(curWeight); 88 86 } 89 return weights .Select(x => x / weights.Sum());87 return weights; 90 88 } 91 89 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/WeightCalculator.cs
r7459 r7504 21 21 22 22 using System.Collections.Generic; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 43 44 } 44 45 45 abstract public IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions); 46 /// <summary> 47 /// calls CalculateWeights and removes negative weights 48 /// </summary> 49 /// <param name="classificationSolutions"></param> 50 /// <returns>weights which are equal or bigger than zero</returns> 51 public IEnumerable<double> CalculateNormalizedWeights(ItemCollection<IClassificationSolution> classificationSolutions) { 52 List<double> weights = new List<double>(); 53 foreach (var weight in CalculateWeights(classificationSolutions)) { 54 weights.Add(weight >= 0 ? weight : 0); 55 } 56 return weights.Select(x => x / weights.Sum()); 57 } 58 59 protected abstract IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions); 46 60 } 47 61 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleSolutionWeightCalculator.cs
r7464 r7504 25 25 namespace HeuristicLab.Problems.DataAnalysis.Interfaces.Classification { 26 26 public interface IClassificationEnsembleSolutionWeightCalculator : INamedItem { 27 IEnumerable<double> Calculate Weights(ItemCollection<IClassificationSolution> classificationSolutions);27 IEnumerable<double> CalculateNormalizedWeights(ItemCollection<IClassificationSolution> classificationSolutions); 28 28 } 29 29 }
Note: See TracChangeset
for help on using the changeset viewer.