Changeset 12957 for branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ExpertSystem.cs
- Timestamp:
- 09/19/15 21:21:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ExpertSystem.cs
r12860 r12957 67 67 public ItemList<IAlgorithm> AlgorithmInstances { 68 68 get { return algorithmInstances; } 69 set { 70 if (algorithmInstances == value) return; 71 algorithmInstances = value; 72 OnPropertyChanged("AlgorithmInstances"); 73 } 69 74 } 70 75 … … 86 91 public ReadOnlyItemList<IAlgorithm> SuggestedInstances { 87 92 get { return readOnlySuggestedInstances; } 93 } 94 95 [Storable] 96 private RunCollection problemInstances; 97 public RunCollection ProblemInstances { 98 get { return problemInstances; } 99 set { 100 if (problemInstances == value) return; 101 problemInstances = value; 102 OnPropertyChanged("ProblemInstances"); 103 } 88 104 } 89 105 … … 101 117 suggestedInstances = cloner.Clone(original.suggestedInstances); 102 118 readOnlySuggestedInstances = suggestedInstances.AsReadOnly(); 119 problemInstances = cloner.Clone(original.problemInstances); 103 120 RegisterEventHandlers(); 104 121 } … … 110 127 suggestedInstances = new ItemList<IAlgorithm>(); 111 128 readOnlySuggestedInstances = suggestedInstances.AsReadOnly(); 129 problemInstances = new RunCollection(); 112 130 RegisterEventHandlers(); 113 131 } … … 137 155 var runCollection = sender as RunCollection; 138 156 if (runCollection != null && runCollection.UpdateOfRunsInProgress) return; 157 UpdateInstanceMap(); 139 158 UpdateSuggestions(); 159 } 160 161 private void UpdateInstanceMap() { 162 var flaValues = ProblemInstances.ResultNames 163 .Where(x => x.StartsWith("Characteristic.") 164 && ProblemInstances.All(y => y.Results.ContainsKey(x) && y.Results[x] is DoubleValue)) 165 .Select(x => x).ToList(); 166 var ds = new double[ProblemInstances.Count, flaValues.Count]; 167 var instanceCounter = 0; 168 foreach (var instance in ProblemInstances) { 169 for (var feature = 0; feature < flaValues.Count; feature++) 170 ds[instanceCounter, feature] = ((DoubleValue)instance.Results[flaValues[feature]]).Value; 171 instanceCounter++; 172 } 173 174 int info; 175 double[] s2; 176 double[,] v; 177 alglib.pcabuildbasis(ds, instanceCounter, flaValues.Count, out info, out s2, out v); 178 179 var algInstRunDict = AlgorithmInstances.SelectMany(x => x.Runs) 180 .Where(x => x.Parameters.ContainsKey("Problem Name") && x.Parameters["Problem Name"] is StringValue) 181 .GroupBy(x => ((StringValue)x.Parameters["Problem Name"]).Value) 182 .ToDictionary(x => x.Key, x => x.GroupBy(y => ((StringValue)y.Parameters["Algorithm Name"]).Value) 183 .ToDictionary(y => y.Key, y => y.ToList())); 184 ProblemInstances.UpdateOfRunsInProgress = true; 185 try { 186 instanceCounter = 0; 187 foreach (var instance in ProblemInstances) { 188 IItem probNameParam; 189 if (!instance.Parameters.TryGetValue("Problem Name", out probNameParam)) continue; 190 var probInstanceName = ((StringValue)probNameParam).Value; 191 192 double x = 0, y = 0; 193 for (var feature = 0; feature < flaValues.Count; feature++) { 194 x += ds[instanceCounter, feature] * v[feature, 0]; 195 y += ds[instanceCounter, feature] * v[feature, 1]; 196 } 197 IItem item; 198 if (instance.Results.TryGetValue("Projection.PCA1", out item)) { 199 ((DoubleValue)item).Value = x; 200 } else instance.Results.Add("Projection.PCA1", new DoubleValue(x)); 201 if (instance.Results.TryGetValue("Projection.PCA2", out item)) { 202 ((DoubleValue)item).Value = y; 203 } else instance.Results.Add("Projection.PCA2", new DoubleValue(y)); 204 205 var bkQuality = ((DoubleValue)instance.Parameters["BestKnownQuality"]).Value; 206 var maximization = ((BoolValue)instance.Parameters["Maximization"]).Value; 207 foreach (var kvp in algInstRunDict[probInstanceName]) { 208 var algInstanceName = kvp.Key; 209 foreach (var run in kvp.Value) { 210 // TODO: Things needs to be configurable here (table name, targets) 211 foreach (var target in new[] { 1, 1.01, 1.05, 1.1, 1.2, 1.5 }) { 212 var result = ExpectedRuntimeHelper.CalculateErt(kvp.Value, "QualityPerEvaluations", bkQuality * target, maximization); 213 var resultName = algInstanceName + "@" + ((target - 1) * 100) + "%"; 214 if (run.Results.TryGetValue(resultName, out item)) 215 ((DoubleValue)item).Value = result.ExpectedRuntime; 216 else run.Results.Add(resultName, new DoubleValue(result.ExpectedRuntime)); 217 } 218 } 219 } 220 } 221 } finally { ProblemInstances.UpdateOfRunsInProgress = false; } 140 222 } 141 223
Note: See TracChangeset
for help on using the changeset viewer.