Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/11 13:59:25 (13 years ago)
Author:
epitzer
Message:

#1530 integrate changes from trunk

Location:
branches/PersistenceSpeedUp
Files:
9 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/PersistenceSpeedUp

  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r5829 r6760  
    111111  </ItemGroup>
    112112  <ItemGroup>
     113    <Compile Include="SymbolicDataAnalysisSolutionResponseFunctionView.cs">
     114      <SubType>UserControl</SubType>
     115    </Compile>
     116    <Compile Include="SymbolicDataAnalysisSolutionResponseFunctionView.Designer.cs">
     117      <DependentUpon>SymbolicDataAnalysisSolutionResponseFunctionView.cs</DependentUpon>
     118    </Compile>
    113119    <Compile Include="TextualSymbolicDataAnalysisModelView.cs">
    114120      <SubType>UserControl</SubType>
     
    158164    <Compile Include="Symbols\VariableView.Designer.cs">
    159165      <DependentUpon>VariableView.cs</DependentUpon>
     166    </Compile>
     167    <Compile Include="VariableTrackbar.cs">
     168      <SubType>UserControl</SubType>
     169    </Compile>
     170    <Compile Include="VariableTrackbar.Designer.cs">
     171      <DependentUpon>VariableTrackbar.cs</DependentUpon>
    160172    </Compile>
    161173    <None Include="HeuristicLab.snk" />
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLabProblemsDataAnalysisSymbolicViewsPlugin.cs.frame

    r5860 r6760  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    28   [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Views","Provides views for symbolic data analysis problem classes.", "3.4.0.$WCREV$")]
     28  [Plugin("HeuristicLab.Problems.DataAnalysis.Symbolic.Views","Provides views for symbolic data analysis problem classes.", "3.4.1.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs

    r5809 r6760  
    4949      this.splitContainer = new System.Windows.Forms.SplitContainer();
    5050      this.grpSimplify = new System.Windows.Forms.GroupBox();
     51      this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
    5152      this.btnSimplify = new System.Windows.Forms.Button();
     53      this.btnOptimizeConstants = new System.Windows.Forms.Button();
    5254      this.grpViewHost = new System.Windows.Forms.GroupBox();
     55      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    5356      this.splitContainer.Panel1.SuspendLayout();
    5457      this.splitContainer.Panel2.SuspendLayout();
    5558      this.splitContainer.SuspendLayout();
    5659      this.grpSimplify.SuspendLayout();
     60      this.flowLayoutPanel.SuspendLayout();
    5761      this.grpViewHost.SuspendLayout();
    5862      this.SuspendLayout();
     
    6064      // treeChart
    6165      //
    62       this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    63                   | System.Windows.Forms.AnchorStyles.Left)
    64                   | System.Windows.Forms.AnchorStyles.Right)));
     66      this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     67            | System.Windows.Forms.AnchorStyles.Left)
     68            | System.Windows.Forms.AnchorStyles.Right)));
    6569      this.treeChart.BackgroundColor = System.Drawing.Color.White;
    6670      this.treeChart.LineColor = System.Drawing.Color.Black;
    6771      this.treeChart.Location = new System.Drawing.Point(6, 16);
    6872      this.treeChart.Name = "treeChart";
    69       this.treeChart.Size = new System.Drawing.Size(201, 297);
     73      this.treeChart.Size = new System.Drawing.Size(201, 291);
    7074      this.treeChart.Spacing = 5;
    7175      this.treeChart.TabIndex = 0;
     
    7680      // viewHost
    7781      //
    78       this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    79                   | System.Windows.Forms.AnchorStyles.Left)
    80                   | System.Windows.Forms.AnchorStyles.Right)));
     82      this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     83            | System.Windows.Forms.AnchorStyles.Left)
     84            | System.Windows.Forms.AnchorStyles.Right)));
    8185      this.viewHost.Caption = "View";
    8286      this.viewHost.Content = null;
     
    8791      this.viewHost.Size = new System.Drawing.Size(335, 326);
    8892      this.viewHost.TabIndex = 0;
     93      this.viewHost.ViewsLabelVisible = true;
    8994      this.viewHost.ViewType = null;
    9095      //
     
    108113      // grpSimplify
    109114      //
    110       this.grpSimplify.Controls.Add(this.btnSimplify);
     115      this.grpSimplify.Controls.Add(this.flowLayoutPanel);
    111116      this.grpSimplify.Controls.Add(this.treeChart);
    112117      this.grpSimplify.Dock = System.Windows.Forms.DockStyle.Fill;
     
    118123      this.grpSimplify.Text = "Simplify";
    119124      //
     125      // flowLayoutPanel
     126      //
     127      this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
     128            | System.Windows.Forms.AnchorStyles.Right)));
     129      this.flowLayoutPanel.Controls.Add(this.btnSimplify);
     130      this.flowLayoutPanel.Controls.Add(this.btnOptimizeConstants);
     131      this.flowLayoutPanel.Location = new System.Drawing.Point(6, 313);
     132      this.flowLayoutPanel.Name = "flowLayoutPanel";
     133      this.flowLayoutPanel.Size = new System.Drawing.Size(204, 29);
     134      this.flowLayoutPanel.TabIndex = 2;
     135      this.flowLayoutPanel.WrapContents = false;
     136      //
    120137      // btnSimplify
    121138      //
    122       this.btnSimplify.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    123                   | System.Windows.Forms.AnchorStyles.Right)));
    124       this.btnSimplify.Location = new System.Drawing.Point(6, 319);
     139      this.btnSimplify.Location = new System.Drawing.Point(3, 3);
    125140      this.btnSimplify.Name = "btnSimplify";
    126       this.btnSimplify.Size = new System.Drawing.Size(201, 23);
     141      this.btnSimplify.Size = new System.Drawing.Size(95, 23);
    127142      this.btnSimplify.TabIndex = 1;
    128143      this.btnSimplify.Text = "Simplify";
    129144      this.btnSimplify.UseVisualStyleBackColor = true;
    130145      this.btnSimplify.Click += new System.EventHandler(this.btnSimplify_Click);
     146      //
     147      // btnOptimizeConstants
     148      //
     149      this.btnOptimizeConstants.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     150      this.btnOptimizeConstants.Enabled = false;
     151      this.btnOptimizeConstants.Location = new System.Drawing.Point(104, 3);
     152      this.btnOptimizeConstants.Name = "btnOptimizeConstants";
     153      this.btnOptimizeConstants.Size = new System.Drawing.Size(97, 23);
     154      this.btnOptimizeConstants.TabIndex = 2;
     155      this.btnOptimizeConstants.Text = "Optimize";
     156      this.btnOptimizeConstants.UseVisualStyleBackColor = true;
     157      this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click);
    131158      //
    132159      // grpViewHost
     
    141168      this.grpViewHost.Text = "Details";
    142169      //
    143       // InteractiveSymbolicRegressionSolutionSimplifierView
     170      // InteractiveSymbolicDataAnalysisSolutionSimplifierView
    144171      //
    145172      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    146173      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    147174      this.Controls.Add(this.splitContainer);
    148       this.Name = "InteractiveSymbolicRegressionSolutionSimplifierView";
     175      this.Name = "InteractiveSymbolicDataAnalysisSolutionSimplifierView";
    149176      this.Size = new System.Drawing.Size(564, 348);
    150177      this.splitContainer.Panel1.ResumeLayout(false);
    151178      this.splitContainer.Panel2.ResumeLayout(false);
     179      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
    152180      this.splitContainer.ResumeLayout(false);
    153181      this.grpSimplify.ResumeLayout(false);
     182      this.flowLayoutPanel.ResumeLayout(false);
    154183      this.grpViewHost.ResumeLayout(false);
    155184      this.ResumeLayout(false);
     
    165194    private System.Windows.Forms.GroupBox grpViewHost;
    166195    private System.Windows.Forms.Button btnSimplify;
     196    private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel;
     197    protected System.Windows.Forms.Button btnOptimizeConstants;
    167198  }
    168199}
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r6113 r6760  
    212212      UpdateModel(simplifiedExpressionTree);
    213213    }
     214
     215    protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e);
    214216  }
    215217}
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Properties/AssemblyInfo.frame

    r5860 r6760  
    5353// by using the '*' as shown below:
    5454[assembly: AssemblyVersion("3.4.0.0")]
    55 [assembly: AssemblyFileVersion("3.4.0.$WCREV$")]
     55[assembly: AssemblyFileVersion("3.4.1.$WCREV$")]
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.Designer.cs

    r5809 r6760  
    4646    private void InitializeComponent() {
    4747      this.matrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
     48      this.comboBox = new System.Windows.Forms.ComboBox();
     49      this.label1 = new System.Windows.Forms.Label();
     50      this.variableImpactsGroupBox = new System.Windows.Forms.GroupBox();
     51      this.variableImpactsGroupBox.SuspendLayout();
    4852      this.SuspendLayout();
    4953      //
     
    5559      this.matrixView.Caption = "StringConvertibleMatrix View";
    5660      this.matrixView.Content = null;
    57       this.matrixView.Location = new System.Drawing.Point(3, 3);
     61      this.matrixView.Location = new System.Drawing.Point(6, 19);
    5862      this.matrixView.Name = "matrixView";
    5963      this.matrixView.ReadOnly = true;
    60       this.matrixView.Size = new System.Drawing.Size(303, 229);
     64      this.matrixView.ShowRowsAndColumnsTextBox = true;
     65      this.matrixView.ShowStatisticalInformation = true;
     66      this.matrixView.Size = new System.Drawing.Size(294, 174);
    6167      this.matrixView.TabIndex = 0;
     68      //
     69      // comboBox
     70      //
     71      this.comboBox.FormattingEnabled = true;
     72      this.comboBox.Location = new System.Drawing.Point(39, 6);
     73      this.comboBox.Name = "comboBox";
     74      this.comboBox.Size = new System.Drawing.Size(68, 21);
     75      this.comboBox.TabIndex = 1;
     76      this.comboBox.SelectedValueChanged += new System.EventHandler(this.comboBox_SelectedValueChanged);
     77      //
     78      // label1
     79      //
     80      this.label1.AutoSize = true;
     81      this.label1.Location = new System.Drawing.Point(3, 9);
     82      this.label1.Name = "label1";
     83      this.label1.Size = new System.Drawing.Size(30, 13);
     84      this.label1.TabIndex = 2;
     85      this.label1.Text = "Fold:";
     86      //
     87      // variableImpactsGroupBox
     88      //
     89      this.variableImpactsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     90                  | System.Windows.Forms.AnchorStyles.Left)
     91                  | System.Windows.Forms.AnchorStyles.Right)));
     92      this.variableImpactsGroupBox.Controls.Add(this.matrixView);
     93      this.variableImpactsGroupBox.Location = new System.Drawing.Point(0, 33);
     94      this.variableImpactsGroupBox.Name = "variableImpactsGroupBox";
     95      this.variableImpactsGroupBox.Size = new System.Drawing.Size(306, 199);
     96      this.variableImpactsGroupBox.TabIndex = 3;
     97      this.variableImpactsGroupBox.TabStop = false;
     98      this.variableImpactsGroupBox.Text = "Variable impacts:";
    6299      //
    63100      // RunCollectionVariableImpactView
     
    65102      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    66103      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    67       this.Controls.Add(this.matrixView);
     104      this.Controls.Add(this.variableImpactsGroupBox);
     105      this.Controls.Add(this.label1);
     106      this.Controls.Add(this.comboBox);
    68107      this.Name = "RunCollectionVariableImpactView";
    69108      this.Size = new System.Drawing.Size(309, 235);
     109      this.variableImpactsGroupBox.ResumeLayout(false);
    70110      this.ResumeLayout(false);
     111      this.PerformLayout();
    71112
    72113    }
     
    75116
    76117    private HeuristicLab.Data.Views.StringConvertibleMatrixView matrixView;
     118    private System.Windows.Forms.ComboBox comboBox;
     119    private System.Windows.Forms.Label label1;
     120    private System.Windows.Forms.GroupBox variableImpactsGroupBox;
    77121  }
    78122}
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.cs

    r5975 r6760  
    3535  public sealed partial class RunCollectionVariableImpactView : AsynchronousContentView {
    3636    private const string variableImpactResultName = "Variable impacts";
     37    private const string crossValidationFoldsResultName = "CrossValidation Folds";
     38    private const string numberOfFoldsParameterName = "Folds";
    3739    public RunCollectionVariableImpactView() {
    3840      InitializeComponent();
     
    9597    }
    9698
     99    private void comboBox_SelectedValueChanged(object sender, EventArgs e) {
     100      if (comboBox.SelectedItem != null) {
     101        var cvRuns = from r in Content
     102                     where r.Visible
     103                     where r.Parameters.ContainsKey(numberOfFoldsParameterName)
     104                     select r;
     105        var selectedFolds = from r in cvRuns
     106                            let foldCollection = (RunCollection)r.Results[crossValidationFoldsResultName]
     107                            select (IRun)foldCollection.ElementAt((int)comboBox.SelectedItem).Clone();
     108        matrixView.Content = CalculateVariableImpactMatrix(selectedFolds.ToArray(), cvRuns.Select(r => r.Name).ToArray());
     109      }
     110    }
     111
     112
    97113    private void UpdateData() {
    98       matrixView.Content = CalculateVariableImpactMatrix();
    99     }
    100 
    101     private DoubleMatrix CalculateVariableImpactMatrix() {
     114      if (Content != null) {
     115        comboBox.Items.Clear();
     116        comboBox.Enabled = false;
     117        var visibleRuns = Content.Where(r => r.Visible).ToArray();
     118        var representativeCvRun =
     119          visibleRuns.Where(r => r.Parameters.ContainsKey(numberOfFoldsParameterName)).FirstOrDefault();
     120        if (representativeCvRun != null) {
     121          // make sure all runs have the same number of folds
     122          int nFolds = ((IntValue)representativeCvRun.Parameters[numberOfFoldsParameterName]).Value;
     123          var cvRuns = visibleRuns.Where(r => r.Parameters.ContainsKey(numberOfFoldsParameterName));
     124          if (cvRuns.All(r => ((IntValue)r.Parameters[numberOfFoldsParameterName]).Value == nFolds)) {
     125            // populate combobox
     126            for (int foldIndex = 0; foldIndex < nFolds; foldIndex++) {
     127              comboBox.Items.Add(foldIndex);
     128            }
     129            comboBox.Enabled = true;
     130            var selectedFolds = from r in cvRuns
     131                                let foldCollection = (RunCollection)r.Results[crossValidationFoldsResultName]
     132                                select foldCollection.First();
     133            matrixView.Content = CalculateVariableImpactMatrix(selectedFolds.ToArray(), cvRuns.Select(f => f.Name).ToArray());
     134          } else {
     135            matrixView.Content = null;
     136          }
     137        } else {
     138          var runsWithVariables = visibleRuns.Where(r => r.Results.ContainsKey(variableImpactResultName)).ToArray();
     139          matrixView.Content = CalculateVariableImpactMatrix(runsWithVariables);
     140        }
     141      }
     142    }
     143
     144    private IStringConvertibleMatrix CalculateVariableImpactMatrix(IRun[] runs) {
     145      return CalculateVariableImpactMatrix(runs, runs.Select(r => r.Name).ToArray());
     146    }
     147
     148    private DoubleMatrix CalculateVariableImpactMatrix(IRun[] runs, string[] runNames) {
    102149      DoubleMatrix matrix = null;
    103       if (Content != null) {
    104         List<IRun> runsWithVariables = Content.Where(r => r.Visible && r.Results.ContainsKey(variableImpactResultName)).ToList();
    105         IEnumerable<DoubleMatrix> allVariableImpacts = (from run in runsWithVariables
    106                                                         select run.Results[variableImpactResultName]).Cast<DoubleMatrix>();
    107         IEnumerable<string> variableNames = (from variableImpact in allVariableImpacts
    108                                              from variableName in variableImpact.RowNames
    109                                              select variableName)
    110                                             .Distinct();
    111         // filter variableNames: only include names that have at least one non-zero value in a run
    112         List<string> variableNamesList = (from variableName in variableNames
    113                                           where GetVariableImpacts(variableName, allVariableImpacts).Any(x => !x.IsAlmost(0.0))
    114                                           select variableName)
    115                                          .ToList();
    116 
    117         List<string> statictics = new List<string> { "Median Rank", "Mean", "StdDev", "pValue" };
    118         List<string> columnNames = runsWithVariables.Select(r => r.Name).ToList();
    119         columnNames.AddRange(statictics);
    120         int runs = runsWithVariables.Count();
    121 
    122         matrix = new DoubleMatrix(variableNamesList.Count, runs + statictics.Count);
    123         matrix.SortableView = true;
    124         matrix.RowNames = variableNamesList;
    125         matrix.ColumnNames = columnNames;
    126 
    127         for (int i = 0; i < runsWithVariables.Count; i++) {
    128           IRun run = runsWithVariables[i];
    129           DoubleMatrix runVariableImpacts = (DoubleMatrix)run.Results[variableImpactResultName];
    130           for (int j = 0; j < runVariableImpacts.Rows; j++) {
    131             int rowIndex = variableNamesList.FindIndex(s => s == runVariableImpacts.RowNames.ElementAt(j));
    132             if (rowIndex > -1) {
    133               matrix[rowIndex, i] = runVariableImpacts[j, 0];
    134             }
    135           }
    136         }
    137 
    138         List<List<double>> variableImpactsOverRuns = (from variableName in variableNamesList
    139                                                       select GetVariableImpacts(variableName, allVariableImpacts).ToList())
    140                                                      .ToList();
    141         List<List<double>> variableRanks = (from variableName in variableNamesList
    142                                             select GetVariableImpactRanks(variableName, allVariableImpacts).ToList())
    143                                         .ToList();
    144         if (variableImpactsOverRuns.Count() > 0) {
    145           // the variable with the worst median impact value is chosen as the reference variable
    146           // this is problematic if all variables are relevant, however works often in practice
    147           List<double> referenceImpacts = (from impacts in variableImpactsOverRuns
    148                                            let avg = impacts.Median()
    149                                            orderby avg
    150                                            select impacts)
    151                                            .First();
    152           // for all variables
    153           for (int row = 0; row < variableImpactsOverRuns.Count; row++) {
    154             // median rank
    155             matrix[row, runs] = variableRanks[row].Median();
    156             // also show mean and std.dev. of relative variable impacts to indicate the relative difference in impacts of variables
    157             matrix[row, runs + 1] = variableImpactsOverRuns[row].Average();
    158             matrix[row, runs + 2] = variableImpactsOverRuns[row].StandardDeviation();
    159 
    160             double leftTail = 0; double rightTail = 0; double bothTails = 0;
    161             // calc differences of impacts for current variable and reference variable
    162             double[] z = new double[referenceImpacts.Count];
    163             for (int i = 0; i < z.Length; i++) {
    164               z[i] = variableImpactsOverRuns[row][i] - referenceImpacts[i];
    165             }
    166             // wilcoxon signed rank test is used because the impact values of two variables in a single run are not independent
    167             alglib.wsr.wilcoxonsignedranktest(z, z.Length, 0, ref bothTails, ref leftTail, ref rightTail);
    168             matrix[row, runs + 3] = bothTails;
    169           }
    170         }
    171       }
    172       return matrix;
     150      IEnumerable<DoubleMatrix> allVariableImpacts = (from run in runs
     151                                                      select run.Results[variableImpactResultName]).Cast<DoubleMatrix>();
     152      IEnumerable<string> variableNames = (from variableImpact in allVariableImpacts
     153                                           from variableName in variableImpact.RowNames
     154                                           select variableName)
     155                                          .Distinct();
     156      // filter variableNames: only include names that have at least one non-zero value in a run
     157      List<string> variableNamesList = (from variableName in variableNames
     158                                        where GetVariableImpacts(variableName, allVariableImpacts).Any(x => !x.IsAlmost(0.0))
     159                                        select variableName)
     160                                       .ToList();
     161
     162      List<string> statictics = new List<string> { "Median Rank", "Mean", "StdDev", "pValue" };
     163      List<string> columnNames = new List<string>(runNames);
     164      columnNames.AddRange(statictics);
     165      int numberOfRuns = runs.Length;
     166
     167      matrix = new DoubleMatrix(variableNamesList.Count, numberOfRuns + statictics.Count);
     168      matrix.SortableView = true;
     169      matrix.RowNames = variableNamesList;
     170      matrix.ColumnNames = columnNames;
     171
     172      // calculate statistics
     173      List<List<double>> variableImpactsOverRuns = (from variableName in variableNamesList
     174                                                    select GetVariableImpacts(variableName, allVariableImpacts).ToList())
     175                                             .ToList();
     176      List<List<double>> variableRanks = (from variableName in variableNamesList
     177                                          select GetVariableImpactRanks(variableName, allVariableImpacts).ToList())
     178                                      .ToList();
     179      if (variableImpactsOverRuns.Count() > 0) {
     180        // the variable with the worst median impact value is chosen as the reference variable
     181        // this is problematic if all variables are relevant, however works often in practice
     182        List<double> referenceImpacts = (from impacts in variableImpactsOverRuns
     183                                         let avg = impacts.Median()
     184                                         orderby avg
     185                                         select impacts)
     186                                         .First();
     187        // for all variables
     188        for (int row = 0; row < variableImpactsOverRuns.Count; row++) {
     189          // median rank
     190          matrix[row, numberOfRuns] = variableRanks[row].Median();
     191          // also show mean and std.dev. of relative variable impacts to indicate the relative difference in impacts of variables
     192          matrix[row, numberOfRuns + 1] = Math.Round(variableImpactsOverRuns[row].Average(), 3);
     193          matrix[row, numberOfRuns + 2] = Math.Round(variableImpactsOverRuns[row].StandardDeviation(), 3);
     194
     195          double leftTail = 0; double rightTail = 0; double bothTails = 0;
     196          // calc differences of impacts for current variable and reference variable
     197          double[] z = new double[referenceImpacts.Count];
     198          for (int i = 0; i < z.Length; i++) {
     199            z[i] = variableImpactsOverRuns[row][i] - referenceImpacts[i];
     200          }
     201          // wilcoxon signed rank test is used because the impact values of two variables in a single run are not independent
     202          alglib.wsr.wilcoxonsignedranktest(z, z.Length, 0, ref bothTails, ref leftTail, ref rightTail);
     203          matrix[row, numberOfRuns + 3] = Math.Round(bothTails, 4);
     204        }
     205      }
     206
     207      // fill matrix with impacts from runs
     208      for (int i = 0; i < runs.Length; i++) {
     209        IRun run = runs[i];
     210        DoubleMatrix runVariableImpacts = (DoubleMatrix)run.Results[variableImpactResultName];
     211        for (int j = 0; j < runVariableImpacts.Rows; j++) {
     212          int rowIndex = variableNamesList.FindIndex(s => s == runVariableImpacts.RowNames.ElementAt(j));
     213          if (rowIndex > -1) {
     214            matrix[rowIndex, i] = Math.Round(runVariableImpacts[j, 0], 3);
     215          }
     216        }
     217      }
     218      // sort by median
     219      var sortedMatrix = (DoubleMatrix)matrix.Clone();
     220      var sortedIndexes = from i in Enumerable.Range(0, sortedMatrix.Rows)
     221                          orderby matrix[i, numberOfRuns]
     222                          select i;
     223
     224      int targetIndex = 0;
     225      foreach (var sourceIndex in sortedIndexes) {
     226        for (int c = 0; c < matrix.Columns; c++)
     227          sortedMatrix[targetIndex, c] = matrix[sourceIndex, c];
     228        targetIndex++;
     229      }
     230      return sortedMatrix;
    173231    }
    174232
     
    213271      }
    214272    }
     273
    215274  }
    216275}
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.cs

    r5809 r6760  
    2323using System.Linq;
    2424using System.Windows.Forms;
     25using HeuristicLab.Collections;
     26using HeuristicLab.Core;
     27using HeuristicLab.Core.Views;
     28using HeuristicLab.Data;
    2529using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    2630using HeuristicLab.MainForm;
    2731using HeuristicLab.MainForm.WindowsForms;
    28 using HeuristicLab.Core;
    29 using HeuristicLab.Data;
    30 using HeuristicLab.Core.Views;
    31 using HeuristicLab.Collections;
    3232
    3333
    3434namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    35 
    3635  [View("Variable View")]
    3736  [Content(typeof(Variable), true)]
     
    5958      variableNamesView.Content.CheckedItemsChanged += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
    6059      variableNamesView.Content.CollectionReset += new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
    61     }
     60      foreach (var variable in variableNamesView.Content) {
     61        variable.ValueChanged += new EventHandler(variable_ValueChanged);
     62      }
     63    }
     64
    6265
    6366    private void DeregisterVariableNamesViewContentEvents() {
     
    6669      variableNamesView.Content.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
    6770      variableNamesView.Content.CollectionReset -= new CollectionItemsChangedEventHandler<StringValue>(variableNames_Changed);
     71      foreach (var variable in variableNamesView.Content) {
     72        variable.ValueChanged -= new EventHandler(variable_ValueChanged);
     73      }
    6874    }
    6975
     
    8187    protected override void OnContentChanged() {
    8288      base.OnContentChanged();
     89      variableNamesView.Content.Clear();
    8390      UpdateControl();
    8491    }
     
    104111    #region control event handlers
    105112    private void variableNames_Changed(object sender, CollectionItemsChangedEventArgs<StringValue> args) {
     113      if (args.Items != null)
     114        foreach (var newVar in args.Items)
     115          newVar.ValueChanged += new EventHandler(variable_ValueChanged);
     116      if (args.OldItems != null)
     117        foreach (var oldVar in args.OldItems)
     118          oldVar.ValueChanged -= new EventHandler(variable_ValueChanged);
     119      UpdateContent();
     120    }
     121
     122    private void variable_ValueChanged(object sender, EventArgs e) {
     123      UpdateContent();
     124    }
     125
     126    private void UpdateContent() {
    106127      if (Content != null) {
     128        Content.Changed -= new EventHandler(Content_Changed);
    107129        Content.VariableNames = variableNamesView.Content.CheckedItems.Select(x => x.Value).ToList();
    108       }
    109     }
     130        Content.Changed += new EventHandler(Content_Changed);
     131      }
     132    }
     133
    110134
    111135    private void weightMuTextBox_TextChanged(object sender, EventArgs e) {
     
    137161      }
    138162    }
    139 
    140163    private void multiplicativeWeightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
    141164      double sigma;
     
    161184        RegisterVariableNamesViewContentEvents();
    162185      } else {
    163         var existingEntries = variableNamesView.Content.Select(x => x.Value);
    164        
     186        var existingEntries = variableNamesView.Content.ToList();
     187
    165188        // temporarily deregister to prevent circular calling of events
    166189        DeregisterVariableNamesViewContentEvents();
    167190        // add additional entries
    168         foreach (var variableName in Content.VariableNames.Except(existingEntries)) {
     191        foreach (var variableName in Content.VariableNames.Except(existingEntries.Select(x => x.Value)))
    169192          variableNamesView.Content.Add(new StringValue(variableName), true);
    170         }
     193        foreach (var oldEntry in existingEntries.Where(x => !Content.VariableNames.Contains(x.Value)))
     194          variableNamesView.Content.Remove(oldEntry);
    171195        RegisterVariableNamesViewContentEvents();
    172196
Note: See TracChangeset for help on using the changeset viewer.