Changeset 13743
- Timestamp:
- 04/06/16 12:00:09 (9 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3
- Property svn:ignore
-
old new 2 2 obj 3 3 Plugin.cs 4 *.user
-
- Property svn:ignore
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/HeuristicLab.OptimizationExpertSystem-3.3.csproj
r13722 r13743 151 151 <SpecificVersion>False</SpecificVersion> 152 152 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 153 <Private>False</Private> 154 </Reference> 155 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 156 <SpecificVersion>False</SpecificVersion> 157 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> 153 158 <Private>False</Private> 154 159 </Reference> -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingSolutionsView.Designer.cs
r13722 r13743 62 62 this.solutionsDiversityViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 63 63 this.solutionsFdcTabPage = new System.Windows.Forms.TabPage(); 64 this.fdcSpearmanLabel = new System.Windows.Forms.Label(); 65 this.fdcPearsonLabel = new System.Windows.Forms.Label(); 66 this.spearmansRankLabel = new System.Windows.Forms.Label(); 67 this.pearsonsRSquaredLabel = new System.Windows.Forms.Label(); 64 68 this.fdcBetweenBestCheckBox = new System.Windows.Forms.CheckBox(); 65 69 this.solutionsFdcViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 66 70 this.solutionsNetworkTabPage = new System.Windows.Forms.TabPage(); 71 this.solutionNetworkProjectionLabel = new System.Windows.Forms.Label(); 72 this.solutionNetworkProjectionComboBox = new System.Windows.Forms.ComboBox(); 67 73 this.solutionsNetworkChart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart(); 68 this.pearsonsRSquaredLabel = new System.Windows.Forms.Label();69 this.fdcPearsonLabel = new System.Windows.Forms.Label();70 this.spearmansRankLabel = new System.Windows.Forms.Label();71 this.fdcSpearmanLabel = new System.Windows.Forms.Label();72 74 this.solutionsTabControl.SuspendLayout(); 73 75 this.solutionsQualityTabPage.SuspendLayout(); … … 227 229 this.solutionsFdcTabPage.UseVisualStyleBackColor = true; 228 230 // 231 // fdcSpearmanLabel 232 // 233 this.fdcSpearmanLabel.AutoSize = true; 234 this.fdcSpearmanLabel.Location = new System.Drawing.Point(357, 7); 235 this.fdcSpearmanLabel.Name = "fdcSpearmanLabel"; 236 this.fdcSpearmanLabel.Size = new System.Drawing.Size(10, 13); 237 this.fdcSpearmanLabel.TabIndex = 4; 238 this.fdcSpearmanLabel.Text = "-"; 239 // 240 // fdcPearsonLabel 241 // 242 this.fdcPearsonLabel.AutoSize = true; 243 this.fdcPearsonLabel.Location = new System.Drawing.Point(512, 7); 244 this.fdcPearsonLabel.Name = "fdcPearsonLabel"; 245 this.fdcPearsonLabel.Size = new System.Drawing.Size(10, 13); 246 this.fdcPearsonLabel.TabIndex = 4; 247 this.fdcPearsonLabel.Text = "-"; 248 // 249 // spearmansRankLabel 250 // 251 this.spearmansRankLabel.AutoSize = true; 252 this.spearmansRankLabel.Location = new System.Drawing.Point(281, 7); 253 this.spearmansRankLabel.Name = "spearmansRankLabel"; 254 this.spearmansRankLabel.Size = new System.Drawing.Size(74, 13); 255 this.spearmansRankLabel.TabIndex = 3; 256 this.spearmansRankLabel.Text = "Spearman\'s ρ:"; 257 // 258 // pearsonsRSquaredLabel 259 // 260 this.pearsonsRSquaredLabel.AutoSize = true; 261 this.pearsonsRSquaredLabel.Location = new System.Drawing.Point(436, 7); 262 this.pearsonsRSquaredLabel.Name = "pearsonsRSquaredLabel"; 263 this.pearsonsRSquaredLabel.Size = new System.Drawing.Size(65, 13); 264 this.pearsonsRSquaredLabel.TabIndex = 3; 265 this.pearsonsRSquaredLabel.Text = "Pearson\'s r²:"; 266 // 229 267 // fdcBetweenBestCheckBox 230 268 // … … 256 294 // solutionsNetworkTabPage 257 295 // 296 this.solutionsNetworkTabPage.Controls.Add(this.solutionNetworkProjectionLabel); 297 this.solutionsNetworkTabPage.Controls.Add(this.solutionNetworkProjectionComboBox); 258 298 this.solutionsNetworkTabPage.Controls.Add(this.solutionsNetworkChart); 259 299 this.solutionsNetworkTabPage.Location = new System.Drawing.Point(4, 22); … … 265 305 this.solutionsNetworkTabPage.UseVisualStyleBackColor = true; 266 306 // 307 // solutionNetworkProjectionLabel 308 // 309 this.solutionNetworkProjectionLabel.AutoSize = true; 310 this.solutionNetworkProjectionLabel.Location = new System.Drawing.Point(6, 9); 311 this.solutionNetworkProjectionLabel.Name = "solutionNetworkProjectionLabel"; 312 this.solutionNetworkProjectionLabel.Size = new System.Drawing.Size(57, 13); 313 this.solutionNetworkProjectionLabel.TabIndex = 4; 314 this.solutionNetworkProjectionLabel.Text = "Projection:"; 315 // 316 // solutionNetworkProjectionComboBox 317 // 318 this.solutionNetworkProjectionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 319 this.solutionNetworkProjectionComboBox.FormattingEnabled = true; 320 this.solutionNetworkProjectionComboBox.Items.AddRange(new object[] { 321 "SOM", 322 "MDS"}); 323 this.solutionNetworkProjectionComboBox.Location = new System.Drawing.Point(69, 6); 324 this.solutionNetworkProjectionComboBox.Name = "solutionNetworkProjectionComboBox"; 325 this.solutionNetworkProjectionComboBox.Size = new System.Drawing.Size(180, 21); 326 this.solutionNetworkProjectionComboBox.TabIndex = 3; 327 this.solutionNetworkProjectionComboBox.SelectedIndexChanged += new System.EventHandler(this.SolutionNetworkProjectionComboBoxOnSelectedIndexChanged); 328 // 267 329 // solutionsNetworkChart 268 330 // 331 this.solutionsNetworkChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 332 | System.Windows.Forms.AnchorStyles.Left) 333 | System.Windows.Forms.AnchorStyles.Right))); 269 334 chartArea1.AxisX.IsStartedFromZero = false; 270 335 chartArea1.AxisX.LabelStyle.Enabled = false; … … 279 344 chartArea1.Name = "SolutionsNetworkChartArea"; 280 345 this.solutionsNetworkChart.ChartAreas.Add(chartArea1); 281 this.solutionsNetworkChart.Dock = System.Windows.Forms.DockStyle.Fill;282 346 legend1.Enabled = false; 283 347 legend1.Name = "Legend1"; 284 348 this.solutionsNetworkChart.Legends.Add(legend1); 285 this.solutionsNetworkChart.Location = new System.Drawing.Point(3, 3 );349 this.solutionsNetworkChart.Location = new System.Drawing.Point(3, 33); 286 350 this.solutionsNetworkChart.Name = "solutionsNetworkChart"; 287 351 series1.ChartArea = "SolutionsNetworkChartArea"; … … 303 367 this.solutionsNetworkChart.Series.Add(series1); 304 368 this.solutionsNetworkChart.Series.Add(series2); 305 this.solutionsNetworkChart.Size = new System.Drawing.Size(718, 4 46);369 this.solutionsNetworkChart.Size = new System.Drawing.Size(718, 416); 306 370 this.solutionsNetworkChart.TabIndex = 0; 307 371 this.solutionsNetworkChart.Text = "enhancedChart1"; 308 372 this.solutionsNetworkChart.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SolutionsNetworkChartOnMouseClick); 309 373 this.solutionsNetworkChart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.SolutionsNetworkChartOnMouseDoubleClick); 310 //311 // pearsonsRSquaredLabel312 //313 this.pearsonsRSquaredLabel.AutoSize = true;314 this.pearsonsRSquaredLabel.Location = new System.Drawing.Point(436, 7);315 this.pearsonsRSquaredLabel.Name = "pearsonsRSquaredLabel";316 this.pearsonsRSquaredLabel.Size = new System.Drawing.Size(65, 13);317 this.pearsonsRSquaredLabel.TabIndex = 3;318 this.pearsonsRSquaredLabel.Text = "Pearson\'s r²:";319 //320 // fdcPearsonLabel321 //322 this.fdcPearsonLabel.AutoSize = true;323 this.fdcPearsonLabel.Location = new System.Drawing.Point(512, 7);324 this.fdcPearsonLabel.Name = "fdcPearsonLabel";325 this.fdcPearsonLabel.Size = new System.Drawing.Size(10, 13);326 this.fdcPearsonLabel.TabIndex = 4;327 this.fdcPearsonLabel.Text = "-";328 //329 // spearmansRankLabel330 //331 this.spearmansRankLabel.AutoSize = true;332 this.spearmansRankLabel.Location = new System.Drawing.Point(281, 7);333 this.spearmansRankLabel.Name = "spearmansRankLabel";334 this.spearmansRankLabel.Size = new System.Drawing.Size(74, 13);335 this.spearmansRankLabel.TabIndex = 3;336 this.spearmansRankLabel.Text = "Spearman\'s ρ:";337 //338 // fdcSpearmanLabel339 //340 this.fdcSpearmanLabel.AutoSize = true;341 this.fdcSpearmanLabel.Location = new System.Drawing.Point(357, 7);342 this.fdcSpearmanLabel.Name = "fdcSpearmanLabel";343 this.fdcSpearmanLabel.Size = new System.Drawing.Size(10, 13);344 this.fdcSpearmanLabel.TabIndex = 4;345 this.fdcSpearmanLabel.Text = "-";346 374 // 347 375 // UnderstandingSolutionsView … … 363 391 this.solutionsFdcTabPage.PerformLayout(); 364 392 this.solutionsNetworkTabPage.ResumeLayout(false); 393 this.solutionsNetworkTabPage.PerformLayout(); 365 394 ((System.ComponentModel.ISupportInitialize)(this.solutionsNetworkChart)).EndInit(); 366 395 this.ResumeLayout(false); … … 391 420 private System.Windows.Forms.Label fdcSpearmanLabel; 392 421 private System.Windows.Forms.Label spearmansRankLabel; 422 private System.Windows.Forms.Label solutionNetworkProjectionLabel; 423 private System.Windows.Forms.ComboBox solutionNetworkProjectionComboBox; 393 424 } 394 425 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingSolutionsView.cs
r13722 r13743 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.OptimizationExpertSystem.Common; 30 using HeuristicLab.Random; 30 31 using System; 31 32 using System.Collections.Generic; … … 42 43 public UnderstandingSolutionsView() { 43 44 InitializeComponent(); 45 solutionNetworkProjectionComboBox.SelectedIndex = 0; 44 46 } 45 47 … … 66 68 protected override void OnSolutionSeedingPoolChanged() { 67 69 base.OnSolutionSeedingPoolChanged(); 68 UpdateSolutionNetworkAnalysis(similarityComboBox.SelectedItem as ISolutionSimilarityCalculator );70 UpdateSolutionNetworkAnalysis(similarityComboBox.SelectedItem as ISolutionSimilarityCalculator, (string)solutionNetworkProjectionComboBox.SelectedItem); 69 71 } 70 72 … … 107 109 UpdateSolutionFdcAnalysis(calculator, fdcBetweenBestCheckBox.Checked); 108 110 UpdateSolutionLengthScaleAnalysis(calculator); 109 UpdateSolutionNetworkAnalysis(calculator );111 UpdateSolutionNetworkAnalysis(calculator, (string)solutionNetworkProjectionComboBox.SelectedItem); 110 112 } else { 111 113 solutionsDiversityViewHost.Content = null; … … 221 223 } 222 224 223 private void UpdateSolutionNetworkAnalysis(ISolutionSimilarityCalculator calculator ) {225 private void UpdateSolutionNetworkAnalysis(ISolutionSimilarityCalculator calculator, string projection) { 224 226 var series = solutionsNetworkChart.Series["SolutionSeries"]; 225 227 var seedingSeries = solutionsNetworkChart.Series["SeedingSolutionSeries"]; … … 235 237 } 236 238 } 237 var coords = MultidimensionalScaling.KruskalShepard(dissimilarities); 239 DoubleMatrix coords = null; 240 if (projection == "SOM") 241 coords = Som(dissimilarities, new MersenneTwister(42), jittering: true); 242 else coords = MultidimensionalScaling.KruskalShepard(dissimilarities); 238 243 for (var i = 0; i < coords.Rows; i++) { 239 244 var quality = GetQuality(solutionScopes[i], calculator.QualityVariableName) ?? double.NaN; … … 266 271 UpdateSolutionFdcAnalysis(calculator, fdcBetweenBestCheckBox.Checked); 267 272 UpdateSolutionLengthScaleAnalysis(calculator); 268 UpdateSolutionNetworkAnalysis(calculator );273 UpdateSolutionNetworkAnalysis(calculator, (string)solutionNetworkProjectionComboBox.SelectedItem); 269 274 } 270 275 … … 279 284 UpdateSolutionFdcAnalysis(calculator, fdcBetweenBestCheckBox.Checked); 280 285 UpdateSolutionLengthScaleAnalysis(calculator); 281 UpdateSolutionNetworkAnalysis(calculator );286 UpdateSolutionNetworkAnalysis(calculator, (string)solutionNetworkProjectionComboBox.SelectedItem); 282 287 } 283 288 … … 285 290 if (InvokeRequired) { Invoke((Action<object, EventArgs>)FdcBetweenBestCheckBoxOnCheckedChanged, sender, e); return; } 286 291 UpdateSolutionFdcAnalysis((ISolutionSimilarityCalculator)similarityComboBox.SelectedItem, fdcBetweenBestCheckBox.Checked); 292 } 293 294 private void SolutionNetworkProjectionComboBoxOnSelectedIndexChanged(object sender, EventArgs e) { 295 if (InvokeRequired) { Invoke((Action<object, EventArgs>)SolutionNetworkProjectionComboBoxOnSelectedIndexChanged, sender, e); return; } 296 var calculator = (ISolutionSimilarityCalculator)similarityComboBox.SelectedItem; 297 if (calculator != null) { 298 calculator.SolutionVariableName = (string)solutionNameComboBox.SelectedItem; 299 calculator.QualityVariableName = Content.Problem.Problem.Evaluator.QualityParameter.ActualName; 300 } 301 UpdateSolutionNetworkAnalysis(calculator, (string)solutionNetworkProjectionComboBox.SelectedItem); 287 302 } 288 303 … … 318 333 return dval.Value; 319 334 } 335 336 #region SOM projection 337 /// <summary> 338 /// This is the online algorithm described in 339 /// Olteanu, M. and Villa-Vialaneix, N. 2015. 340 /// On-line relational and multiple relational SOM. 341 /// Neurocomputing 147, pp. 15-30. 342 /// </summary> 343 /// <param name="dissimilarities">The full NxN matrix containing all dissimilarities between N points.</param> 344 /// <param name="random">The random number generator to use.</param> 345 /// <param name="somSize">The length of a side of the SOM grid (there are somSize * somSize neurons).</param> 346 /// <param name="iterations">The amount of iterations to perform in learning.</param> 347 /// <param name="learningRate">The initial learning rate.</param> 348 /// <param name="learningRadius">The initial learning radius.</param> 349 /// <param name="jittering">If the final coordinates should be jittered slightly within the grid.</param> 350 /// <returns>A matrix of coordinates having N rows and 2 columns.</returns> 351 private DoubleMatrix Som(DoubleMatrix dissimilarities, IRandom random, int somSize = 5, int iterations = 100, double learningRate = double.NaN, double learningRadius = 5.0, bool jittering = true) { 352 var K = somSize * somSize; 353 var N = dissimilarities.Rows; 354 if (double.IsNaN(learningRate)) learningRate = 1.0 / Math.Sqrt(2.0 * N); 355 var fixedLearningRate = learningRate / 10.0; 356 var varLearningRate = 9.0 * fixedLearningRate; 357 Func<int, int, double> learningRateT = (maxIter, iter) => { 358 return varLearningRate * ((maxIter - iter) / (double)maxIter) + fixedLearningRate; 359 }; 360 Func<int, int> getX = (neuron) => neuron % somSize; 361 Func<int, int> getY = (neuron) => neuron / somSize; 362 Func<int, int, int, int, double> neighborhood = (maxIter, iter, k, bmu) => { 363 var sigma = 1.0 * ((maxIter - iter) / (double)maxIter) + 0.0001; 364 var xK = getX(k); 365 var yK = getY(k); 366 var xW = getX(bmu); 367 var yW = getY(bmu); 368 var d = (xK - xW) * (xK - xW) + (yK - yW) * (yK - yW); 369 return Math.Exp(-d / (2.0 * sigma * sigma)); 370 }; 371 var alphas = Enumerable.Range(0, K).Select(k => Enumerable.Range(0, N).Select(_ => random.NextDouble()).ToArray()).ToArray(); 372 // normalize s.t. sum(alphas[k]) = 1 373 for (var k = 0; k < K; k++) { 374 var sum = alphas[k].Sum(); 375 for (var i = 0; i < alphas[k].Length; i++) alphas[k][i] /= sum; 376 } 377 var oldAlphas = alphas.Select(x => (double[])x.Clone()).ToArray(); 378 379 for (var iter = 0; iter < iterations; iter++) { 380 var pointShuffle = Enumerable.Range(0, N).Shuffle(random).ToArray(); 381 for (var p = 0; p < N; p++) { 382 var i = pointShuffle[p]; 383 var bmu = GetBestMatchingUnit(dissimilarities, alphas, i); 384 385 for (var k = 0; k < K; k++) { 386 for (var j = 0; j < N; j++) { 387 alphas[k][j] = oldAlphas[k][j] + learningRateT(iterations, iter) * neighborhood(iterations, iter, k, bmu) * ((i == j ? 1.0 : 0.0) - oldAlphas[k][j]); 388 } 389 } 390 } 391 for (var k = 0; k < K; k++) { 392 for (var j = 0; j < N; j++) { 393 oldAlphas[k][j] = alphas[k][j]; 394 } 395 } 396 } 397 398 var result = new DoubleMatrix(N, 2); 399 for (var i = 0; i < N; i++) { 400 var bmu = GetBestMatchingUnit(dissimilarities, alphas, i); 401 if (!jittering) { 402 result[i, 0] = getX(bmu); 403 result[i, 1] = getY(bmu); 404 } else { 405 result[i, 0] = getX(bmu) + random.NextDouble() * 0.8; 406 result[i, 1] = getY(bmu) + random.NextDouble() * 0.8; 407 } 408 } 409 return result; 410 } 411 412 private int GetBestMatchingUnit(DoubleMatrix D, double[][] alphas, int i) { 413 var bmu = -1; 414 var minV = double.MaxValue; 415 for (var k = 0; k < alphas.Length; k++) { 416 var Daki = 0.0; 417 var akDak = 0.0; 418 for (var r = 0; r < D.Rows; r++) { 419 var Dakr = 0.0; 420 for (var s = 0; s < D.Rows; s++) { 421 Dakr += D[r, s] * alphas[k][s]; 422 } 423 if (r == i) Daki = Dakr; 424 akDak += alphas[k][r] * Dakr; 425 } 426 var v = Daki - 0.5 * akDak; 427 if (v < minV) { 428 bmu = k; 429 minV = v; 430 } 431 } 432 return bmu; 433 } 434 #endregion 435 436 private DoubleMatrix Mds(DoubleMatrix dissimilarities) { 437 return MultidimensionalScaling.KruskalShepard(dissimilarities); 438 } 320 439 #endregion 321 440 }
Note: See TracChangeset
for help on using the changeset viewer.