Changeset 12229
- Timestamp:
- 03/20/15 16:31:50 (10 years ago)
- Location:
- branches/HeuristicLab.VariableInteractionNetworks
- Files:
-
- 1 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3
-
Property
svn:global-ignores
set to
obj
-
Property
svn:global-ignores
set to
-
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/VariableInteractionNetworkView.Designer.cs
r12198 r12229 29 29 private void InitializeComponent() 30 30 { 31 components = new System.ComponentModel.Container(); 31 this.groupBox1 = new System.Windows.Forms.GroupBox(); 32 this.viewHost1 = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 33 this.groupBox1.SuspendLayout(); 34 this.SuspendLayout(); 35 // 36 // groupBox1 37 // 38 this.groupBox1.Controls.Add(this.viewHost1); 39 this.groupBox1.Location = new System.Drawing.Point(0, 3); 40 this.groupBox1.Name = "groupBox1"; 41 this.groupBox1.Size = new System.Drawing.Size(779, 403); 42 this.groupBox1.TabIndex = 0; 43 this.groupBox1.TabStop = false; 44 this.groupBox1.Text = "Adjacency Matrix"; 45 // 46 // viewHost1 47 // 48 this.viewHost1.Caption = "View"; 49 this.viewHost1.Content = null; 50 this.viewHost1.Enabled = false; 51 this.viewHost1.Location = new System.Drawing.Point(6, 19); 52 this.viewHost1.Name = "viewHost1"; 53 this.viewHost1.ReadOnly = false; 54 this.viewHost1.Size = new System.Drawing.Size(667, 382); 55 this.viewHost1.TabIndex = 0; 56 this.viewHost1.ViewsLabelVisible = true; 57 this.viewHost1.ViewType = null; 58 // 59 // VariableInteractionNetworkView 60 // 61 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 32 62 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 63 this.Controls.Add(this.groupBox1); 64 this.Name = "VariableInteractionNetworkView"; 65 this.Size = new System.Drawing.Size(676, 407); 66 this.groupBox1.ResumeLayout(false); 67 this.ResumeLayout(false); 68 33 69 } 34 70 35 71 #endregion 72 73 private System.Windows.Forms.GroupBox groupBox1; 74 private MainForm.WindowsForms.ViewHost viewHost1; 75 36 76 } 37 77 } -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/VariableInteractionNetworkView.cs
r12198 r12229 34 34 using HeuristicLab.Problems.DataAnalysis.Symbolic; 35 35 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 36 37 38 namespace HeuristicLab.VariableInteractionNetworks.Views 39 { 40 [View("VariableInteractionNetworkView")] 41 [Content(typeof(RunCollection), IsDefaultView = false)] 42 public sealed partial class VariableInteractionNetworkView : AsynchronousContentView 43 { 44 public new RunCollection Content 45 { 46 get { return (RunCollection)base.Content; } 47 set { base.Content = value; } 48 } 49 50 public VariableInteractionNetworkView() 51 { 52 InitializeComponent(); 53 CalculateVariableInteractions(); 54 } 55 56 protected override void DeregisterContentEvents() 57 { 58 // TODO: Deregister your event handlers here 59 base.DeregisterContentEvents(); 60 } 61 62 protected override void RegisterContentEvents() 63 { 64 base.RegisterContentEvents(); 65 // TODO: Register your event handlers here 66 } 67 68 #region Event Handlers (Content) 69 // TODO: Put event handlers of the content here 70 #endregion 71 72 protected override void OnContentChanged() 73 { 74 base.OnContentChanged(); 75 if (Content == null) 76 { 77 // TODO: Add code when content has been changed and is null 78 } 79 else 80 { 81 // TODO: Add code when content has been changed and is not null 82 } 83 } 84 85 86 protected override void SetEnabledStateOfControls() 87 { 88 base.SetEnabledStateOfControls(); 89 // TODO: Enable or disable controls based on whether the content is null or the view is set readonly 90 } 91 92 #region Event Handlers (child controls) 93 // TODO: Put event handlers of child controls here. 94 #endregion 95 96 private void CalculateVariableInteractions() 97 { 98 var runCollection = Content; 99 100 foreach (var g in runCollection.GroupBy(x => ((IRegressionProblem)x.Algorithm.Problem).ProblemData.TargetVariable)) 101 { 102 CalculateVariableNetwork(g); 103 } 104 } 105 106 private void CalculateVariableNetwork(IEnumerable<IRun> runs) 107 { 108 109 } 110 } 36 using System.Collections; 37 38 namespace HeuristicLab.VariableInteractionNetworks.Views { 39 [View("Variable Interaction Network")] 40 [Content(typeof(RunCollection), IsDefaultView = false)] 41 42 public sealed partial class VariableInteractionNetworkView : AsynchronousContentView { 43 private const string variableImpactResultName = "Variable impacts"; 44 public new RunCollection Content { 45 get { return (RunCollection)base.Content; } 46 set { base.Content = value; } 47 } 48 49 public VariableInteractionNetworkView() { 50 InitializeComponent(); 51 } 52 53 #region events 54 55 // #region Event Handlers (Content) 56 protected override void OnContentChanged() { 57 base.OnContentChanged(); 58 if (Content == null) { 59 // TODO: Add code when content has been changed and is null 60 } else { 61 // TODO: Add code when content has been changed and is not null 62 CalculateAdjacencyMatrix(); 63 } 64 } 65 #endregion 66 67 protected override void SetEnabledStateOfControls() { 68 base.SetEnabledStateOfControls(); 69 // TODO: Enable or disable controls based on whether the content is null or the view is set readonly 70 } 71 72 #region Event Handlers (child controls) 73 // TODO: Put event handlers of child controls here. 74 #endregion 75 76 private void CalculateAdjacencyMatrix() 77 { 78 var runCollection = Content; 79 var groupRunCollection = Content.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList(); 80 81 var allVariableImpacts = runCollection.Select(run => (DoubleMatrix)run.Results[variableImpactResultName]); 82 var variableNames = (from variableImpact in allVariableImpacts 83 from variableName in variableImpact.RowNames 84 select variableName).Distinct().ToArray(); 85 86 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; 91 adjMatrix.ColumnNames = adjMatrix.RowNames; 92 93 for (int j = 0; j < groupRunCollection.Count; ++j) 94 { 95 var g = groupRunCollection[j]; 96 var matrix = CalculateAdjacencyRows(g); 97 var variables = new List<Tuple<string, double>>(); 98 var columnNames = matrix.ColumnNames.ToList(); 99 100 for (int i = 0; i < matrix.Columns; ++i) 101 { 102 variables.Add(new Tuple<string, double>(columnNames[i], matrix[0, i])); 103 } 104 variables.Add(new Tuple<string, double>(g.Key, 0)); 105 variables.Sort((a, b) => a.Item1.CompareTo(b.Item1)); 106 for (int i = 0; i < variables.Count; ++i) 107 { 108 adjMatrix[j, i] = variables[i].Item2; 109 } 110 } 111 viewHost1.Content = adjMatrix; 112 } 113 114 private DoubleMatrix CalculateAdjacencyRows(IEnumerable<IRun> runs) 115 { 116 IEnumerable<DoubleMatrix> allVariableImpacts = (from run in runs 117 select run.Results[variableImpactResultName]).Cast<DoubleMatrix>(); 118 var variableNames = (from variableImpact in allVariableImpacts 119 from variableName in variableImpact.RowNames 120 select variableName) 121 .Distinct().ToArray(); 122 123 List<string> variableNamesList = (from variableName in variableNames 124 where GetVariableImpacts(variableName, allVariableImpacts).Any(x => !x.IsAlmost(0.0)) 125 select variableName) 126 .ToList(); 127 128 var inputVariables = runs.Select(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).InputVariables).ToArray(); 129 var runNames = runs.Select(x => x.Name).ToArray(); 130 var runsArray = runs.ToArray(); 131 DoubleMatrix varImpactMatrix = CalculateVariableImpactMatrix(runsArray, runNames); 132 var targetMatrix = new DoubleMatrix(1, variableNames.Length); 133 134 for (int i = 0; i < varImpactMatrix.Rows; ++i) 135 { 136 targetMatrix[0, i] = varImpactMatrix[i, runNames.Length]; 137 } 138 139 targetMatrix.RowNames = new[] { "Target" }; 140 targetMatrix.ColumnNames = variableNames; 141 142 return targetMatrix; 143 } 144 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 } 158 } 159 160 //adapted from RunCollectionVariableImpactView 161 private DoubleMatrix CalculateVariableImpactMatrix(IRun[] runs, string[] runNames) 162 { 163 IEnumerable<DoubleMatrix> allVariableImpacts = (from run in runs 164 select run.Results[variableImpactResultName]).Cast<DoubleMatrix>(); 165 IEnumerable<string> variableNames = (from variableImpact in allVariableImpacts 166 from variableName in variableImpact.RowNames 167 select variableName).Distinct(); 168 169 // filter variableNames: only include names that have at least one non-zero value in a run 170 List<string> variableNamesList = (from variableName in variableNames 171 where GetVariableImpacts(variableName, allVariableImpacts).Any(x => !x.IsAlmost(0.0)) 172 select variableName).ToList(); 173 174 List<string> columnNames = new List<string>(runNames); 175 columnNames.Add("Mean"); 176 177 int numberOfRuns = runs.Length; 178 179 DoubleMatrix matrix = new DoubleMatrix(variableNamesList.Count, numberOfRuns + 1); 180 matrix.SortableView = true; 181 matrix.ColumnNames = columnNames; 182 183 List<List<double>> variableImpactsOverRuns = (from variableName in variableNamesList 184 select GetVariableImpacts(variableName, allVariableImpacts).ToList()).ToList(); 185 186 for (int row = 0; row < variableImpactsOverRuns.Count; row++) 187 { 188 matrix[row, numberOfRuns] = Math.Round(variableImpactsOverRuns[row].Average(), 3); 189 } 190 191 // fill matrix with impacts from runs 192 for (int i = 0; i < runs.Length; i++) 193 { 194 IRun run = runs[i]; 195 DoubleMatrix runVariableImpacts = (DoubleMatrix)run.Results[variableImpactResultName]; 196 for (int j = 0; j < runVariableImpacts.Rows; j++) 197 { 198 int rowIndex = variableNamesList.FindIndex(s => s == runVariableImpacts.RowNames.ElementAt(j)); 199 if (rowIndex > -1) 200 { 201 matrix[rowIndex, i] = Math.Round(runVariableImpacts[j, 0], 3); 202 } 203 } 204 } 205 return matrix; 206 } 207 } 111 208 } -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.sln
r12198 r12229 11 11 EndProjectSection 12 12 EndProject 13 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.VariableInteractionNetworks.Views ", "HeuristicLab.VariableInteractionNetworks.Views\3.3\HeuristicLab.VariableInteractionNetworks.Views.csproj", "{EA1A0A27-A38D-4086-812A-9CE0FF557103}"13 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.VariableInteractionNetworks.Views-3.3", "HeuristicLab.VariableInteractionNetworks.Views\3.3\HeuristicLab.VariableInteractionNetworks.Views-3.3.csproj", "{EA1A0A27-A38D-4086-812A-9CE0FF557103}" 14 14 EndProject 15 15 Global -
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/TargetVariation.cs
r12198 r12229 35 35 { 36 36 var alg = (IAlgorithm)algorithm.Clone(); 37 var rp = (IRegressionProblem) alg.Problem; 38 var pd = rp.ProblemData; 37 var pd = ((IRegressionProblem)alg.Problem).ProblemData; 39 38 40 39 // check all input variables … … 47 46 pd.TargetVariable = pd.InputVariables[i].Value; 48 47 alg.Name += "{Target variable=" + pd.TargetVariable + "}"; 49 50 48 51 49 var batchrun = new BatchRun("Batchrun" + i) 52 50 {
Note: See TracChangeset
for help on using the changeset viewer.