Changeset 13797 for branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/PerformanceModelingView.cs
- Timestamp:
- 04/26/16 13:07:26 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/PerformanceModelingView.cs
r13794 r13797 31 31 using System.Collections.Generic; 32 32 using System.Linq; 33 using System.Threading.Tasks; 33 34 34 35 namespace HeuristicLab.OptimizationExpertSystem { … … 131 132 private void xValidateButton_Click(object sender, EventArgs e) { 132 133 var recommender = (IAlgorithmInstanceRecommender)recommenderComboBox.SelectedItem; 134 var progress = MainForm.AddOperationProgressToView(this, "Performing Leave-one-out Crossvalidation"); 135 136 Task.Factory.StartNew(() => { DoCrossvalidate(recommender, progress); }, TaskCreationOptions.LongRunning); 137 } 138 139 private void DoCrossvalidate(IAlgorithmInstanceRecommender recommender, IProgress progress) { 133 140 var features = characteristics.CheckedItems.Select(x => x.Value.Value).ToArray(); 134 135 141 var trainingSet = Content.ProblemInstances.Where(x => !Content.IsCurrentInstance(x)).ToArray(); 136 142 137 143 var absErr = 0.0; 144 var absLogError = 0.0; 138 145 var confMatrix = new int[6, 6]; 139 146 var tau = 0.0; 140 147 // leave one out crossvalidation 148 var count = 0; 141 149 foreach (var pi in trainingSet) { 150 progress.Status = pi.Name + "..."; 142 151 var model = recommender.TrainModel(trainingSet.Where(x => x != pi).ToArray(), Content, features); 143 152 var predicted = model.GetRanking(pi).ToDictionary(x => x.Key, x => x.Value); 144 153 var observed = Content.GetAlgorithmPerformance(pi); 145 154 absErr += AbsoluteError(observed, predicted); 155 absLogError += AbsoluteLogError(observed, predicted); 146 156 var confMat = ConfusionMatrix(observed, predicted); 147 for (var i = 0; i < confMat.GetLength(0); i++) 157 for (var i = 0; i < confMat.GetLength(0); i++) { 148 158 for (var j = 0; j < confMat.GetLength(1); j++) 149 159 confMatrix[i, j] += confMat[i, j]; 160 } 150 161 tau += KendallsTau(observed, predicted); 151 162 // average NCDG ... relevance determined by clustering (unsuccessful algorithms being penalized with negative relevance) 152 163 // mean reciprocal rank 153 164 // optional: expected reciprocal rank 165 progress.ProgressValue = ++count / (double)trainingSet.Length; 154 166 } 155 167 absErr /= trainingSet.Length; 168 absLogError /= trainingSet.Length; 156 169 tau /= trainingSet.Length; 157 170 158 confusionMatrixView.Content = new IntMatrix(confMatrix);159 171 absoluteErrorView.Content = new DoubleValue(absErr); 172 absoluteLogErrorView.Content = new DoubleValue(absLogError); 173 var description = new[] { "A", "B", "C", "D", "E", "F" }; 174 confusionMatrixView.Content = new IntMatrix(confMatrix) { ColumnNames = description, RowNames = description }; 160 175 kendallsTauView.Content = new DoubleValue(tau); 176 177 progress.Finish(); 161 178 } 162 179 … … 168 185 if (double.IsNaN(actual)) actual = int.MaxValue; 169 186 error += Math.Abs(actual - tuple.Value); 187 } 188 return error; 189 } 190 191 private static double AbsoluteLogError(Dictionary<IAlgorithm, double> performance, Dictionary<IAlgorithm, double> ranking) { 192 var error = 0.0; 193 foreach (var tuple in ranking) { 194 double actual; 195 if (!performance.TryGetValue(tuple.Key, out actual)) continue; 196 if (double.IsNaN(actual)) actual = int.MaxValue; 197 error += Math.Abs(Math.Log10(actual) - Math.Log10(tuple.Value)); 170 198 } 171 199 return error;
Note: See TracChangeset
for help on using the changeset viewer.