Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13743


Ignore:
Timestamp:
04/06/16 12:00:09 (8 years ago)
Author:
abeham
Message:

#2457: adding relational SOM projection for solution network visualization

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  
        22obj
        33Plugin.cs
         4*.user
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/HeuristicLab.OptimizationExpertSystem-3.3.csproj

    r13722 r13743  
    151151      <SpecificVersion>False</SpecificVersion>
    152152      <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>
    153158      <Private>False</Private>
    154159    </Reference>
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingSolutionsView.Designer.cs

    r13722 r13743  
    6262      this.solutionsDiversityViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    6363      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();
    6468      this.fdcBetweenBestCheckBox = new System.Windows.Forms.CheckBox();
    6569      this.solutionsFdcViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    6670      this.solutionsNetworkTabPage = new System.Windows.Forms.TabPage();
     71      this.solutionNetworkProjectionLabel = new System.Windows.Forms.Label();
     72      this.solutionNetworkProjectionComboBox = new System.Windows.Forms.ComboBox();
    6773      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();
    7274      this.solutionsTabControl.SuspendLayout();
    7375      this.solutionsQualityTabPage.SuspendLayout();
     
    227229      this.solutionsFdcTabPage.UseVisualStyleBackColor = true;
    228230      //
     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      //
    229267      // fdcBetweenBestCheckBox
    230268      //
     
    256294      // solutionsNetworkTabPage
    257295      //
     296      this.solutionsNetworkTabPage.Controls.Add(this.solutionNetworkProjectionLabel);
     297      this.solutionsNetworkTabPage.Controls.Add(this.solutionNetworkProjectionComboBox);
    258298      this.solutionsNetworkTabPage.Controls.Add(this.solutionsNetworkChart);
    259299      this.solutionsNetworkTabPage.Location = new System.Drawing.Point(4, 22);
     
    265305      this.solutionsNetworkTabPage.UseVisualStyleBackColor = true;
    266306      //
     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      //
    267329      // solutionsNetworkChart
    268330      //
     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)));
    269334      chartArea1.AxisX.IsStartedFromZero = false;
    270335      chartArea1.AxisX.LabelStyle.Enabled = false;
     
    279344      chartArea1.Name = "SolutionsNetworkChartArea";
    280345      this.solutionsNetworkChart.ChartAreas.Add(chartArea1);
    281       this.solutionsNetworkChart.Dock = System.Windows.Forms.DockStyle.Fill;
    282346      legend1.Enabled = false;
    283347      legend1.Name = "Legend1";
    284348      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);
    286350      this.solutionsNetworkChart.Name = "solutionsNetworkChart";
    287351      series1.ChartArea = "SolutionsNetworkChartArea";
     
    303367      this.solutionsNetworkChart.Series.Add(series1);
    304368      this.solutionsNetworkChart.Series.Add(series2);
    305       this.solutionsNetworkChart.Size = new System.Drawing.Size(718, 446);
     369      this.solutionsNetworkChart.Size = new System.Drawing.Size(718, 416);
    306370      this.solutionsNetworkChart.TabIndex = 0;
    307371      this.solutionsNetworkChart.Text = "enhancedChart1";
    308372      this.solutionsNetworkChart.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SolutionsNetworkChartOnMouseClick);
    309373      this.solutionsNetworkChart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.SolutionsNetworkChartOnMouseDoubleClick);
    310       //
    311       // pearsonsRSquaredLabel
    312       //
    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       // fdcPearsonLabel
    321       //
    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       // spearmansRankLabel
    330       //
    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       // fdcSpearmanLabel
    339       //
    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 = "-";
    346374      //
    347375      // UnderstandingSolutionsView
     
    363391      this.solutionsFdcTabPage.PerformLayout();
    364392      this.solutionsNetworkTabPage.ResumeLayout(false);
     393      this.solutionsNetworkTabPage.PerformLayout();
    365394      ((System.ComponentModel.ISupportInitialize)(this.solutionsNetworkChart)).EndInit();
    366395      this.ResumeLayout(false);
     
    391420    private System.Windows.Forms.Label fdcSpearmanLabel;
    392421    private System.Windows.Forms.Label spearmansRankLabel;
     422    private System.Windows.Forms.Label solutionNetworkProjectionLabel;
     423    private System.Windows.Forms.ComboBox solutionNetworkProjectionComboBox;
    393424  }
    394425}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingSolutionsView.cs

    r13722 r13743  
    2828using HeuristicLab.Optimization;
    2929using HeuristicLab.OptimizationExpertSystem.Common;
     30using HeuristicLab.Random;
    3031using System;
    3132using System.Collections.Generic;
     
    4243    public UnderstandingSolutionsView() {
    4344      InitializeComponent();
     45      solutionNetworkProjectionComboBox.SelectedIndex = 0;
    4446    }
    4547
     
    6668    protected override void OnSolutionSeedingPoolChanged() {
    6769      base.OnSolutionSeedingPoolChanged();
    68       UpdateSolutionNetworkAnalysis(similarityComboBox.SelectedItem as ISolutionSimilarityCalculator);
     70      UpdateSolutionNetworkAnalysis(similarityComboBox.SelectedItem as ISolutionSimilarityCalculator, (string)solutionNetworkProjectionComboBox.SelectedItem);
    6971    }
    7072
     
    107109        UpdateSolutionFdcAnalysis(calculator, fdcBetweenBestCheckBox.Checked);
    108110        UpdateSolutionLengthScaleAnalysis(calculator);
    109         UpdateSolutionNetworkAnalysis(calculator);
     111        UpdateSolutionNetworkAnalysis(calculator, (string)solutionNetworkProjectionComboBox.SelectedItem);
    110112      } else {
    111113        solutionsDiversityViewHost.Content = null;
     
    221223    }
    222224
    223     private void UpdateSolutionNetworkAnalysis(ISolutionSimilarityCalculator calculator) {
     225    private void UpdateSolutionNetworkAnalysis(ISolutionSimilarityCalculator calculator, string projection) {
    224226      var series = solutionsNetworkChart.Series["SolutionSeries"];
    225227      var seedingSeries = solutionsNetworkChart.Series["SeedingSolutionSeries"];
     
    235237          }
    236238        }
    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);
    238243        for (var i = 0; i < coords.Rows; i++) {
    239244          var quality = GetQuality(solutionScopes[i], calculator.QualityVariableName) ?? double.NaN;
     
    266271      UpdateSolutionFdcAnalysis(calculator, fdcBetweenBestCheckBox.Checked);
    267272      UpdateSolutionLengthScaleAnalysis(calculator);
    268       UpdateSolutionNetworkAnalysis(calculator);
     273      UpdateSolutionNetworkAnalysis(calculator, (string)solutionNetworkProjectionComboBox.SelectedItem);
    269274    }
    270275
     
    279284      UpdateSolutionFdcAnalysis(calculator, fdcBetweenBestCheckBox.Checked);
    280285      UpdateSolutionLengthScaleAnalysis(calculator);
    281       UpdateSolutionNetworkAnalysis(calculator);
     286      UpdateSolutionNetworkAnalysis(calculator, (string)solutionNetworkProjectionComboBox.SelectedItem);
    282287    }
    283288
     
    285290      if (InvokeRequired) { Invoke((Action<object, EventArgs>)FdcBetweenBestCheckBoxOnCheckedChanged, sender, e); return; }
    286291      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);
    287302    }
    288303
     
    318333      return dval.Value;
    319334    }
     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    }
    320439    #endregion
    321440  }
Note: See TracChangeset for help on using the changeset viewer.