Changeset 9135 for branches/ClassificationModelComparison
- Timestamp:
- 01/09/13 16:27:12 (12 years ago)
- Location:
- branches/ClassificationModelComparison
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/OneRClassificationModelView.Designer.cs
r9119 r9135 46 46 private void InitializeComponent() { 47 47 this.dataGridView = new System.Windows.Forms.DataGridView(); 48 this.variableLabel = new System.Windows.Forms.Label();49 48 this.intervalstart = new System.Windows.Forms.DataGridViewTextBoxColumn(); 50 49 this.intervalend = new System.Windows.Forms.DataGridViewTextBoxColumn(); 51 50 this.classcolumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); 51 this.variableLabel = new System.Windows.Forms.Label(); 52 this.MissingValuesClassLabel = new System.Windows.Forms.Label(); 52 53 ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); 53 54 this.SuspendLayout(); … … 68 69 this.dataGridView.Name = "dataGridView"; 69 70 this.dataGridView.ReadOnly = true; 70 this.dataGridView.Size = new System.Drawing.Size(3 61, 196);71 this.dataGridView.Size = new System.Drawing.Size(389, 230); 71 72 this.dataGridView.TabIndex = 0; 72 //73 // variableLabel74 //75 this.variableLabel.AutoSize = true;76 this.variableLabel.Location = new System.Drawing.Point(3, 10);77 this.variableLabel.Name = "variableLabel";78 this.variableLabel.Size = new System.Drawing.Size(48, 13);79 this.variableLabel.TabIndex = 1;80 this.variableLabel.Text = "Variable:";81 73 // 82 74 // intervalstart … … 98 90 this.classcolumn.ReadOnly = true; 99 91 // 92 // variableLabel 93 // 94 this.variableLabel.AutoSize = true; 95 this.variableLabel.Location = new System.Drawing.Point(3, 10); 96 this.variableLabel.Name = "variableLabel"; 97 this.variableLabel.Size = new System.Drawing.Size(48, 13); 98 this.variableLabel.TabIndex = 1; 99 this.variableLabel.Text = "Variable:"; 100 // 101 // MissingValuesClassLabel 102 // 103 this.MissingValuesClassLabel.Anchor = System.Windows.Forms.AnchorStyles.Top; 104 this.MissingValuesClassLabel.AutoSize = true; 105 this.MissingValuesClassLabel.Location = new System.Drawing.Point(165, 10); 106 this.MissingValuesClassLabel.Name = "MissingValuesClassLabel"; 107 this.MissingValuesClassLabel.Size = new System.Drawing.Size(118, 13); 108 this.MissingValuesClassLabel.TabIndex = 2; 109 this.MissingValuesClassLabel.Text = "Class of missing values:"; 110 // 100 111 // OneRClassificationModelView 101 112 // 102 113 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 103 114 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 115 this.Controls.Add(this.MissingValuesClassLabel); 104 116 this.Controls.Add(this.variableLabel); 105 117 this.Controls.Add(this.dataGridView); 106 118 this.Name = "OneRClassificationModelView"; 107 this.Size = new System.Drawing.Size(3 67, 231);119 this.Size = new System.Drawing.Size(395, 265); 108 120 ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); 109 121 this.ResumeLayout(false); … … 119 131 private System.Windows.Forms.DataGridViewTextBoxColumn intervalend; 120 132 private System.Windows.Forms.DataGridViewTextBoxColumn classcolumn; 133 private System.Windows.Forms.Label MissingValuesClassLabel; 121 134 } 122 135 } -
branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/OneRClassificationModelView.cs
r9119 r9135 49 49 if (Content == null) { 50 50 variableLabel.Text = "Variable: "; 51 MissingValuesClassLabel.Text = "Class of missing values: "; 51 52 dataGridView.Rows.Clear(); 52 53 } else { 53 54 variableLabel.Text = "Variable: " + Content.Variable; 55 MissingValuesClassLabel.Text = "Class of missing values: " + Content.MissingValuesClass; 54 56 55 57 dataGridView.RowCount = Content.Classes.Length; -
branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/OneR.cs
r9119 r9135 84 84 string bestVariable = null; 85 85 Dictionary<double, double> bestSplits = null; 86 double missingValuesClass = double.NaN; 86 87 int correctClassified = 0; 87 88 … … 98 99 bool done = false; 99 100 int curRow = 0; 101 102 if (curRow < inputVariableValues.Length && Double.IsNaN(inputVariableValues[curRow])) { 103 while (curRow < inputVariableValues.Length && Double.IsNaN(inputVariableValues[curRow])) { 104 classCount[classValuesInDataset[curRow]] += 1; 105 curRow++; 106 } 107 if (ExistsDominatingClass(classCount, out dominatingClass)) { 108 missingValuesClass = dominatingClass; 109 } else { 110 missingValuesClass = GetRandomMaxClass(classCount, random); 111 } 112 correctClassified += classCount[missingValuesClass]; 113 classCount = PrepareClassCountDictionary(classValues); 114 } 100 115 while (curRow < inputVariableValues.Length) { 101 116 if (newBucket) { … … 108 123 } 109 124 curSplit = inputVariableValues[curRow]; 110 curRow = SetCurRow Correctly(curRow, inputVariableValues, classValuesInDataset, classCount, curSplit);125 curRow = SetCurRowToEndOfSplit(curRow, inputVariableValues, classValuesInDataset, classCount, curSplit); 111 126 newBucket = false; 112 127 } 113 114 128 115 129 if (ExistsDominatingClass(classCount, out dominatingClass)) { 116 130 while (curRow + 1 < classValuesInDataset.Length && 117 IsNextSplitStillDominationClass(curRow, inputVariableValues, classValuesInDataset, curSplit, dominatingClass)) { 118 // curRow + i < classValuesInDataset.Length && classValuesInDataset[curRow + i] == dominatingClass) { 119 curSplit = inputVariableValues[curRow + 1]; 120 classCount[classValuesInDataset[curRow + 1]] += 1; 131 IsNextSplitStillDominatingClass(curRow, inputVariableValues, classValuesInDataset, curSplit, dominatingClass)) { 121 132 curRow++; 122 curRow = SetCurRowCorrectly(curRow, inputVariableValues, classValuesInDataset, classCount, curSplit); 133 curSplit = inputVariableValues[curRow]; 134 classCount[classValuesInDataset[curRow]] += 1; 135 curRow = SetCurRowToEndOfSplit(curRow, inputVariableValues, classValuesInDataset, classCount, curSplit); 123 136 } 124 137 … … 144 157 curSplit = inputVariableValues[curRow]; 145 158 classCount[classValuesInDataset[curRow]] += 1; 146 curRow = SetCurRow Correctly(curRow, inputVariableValues, classValuesInDataset, classCount, curSplit);159 curRow = SetCurRowToEndOfSplit(curRow, inputVariableValues, classValuesInDataset, classCount, curSplit); 147 160 } 148 161 } … … 150 163 if (!done) { 151 164 curSplit = Double.PositiveInfinity; 152 153 IList<double> possibleClasses = new List<double>(); 154 int max = 0; 155 foreach (var item in classCount) { 156 if (max < item.Value) { 157 max = item.Value; 158 possibleClasses = new List<double>(); 159 possibleClasses.Add(item.Key); 160 } else { 161 possibleClasses.Add(item.Key); 162 } 163 } 164 int classindex = random.Next(possibleClasses.Count); 165 splits.Add(curSplit, possibleClasses[classindex]); 166 167 curCorrectClassified += classCount[possibleClasses[classindex]]; 165 double randomClass = GetRandomMaxClass(classCount, random); 166 splits.Add(curSplit, randomClass); 167 168 curCorrectClassified += classCount[randomClass]; 168 169 } 169 170 … … 177 178 Dictionary<double, double> mergedSplits = MergeSplits(bestSplits); 178 179 179 var model = new OneRClassificationModel(bestVariable, mergedSplits.Keys.ToArray(), mergedSplits.Values.ToArray() );180 var model = new OneRClassificationModel(bestVariable, mergedSplits.Keys.ToArray(), mergedSplits.Values.ToArray(), missingValuesClass); 180 181 var solution = new OneRClassificationSolution(model, (IClassificationProblemData)problemData.Clone()); 181 182 … … 183 184 } 184 185 185 private static bool IsNextSplitStillDominationClass(int curRow, double[] inputVariableValues, double[] classValuesInDataset, double curSplit, double dominatingClass) { 186 private static double GetRandomMaxClass(Dictionary<double, int> classCount, IRandom random) { 187 IList<double> possibleClasses = new List<double>(); 188 int max = 0; 189 foreach (var item in classCount) { 190 if (max < item.Value) { 191 max = item.Value; 192 possibleClasses = new List<double>(); 193 possibleClasses.Add(item.Key); 194 } else if (max == item.Value) { 195 possibleClasses.Add(item.Key); 196 } 197 } 198 int classindex = random.Next(possibleClasses.Count); 199 return possibleClasses[classindex]; 200 } 201 202 private static bool IsNextSplitStillDominatingClass(int curRow, double[] inputVariableValues, double[] classValuesInDataset, double curSplit, double dominatingClass) { 186 203 if (curRow >= classValuesInDataset.Length) { 187 204 return false; … … 205 222 } 206 223 207 private static int SetCurRowCorrectly(int curRow, double[] inputVariableValues, double[] classValuesInDataset, Dictionary<double, int> classCount, double curSplit) { 224 // needed if variable contains the same value several times 225 private static int SetCurRowToEndOfSplit(int curRow, double[] inputVariableValues, double[] classValuesInDataset, Dictionary<double, int> classCount, double curSplit) { 208 226 while (curRow + 1 < inputVariableValues.Length && inputVariableValues[curRow + 1] == curSplit) { 209 227 curRow++; -
branches/ClassificationModelComparison/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/OneR/OneRClassificationModel.cs
r9119 r9135 50 50 } 51 51 52 [Storable] 53 protected double missingValuesClass; 54 public double MissingValuesClass { 55 get { return missingValuesClass; } 56 } 57 52 58 [StorableConstructor] 53 59 protected OneRClassificationModel(bool deserializing) : base(deserializing) { } … … 60 66 public override IDeepCloneable Clone(Cloner cloner) { return new OneRClassificationModel(this, cloner); } 61 67 62 public OneRClassificationModel(string variable, double[] splits, double[] classes )68 public OneRClassificationModel(string variable, double[] splits, double[] classes, double missingValuesClass = double.NaN) 63 69 : base() { 64 70 if (splits.Length != classes.Length) { … … 73 79 this.splits = splits; 74 80 this.classes = classes; 81 this.missingValuesClass = missingValuesClass; 75 82 } 76 83 … … 85 92 Array.Sort(values, rowsArray); 86 93 int curSplit = 0, curIndex = 0; 94 while (curIndex < values.Length && Double.IsNaN(values[curIndex])) { 95 estimated[curIndex] = MissingValuesClass; 96 curIndex++; 97 } 87 98 while (curSplit < Splits.Length) { 88 99 while (curIndex < values.Length && Splits[curSplit] > values[curIndex]) { -
branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionComparisonView.Designer.cs
r9119 r9135 60 60 this.dataGridView.Size = new System.Drawing.Size(418, 257); 61 61 this.dataGridView.TabIndex = 0; 62 this.dataGridView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.dataGridView_MouseDoubleClick); 62 63 // 63 64 // ClassificationSolutionComparisonView -
branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionComparisonView.cs
r9119 r9135 33 33 [Content(typeof(IClassificationSolution))] 34 34 public partial class ClassificationSolutionComparisonView : DataAnalysisSolutionEvaluationView { 35 private List<IClassificationSolution> solutions; 36 35 37 public ClassificationSolutionComparisonView() { 36 38 InitializeComponent(); … … 75 77 dataGridView.Rows.Clear(); 76 78 dataGridView.Columns.Clear(); 79 solutions.Clear(); 77 80 } else { 78 81 79 82 IClassificationProblemData problemData = Content.ProblemData; 80 83 Dataset dataset = problemData.Dataset; 81 List<IClassificationSolution>solutions = new List<IClassificationSolution>() { Content };84 solutions = new List<IClassificationSolution>() { Content }; 82 85 solutions.AddRange(GenerateClassificationSolutions(problemData)); 83 86 … … 126 129 127 130 private IEnumerable<IClassificationSolution> GenerateClassificationSolutions(IClassificationProblemData problemData) { 131 var solutions = new List<IClassificationSolution>(); 128 132 var zeroR = ZeroR.CreateZeroRSolution(problemData); 129 133 zeroR.Name = "0R Classification Solution"; 134 solutions.Add(zeroR); 130 135 var oneR = OneR.CreateOneRSolution(problemData, 6, new FastRandom()); 131 136 oneR.Name = "1R Classification Solution"; 132 var lda = LinearDiscriminantAnalysis.CreateLinearDiscriminantAnalysisSolution(problemData); 133 lda.Name = "Linear Discriminant Analysis Solution"; 134 return new List<IClassificationSolution>() { zeroR, oneR, lda }; 137 solutions.Add(oneR); 138 try { 139 var lda = LinearDiscriminantAnalysis.CreateLinearDiscriminantAnalysisSolution(problemData); 140 lda.Name = "Linear Discriminant Analysis Solution"; 141 solutions.Add(lda); 142 } 143 catch (NotSupportedException) { } 144 catch (ArgumentException) { } 145 return solutions; 146 } 147 148 private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e) { 149 var hittestinfo = dataGridView.HitTest(e.X, e.Y); 150 if (hittestinfo.Type != DataGridViewHitTestType.RowHeader) { return; } 151 if (hittestinfo.RowIndex > solutions.Count) { return; } 152 153 MainFormManager.MainForm.ShowContent(solutions[hittestinfo.RowIndex]); 135 154 } 136 155 }
Note: See TracChangeset
for help on using the changeset viewer.