Changeset 12568 for branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/VariableInteractionNetworkView.cs
- Timestamp:
- 07/01/15 21:06:50 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/VariableInteractionNetworkView.cs
r12321 r12568 87 87 { 88 88 // TODO: Add code when content has been changed and is not null 89 viewHost2.Content = CalculateNodeImportance(CalculateAdjacencyMatrix()); 89 viewHost2.Content = CalculateNodeImportance(CalculateAdjacencyMatrix()); 90 90 var adjMatrix = CalculateAdjacencyMatrix(); 91 91 viewHost1.Content = adjMatrix; … … 110 110 { 111 111 var runCollection = Content; 112 var groupRunCollection = Content.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList(); 112 var inputVariables = ((IRegressionProblemData)runCollection.First().Parameters["ProblemData"]).InputVariables.Select(x => x.Value).ToList(); 113 var groupRunCollection = Content.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).OrderBy(x => inputVariables.IndexOf(x.Key)).ToList(); 113 114 114 115 var allVariableImpacts = runCollection.Select(run => (DoubleMatrix)run.Results[variableImpactResultName]); … … 116 117 from variableName in variableImpact.RowNames 117 118 select variableName).Distinct().ToArray(); 119 120 var vars = new List<Tuple<int, string>>(); 121 122 var allowedInputs = ((IRegressionProblemData)groupRunCollection[0].First().Parameters["ProblemData"]).AllowedInputVariables.ToList(); 123 118 124 var adjMatrix = new DoubleMatrix(variableNames.Length, variableNames.Length); 119 125 120 adjMatrix.RowNames = groupRunCollection.Select(x => x.Key); 126 for (int i = 0; i < adjMatrix.Rows; ++i) 127 { 128 int inputIndex = allowedInputs.FindIndex(x => x == variableNames[i]); 129 vars.Add(new Tuple<int, string>(inputIndex, variableNames[i])); 130 } 131 132 vars.Sort((a, b) => a.Item1.CompareTo(b.Item1)); 133 134 for (int i = 0; i < adjMatrix.Rows; ++i) 135 { 136 variableNames[i] = vars[i].Item2; 137 } 138 adjMatrix.RowNames = variableNames; 121 139 adjMatrix.ColumnNames = adjMatrix.RowNames; 140 122 141 for (int j = 0; j < groupRunCollection.Count; ++j) 123 142 { 124 143 var g = groupRunCollection[j]; 144 125 145 var matrix = CalculateAdjacencyRows(g); 126 var variables = new List<Tuple<string, double>>(); 127 var columnNames = matrix.ColumnNames.ToList(); 146 var variables = new List<double>(); 128 147 129 148 for (int i = 0; i < matrix.Columns; ++i) 130 149 { 131 variables.Add(new Tuple<string, double>(columnNames[i], matrix[0, i])); 132 } 133 variables.Add(new Tuple<string, double>(g.Key, 0)); 134 variables.Sort((a, b) => a.Item1.CompareTo(b.Item1)); 150 variables.Add(matrix[0, i]); 151 } 152 135 153 for (int i = 0; i < variables.Count; ++i) 136 154 { 137 adjMatrix[j, i] = variables[i].Item2; 138 155 if (i == j) 156 { 157 adjMatrix[i, i] = 0; 158 variables.Insert(i, 0); 159 } 160 else 161 adjMatrix[j, i] = variables[i]; 139 162 } 140 163 } … … 144 167 private DoubleMatrix CalculateAdjacencyRows(IEnumerable<IRun> runs) 145 168 { 146 IEnumerable<DoubleMatrix> allVariableImpacts = (from run in runs147 select run.Results[variableImpactResultName]).Cast<DoubleMatrix>();148 var variableNames = (from variableImpact in allVariableImpacts149 from variableName in variableImpact.RowNames150 select variableName).Distinct().ToArray();151 152 List<string> variableNamesList = (from variableName in variableNames153 where GetVariableImpacts(variableName, allVariableImpacts).Any(x => !x.IsAlmost(0.0))154 select variableName)155 .ToList();156 157 169 var runNames = runs.Select(x => x.Name).ToArray(); 158 170 var runsArray = runs.ToArray(); 159 171 DoubleMatrix varImpactMatrix = CalculateVariableImpactMatrix(runsArray, runNames); 160 var targetMatrix = new DoubleMatrix(1, variableNames.Length); 172 173 var targetMatrix = new DoubleMatrix(1, varImpactMatrix.Rows); 161 174 162 175 for (int i = 0; i < varImpactMatrix.Rows; ++i) … … 165 178 } 166 179 167 targetMatrix.RowNames = new[] { "Target" }; 168 targetMatrix.ColumnNames = variableNames; 169 180 targetMatrix.RowNames = new[] { "Impacts" }; 181 targetMatrix.ColumnNames = varImpactMatrix.RowNames; 170 182 return targetMatrix; 171 183 } … … 262 274 } 263 275 264 // adapted from RunCollectionVariableImpactView276 //modified from RunCollectionVariableImpactView 265 277 private DoubleMatrix CalculateVariableImpactMatrix(IRun[] runs, string[] runNames) 266 278 { … … 307 319 } 308 320 } 309 return matrix; 321 322 // sort by median 323 var sortedMatrix = (DoubleMatrix)matrix.Clone(); 324 var sortedIndexes = from i in Enumerable.Range(0, sortedMatrix.Rows) 325 orderby matrix[i, numberOfRuns] 326 select i; 327 328 int targetIndex = 0; 329 foreach (var sourceIndex in sortedIndexes) 330 { 331 for (int c = 0; c < matrix.Columns; c++) 332 sortedMatrix[targetIndex, c] = matrix[sourceIndex, c]; 333 targetIndex++; 334 } 335 sortedMatrix.RowNames = sortedIndexes.Select(i => variableNamesList[i]); 336 337 var vars = new List<Tuple<int, string, double>>(); 338 var rowNames = sortedMatrix.RowNames.ToList(); 339 340 var groupRunCollection = Content.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList(); 341 var inputs = ((IRegressionProblemData)groupRunCollection[0].First().Parameters["ProblemData"]).InputVariables.ToList(); 342 List<string> inp = (from input in inputs 343 select (input.ToString())).ToList(); 344 345 for (int i = 0; i < sortedMatrix.Rows; ++i) 346 { 347 int inputIndex = inp.FindIndex(x => x == rowNames[i]); 348 vars.Add(new Tuple<int, string, double>(inputIndex, rowNames[i], sortedMatrix[i, runNames.Length])); 349 } 350 351 vars.Sort((a, b) => a.Item1.CompareTo(b.Item1)); 352 353 for (int i = 0; i < sortedMatrix.Rows; ++i) 354 { 355 sortedMatrix[i, runNames.Length] = vars[i].Item3; 356 rowNames[i] = vars[i].Item2; 357 } 358 sortedMatrix.RowNames = rowNames; 359 360 return sortedMatrix; 310 361 } 311 362
Note: See TracChangeset
for help on using the changeset viewer.