- Timestamp:
- 02/07/12 16:50:35 (13 years ago)
- Location:
- branches/ClassificationEnsembleVoting
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs
r7259 r7464 102 102 List<List<double?>> estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indizes, 103 103 Content.ClassificationSolutions); 104 List<double> weights = Content.Weights.ToList(); 105 double weightSum = weights.Sum(); 104 106 105 107 for (int i = 0; i < indizes.Length; i++) { … … 111 113 values[i, 2] = estimatedClassValues[i].ToString(); 112 114 values[i, 3] = (target[i].IsAlmost(estimatedClassValues[i])).ToString(); 115 116 IEnumerable<int> indices = FindAllIndices(estimatedValuesVector[i], estimatedClassValues[i]); 117 double confidence = 0.0; 118 foreach (var index in indices) { 119 confidence += weights[index]; 120 } 121 values[i, 4] = (confidence / weightSum).ToString(); 122 //var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum(); 123 //values[i, 4] = 124 // (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString(); 125 113 126 var groups = 114 127 estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList(); 115 var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum();116 values[i, 4] =117 (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();118 128 for (int classIndex = 0; classIndex < Content.ProblemData.ClassValues.Count; classIndex++) { 119 129 var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues[classIndex]).SingleOrDefault(); … … 136 146 matrix.SortableView = true; 137 147 matrixView.Content = matrix; 148 } 149 150 private IEnumerable<int> FindAllIndices(List<double?> list, double value) { 151 List<int> indices = new List<int>(); 152 for (int i = 0; i < list.Count; i++) { 153 if (list[i].Equals(value)) 154 indices.Add(i); 155 } 156 return indices; 138 157 } 139 158 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClassificationEnsembleSolutionView.Designer.cs
r7259 r7464 44 44 /// </summary> 45 45 private void InitializeComponent() { 46 components = new System.ComponentModel.Container(); 46 this.cmbWeightCalculator = new System.Windows.Forms.ComboBox(); 47 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 48 this.splitContainer.Panel1.SuspendLayout(); 49 this.splitContainer.Panel2.SuspendLayout(); 50 this.splitContainer.SuspendLayout(); 51 this.itemsGroupBox.SuspendLayout(); 52 this.detailsGroupBox.SuspendLayout(); 53 this.SuspendLayout(); 54 // 55 // splitContainer 56 // 57 // 58 // splitContainer.Panel2 59 // 60 this.splitContainer.Panel2.Controls.Add(this.cmbWeightCalculator); 61 // 62 // addButton 63 // 64 this.toolTip.SetToolTip(this.addButton, "Add"); 65 // 66 // removeButton 67 // 68 this.toolTip.SetToolTip(this.removeButton, "Remove"); 69 // 70 // cmbWeightCalculator 71 // 72 this.cmbWeightCalculator.FormattingEnabled = true; 73 this.cmbWeightCalculator.Location = new System.Drawing.Point(9, 6); 74 this.cmbWeightCalculator.Name = "cmbWeightCalculator"; 75 this.cmbWeightCalculator.Size = new System.Drawing.Size(180, 21); 76 this.cmbWeightCalculator.TabIndex = 1; 77 this.cmbWeightCalculator.SelectedIndexChanged += new System.EventHandler(this.cmbWeightCalculator_SelectedIndexChanged); 78 // 79 // ClassificationEnsembleSolutionView 80 // 81 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 47 82 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 83 this.Name = "ClassificationEnsembleSolutionView"; 84 this.splitContainer.Panel1.ResumeLayout(false); 85 this.splitContainer.Panel2.ResumeLayout(false); 86 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); 87 this.splitContainer.ResumeLayout(false); 88 this.itemsGroupBox.ResumeLayout(false); 89 this.detailsGroupBox.ResumeLayout(false); 90 this.ResumeLayout(false); 91 48 92 } 49 93 50 94 #endregion 95 96 private System.Windows.Forms.ComboBox cmbWeightCalculator; 51 97 } 52 98 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClassificationEnsembleSolutionView.cs
r7259 r7464 20 20 #endregion 21 21 22 using System.Linq; 22 23 using System.Windows.Forms; 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; 24 26 using HeuristicLab.MainForm; 27 using HeuristicLab.PluginInfrastructure; 28 using HeuristicLab.Problems.DataAnalysis.Interfaces.Classification; 25 29 26 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 37 41 } 38 42 43 protected override void SetEnabledStateOfControls() { 44 base.SetEnabledStateOfControls(); 45 cmbWeightCalculator.Enabled = !Locked && !ReadOnly && Content != null; 46 } 47 39 48 protected override void OnContentChanged() { 40 49 base.OnContentChanged(); 41 50 itemsListView.Items.Remove(itemsListView.FindItemWithText("Model: ClassificationEnsembleModel")); 51 if (cmbWeightCalculator.Items.Count == 0) { 52 cmbWeightCalculator.Items.AddRange(ApplicationManager.Manager.GetInstances<IClassificationEnsembleSolutionWeightCalculator>().OrderBy(b => b.Name, new NaturalStringComparer()).ToArray()); 53 if (cmbWeightCalculator.Items.Count > 0) 54 cmbWeightCalculator.SelectedIndex = 0; 55 } else { 56 Content.WeightCalculator = (IClassificationEnsembleSolutionWeightCalculator)cmbWeightCalculator.SelectedItem; 57 } 58 } 59 60 private void cmbWeightCalculator_SelectedIndexChanged(object sender, System.EventArgs e) { 61 if (cmbWeightCalculator.SelectedItem != null) 62 Content.WeightCalculator = (IClassificationEnsembleSolutionWeightCalculator)cmbWeightCalculator.SelectedItem; 42 63 } 43 64 -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DiscriminantFunctionClassificationSolutionView.cs
r7259 r7464 24 24 namespace HeuristicLab.Problems.DataAnalysis.Views { 25 25 [View("ClassificationSolution View")] 26 [Content(typeof(DiscriminantFunctionClassificationSolutionBase), false)]26 [Content(typeof(DiscriminantFunctionClassificationSolutionBase), true)] 27 27 public partial class DiscriminantFunctionClassificationSolutionView : ClassificationSolutionView { 28 28 public DiscriminantFunctionClassificationSolutionView() { -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r7459 r7464 129 129 <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" /> 130 130 <Compile Include="Implementation\Classification\WeightCalculators\AccuracyWeightCalculator.cs" /> 131 <Compile Include="Implementation\Classification\WeightCalculators\AdaBoostWeightCalculator.cs" /> 131 132 <Compile Include="Implementation\Classification\WeightCalculators\MajorityVoteWeightCalculator.cs" /> 132 133 <Compile Include="Implementation\Classification\WeightCalculators\WeightCalculator.cs" /> -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r7459 r7464 51 51 } 52 52 53 public IEnumerable<double> Weights { 54 get { return new List<double>(weights); } 55 } 56 53 57 [Storable] 54 58 private Dictionary<IClassificationModel, IntRange> trainingPartitions; … … 56 60 private Dictionary<IClassificationModel, IntRange> testPartitions; 57 61 62 private IEnumerable<double> weights; 63 58 64 private IClassificationEnsembleSolutionWeightCalculator weightCalculator; 65 66 public IClassificationEnsembleSolutionWeightCalculator WeightCalculator { 67 set { 68 if (value != null) { 69 weightCalculator = value; 70 weights = weights = weightCalculator.CalculateWeights(classificationSolutions); 71 if (!ProblemData.IsEmpty) 72 RecalculateResults(); 73 } 74 } 75 } 59 76 60 77 [StorableConstructor] … … 98 115 classificationSolutions = new ItemCollection<IClassificationSolution>(); 99 116 100 weightCalculator = new AccuracyWeightCalculator();117 weightCalculator = new MajorityVoteWeightCalculator(); 101 118 102 119 RegisterClassificationSolutionsEventHandler(); … … 158 175 .ToList(); 159 176 var rowsEnumerator = rows.GetEnumerator(); 160 IEnumerable<double> weights = weightCalculator.CalculateWeights(classificationSolutions);161 177 // aggregate to make sure that MoveNext is called for all enumerators 162 178 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators.Select(en => en.EstimatedValuesEnumerator.MoveNext()).Aggregate(true, (acc, b) => acc & b)) { … … 178 194 .ToList(); 179 195 var rowsEnumerator = ProblemData.TestIndizes.GetEnumerator(); 180 IEnumerable<double> weights = weightCalculator.CalculateWeights(classificationSolutions);181 196 // aggregate to make sure that MoveNext is called for all enumerators 182 197 while (rowsEnumerator.MoveNext() & estimatedValuesEnumerators.Select(en => en.EstimatedValuesEnumerator.MoveNext()).Aggregate(true, (acc, b) => acc & b)) { … … 203 218 204 219 public override IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows) { 205 IEnumerable<double> weights = weightCalculator.CalculateWeights(classificationSolutions);206 220 return from xs in GetEstimatedClassValueVectors(ProblemData.Dataset, rows) 207 221 select AggregateEstimatedClassValues(xs, weights); … … 302 316 trainingPartitions[solution.Model] = solution.ProblemData.TrainingPartition; 303 317 testPartitions[solution.Model] = solution.ProblemData.TestPartition; 318 weights = weightCalculator.CalculateWeights(classificationSolutions); 304 319 } 305 320 … … 309 324 trainingPartitions.Remove(solution.Model); 310 325 testPartitions.Remove(solution.Model); 326 weights = weightCalculator.CalculateWeights(classificationSolutions); 311 327 } 312 328 } -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/WeightCalculators/AccuracyWeightCalculator.cs
r7459 r7464 28 28 namespace HeuristicLab.Problems.DataAnalysis { 29 29 /// <summary> 30 /// Represents a weight calculator that gives every classification solution a weight based on the accuracy. .30 /// Represents a weight calculator that gives every classification solution a weight based on the accuracy. 31 31 /// </summary> 32 32 [StorableClass] -
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationEnsembleSolutionWeightCalculator.cs
r7459 r7464 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis.Interfaces.Classification { 26 public interface IClassificationEnsembleSolutionWeightCalculator {26 public interface IClassificationEnsembleSolutionWeightCalculator : INamedItem { 27 27 IEnumerable<double> CalculateWeights(ItemCollection<IClassificationSolution> classificationSolutions); 28 28 }
Note: See TracChangeset
for help on using the changeset viewer.