Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12263


Ignore:
Timestamp:
03/27/15 16:10:16 (9 years ago)
Author:
arapeanu
Message:

#2288: Added adjacency matrix update by threshold and target variable functionality + node importance calculation

Location:
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/HeuristicLab.VariableInteractionNetworks.Views-3.3.csproj

    r12230 r12263  
    4747      <Private>False</Private>
    4848    </Reference>
     49    <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     50      <SpecificVersion>False</SpecificVersion>
     51      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
     52    </Reference>
    4953    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    5054      <SpecificVersion>False</SpecificVersion>
     
    6165      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
    6266      <Private>False</Private>
     67    </Reference>
     68    <Reference Include="HeuristicLab.Data.Views-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     69      <SpecificVersion>False</SpecificVersion>
     70      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data.Views-3.3.dll</HintPath>
    6371    </Reference>
    6472    <Reference Include="HeuristicLab.MainForm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     
    102110      <Private>False</Private>
    103111    </Reference>
     112    <Reference Include="PresentationCore" />
     113    <Reference Include="PresentationFramework" />
    104114    <Reference Include="System" />
    105115    <Reference Include="System.Core" />
    106116    <Reference Include="System.Drawing" />
    107117    <Reference Include="System.Windows.Forms" />
     118    <Reference Include="System.Xaml" />
    108119    <Reference Include="System.Xml.Linq" />
    109120    <Reference Include="System.Data.DataSetExtensions" />
     
    111122    <Reference Include="System.Data" />
    112123    <Reference Include="System.Xml" />
     124    <Reference Include="UIAutomationProvider" />
     125    <Reference Include="WindowsBase" />
     126    <Reference Include="WindowsFormsIntegration" />
    113127  </ItemGroup>
    114128  <ItemGroup>
     
    133147    <None Include="Plugin.cs.frame" />
    134148  </ItemGroup>
     149  <ItemGroup>
     150    <EmbeddedResource Include="VariableInteractionNetworkView.resx">
     151      <DependentUpon>VariableInteractionNetworkView.cs</DependentUpon>
     152    </EmbeddedResource>
     153  </ItemGroup>
    135154  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    136155  <PropertyGroup>
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/VariableInteractionNetworkView.Designer.cs

    r12229 r12263  
    3131            this.groupBox1 = new System.Windows.Forms.GroupBox();
    3232            this.viewHost1 = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     33            this.viewHost2 = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     34            this.groupBox2 = new System.Windows.Forms.GroupBox();
     35            this.viewHost3 = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    3336            this.groupBox1.SuspendLayout();
     37            this.groupBox2.SuspendLayout();
    3438            this.SuspendLayout();
    3539            //
     
    3741            //
    3842            this.groupBox1.Controls.Add(this.viewHost1);
     43            this.groupBox1.Controls.Add(this.viewHost2);
    3944            this.groupBox1.Location = new System.Drawing.Point(0, 3);
    4045            this.groupBox1.Name = "groupBox1";
    41             this.groupBox1.Size = new System.Drawing.Size(779, 403);
     46            this.groupBox1.Size = new System.Drawing.Size(635, 228);
    4247            this.groupBox1.TabIndex = 0;
    4348            this.groupBox1.TabStop = false;
    44             this.groupBox1.Text = "Adjacency Matrix";
     49            this.groupBox1.Text = "Adjacency Matrix. Node Impacts";
    4550            //
    4651            // viewHost1
     
    5257            this.viewHost1.Name = "viewHost1";
    5358            this.viewHost1.ReadOnly = false;
    54             this.viewHost1.Size = new System.Drawing.Size(667, 382);
     59            this.viewHost1.Size = new System.Drawing.Size(354, 247);
    5560            this.viewHost1.TabIndex = 0;
    5661            this.viewHost1.ViewsLabelVisible = true;
    5762            this.viewHost1.ViewType = null;
     63            //
     64            // viewHost2
     65            //
     66            this.viewHost2.Caption = "View";
     67            this.viewHost2.Content = null;
     68            this.viewHost2.Enabled = false;
     69            this.viewHost2.Location = new System.Drawing.Point(365, 19);
     70            this.viewHost2.Name = "viewHost2";
     71            this.viewHost2.ReadOnly = false;
     72            this.viewHost2.Size = new System.Drawing.Size(210, 259);
     73            this.viewHost2.TabIndex = 0;
     74            this.viewHost2.ViewsLabelVisible = true;
     75            this.viewHost2.ViewType = null;
     76            //
     77            // groupBox2
     78            //
     79            this.groupBox2.Controls.Add(this.viewHost3);
     80            this.groupBox2.Location = new System.Drawing.Point(6, 268);
     81            this.groupBox2.Name = "groupBox2";
     82            this.groupBox2.Size = new System.Drawing.Size(629, 258);
     83            this.groupBox2.TabIndex = 1;
     84            this.groupBox2.TabStop = false;
     85            this.groupBox2.Text = "Updated Adjacency Matrix (for target variable x1 and threshold 0.2)";
     86            //
     87            // viewHost3
     88            //
     89            this.viewHost3.Caption = "View";
     90            this.viewHost3.Content = null;
     91            this.viewHost3.Enabled = false;
     92            this.viewHost3.Location = new System.Drawing.Point(6, 19);
     93            this.viewHost3.Name = "viewHost3";
     94            this.viewHost3.ReadOnly = false;
     95            this.viewHost3.Size = new System.Drawing.Size(367, 239);
     96            this.viewHost3.TabIndex = 0;
     97            this.viewHost3.ViewsLabelVisible = true;
     98            this.viewHost3.ViewType = null;
    5899            //
    59100            // VariableInteractionNetworkView
     
    61102            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    62103            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     104            this.Controls.Add(this.groupBox2);
    63105            this.Controls.Add(this.groupBox1);
    64106            this.Name = "VariableInteractionNetworkView";
    65             this.Size = new System.Drawing.Size(676, 407);
     107            this.Size = new System.Drawing.Size(635, 513);
    66108            this.groupBox1.ResumeLayout(false);
     109            this.groupBox2.ResumeLayout(false);
    67110            this.ResumeLayout(false);
    68111
     
    73116        private System.Windows.Forms.GroupBox groupBox1;
    74117        private MainForm.WindowsForms.ViewHost viewHost1;
    75 
     118        private MainForm.WindowsForms.ViewHost viewHost2;
     119        private System.Windows.Forms.GroupBox groupBox2;
     120        private MainForm.WindowsForms.ViewHost viewHost3;
    76121    }
    77122}
  • branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/VariableInteractionNetworkView.cs

    r12229 r12263  
    4242  public sealed partial class VariableInteractionNetworkView : AsynchronousContentView {
    4343    private const string variableImpactResultName = "Variable impacts";
     44    private const string TrainingBestSolutionParameterName = "Best training solution";
    4445    public new RunCollection Content {
    4546      get { return (RunCollection)base.Content; }
     
    8384                             from variableName in variableImpact.RowNames
    8485                             select variableName).Distinct().ToArray();
    85 
    8686        var adjMatrix = new DoubleMatrix(variableNames.Length, variableNames.Length);
    87         var adjRow = groupRunCollection.Select(x => CalculateAdjacencyRows(x)).ToList();
    88         var targets = groupRunCollection.Select(x => x.Key);
    89 
    90         adjMatrix.RowNames = targets;
     87
     88        adjMatrix.RowNames = groupRunCollection.Select(x => x.Key);
    9189        adjMatrix.ColumnNames = adjMatrix.RowNames;
    9290
     
    109107            }
    110108        }
     109        viewHost2.Content = CalculateNodeImportance(adjMatrix);
     110        viewHost3.Content = UpdateAdjacencyMatrixByThreshold(0.2, "x1", adjMatrix);
    111111        viewHost1.Content = adjMatrix;
    112112    }
     
    125125                                          select variableName)
    126126                                         .ToList();
    127 
    128         var inputVariables = runs.Select(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).InputVariables).ToArray();     
     127   
    129128        var runNames = runs.Select(x => x.Name).ToArray();
    130129        var runsArray = runs.ToArray();
     
    143142    }
    144143
    145     //taken from RunCollectionVariableImpactView
    146     private IEnumerable<double> GetVariableImpacts(string variableName, IEnumerable<DoubleMatrix> allVariableImpacts)
    147     {
    148         foreach (DoubleMatrix runVariableImpacts in allVariableImpacts)
    149         {
    150             int row = 0;
    151             foreach (string rowName in runVariableImpacts.RowNames)
    152             {
    153                 if (rowName == variableName)
    154                     yield return runVariableImpacts[row, 0];
    155                 row++;
    156             }
    157         }
     144    private DoubleMatrix UpdateAdjacencyMatrixByThreshold(double threshold, string targetVariable, DoubleMatrix adjMatrix)
     145    {
     146        var updatedMatrix = (DoubleMatrix) adjMatrix.Clone();
     147        var groupRunCollection = Content.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList();
     148        string[] targets = adjMatrix.RowNames.ToArray();
     149        var targetIndex = Array.IndexOf(targets, targetVariable);
     150       
     151        for (int j = 0; j < groupRunCollection.Count; ++j)
     152        {
     153            if (updatedMatrix[targetIndex, j] < threshold)
     154            {
     155                updatedMatrix[targetIndex, j] = 0;
     156            }         
     157        }
     158        return updatedMatrix;
     159    }
     160
     161    private DoubleMatrix CalculateNodeImportance(DoubleMatrix adjMatrix)
     162    {
     163           DoubleMatrix nodeImportance = new DoubleMatrix(adjMatrix.Rows, 1);
     164           var variables = new List<Tuple<string, double>>();
     165           var rowNames = adjMatrix.RowNames.ToList();
     166           var groupRunCollection = Content.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList();
     167           double[] meanQuality = new double[groupRunCollection.Count];
     168
     169           for (int j = 0; j < groupRunCollection.Count; ++j)
     170           {
     171               var g = groupRunCollection[j];
     172               meanQuality[j] = g.Average(x => ((IRegressionSolution)x.Results[TrainingBestSolutionParameterName]).TrainingRSquared);
     173           }
     174
     175           for (int i = 0; i < adjMatrix.Columns; ++i)
     176           {
     177               for (int j = 0; j < adjMatrix.Rows; ++j)
     178               {
     179                   nodeImportance[i, 0] += adjMatrix[j, i];
     180               }
     181               nodeImportance[i, 0] = nodeImportance[i, 0] * meanQuality[i] / (adjMatrix.Rows - 1);
     182               variables.Add(new Tuple<string, double>(rowNames[i], nodeImportance[i, 0]));
     183           }
     184           
     185           variables.Sort((b,a) => a.Item2.CompareTo(b.Item2));
     186
     187           for (int i = 0; i < nodeImportance.Rows; ++i)
     188           {
     189               nodeImportance[i, 0] = variables[i].Item2;
     190               rowNames[i] = variables[i].Item1;
     191           }
     192
     193           nodeImportance.RowNames = rowNames;
     194           nodeImportance.ColumnNames = new[] { "Node Importance" };
     195           return nodeImportance;   
    158196    }
    159197
     
    205243        return matrix;
    206244    }
     245
     246    //taken from RunCollectionVariableImpactView
     247    private IEnumerable<double> GetVariableImpacts(string variableName, IEnumerable<DoubleMatrix> allVariableImpacts)
     248    {
     249        foreach (DoubleMatrix runVariableImpacts in allVariableImpacts)
     250        {
     251            int row = 0;
     252            foreach (string rowName in runVariableImpacts.RowNames)
     253            {
     254                if (rowName == variableName)
     255                    yield return runVariableImpacts[row, 0];
     256                row++;
     257            }
     258        }
     259    }
    207260  }
    208261}
Note: See TracChangeset for help on using the changeset viewer.