Changeset 16966
- Timestamp:
- 05/20/19 16:33:14 (6 years ago)
- Location:
- branches/2288_HeuristicLab.VariableInteractionNetworks
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/HeuristicLab.VariableInteractionNetworks.Views-3.3.csproj
r16864 r16966 140 140 <SpecificVersion>False</SpecificVersion> 141 141 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Optimizer-3.3.dll</HintPath> 142 <Private>False</Private> 143 </Reference> 144 <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 145 <SpecificVersion>False</SpecificVersion> 146 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Persistence-3.3.dll</HintPath> 147 <Private>False</Private> 142 148 </Reference> 143 149 <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> -
branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/ImpactCalculator.cs
r16962 r16966 34 34 shuffledRows.ShuffleInPlace(new FastRandom(1234), partition.Start, partition.End); 35 35 36 for (int setSize = 1; setSize <= maxInteractions ; setSize++) {36 for (int setSize = 1; setSize <= maxInteractions && setSize <= variableNames.Count; setSize++) { 37 37 var combinations = HeuristicLab.Common.EnumerableExtensions.Combinations(variableNames, setSize) 38 38 .Where(comb => comb.Any(v => v == variableName)); // variable combinations that contain the selected variable -
branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/VariableInteractionNetwork.cs
r16864 r16966 37 37 public class VariableInteractionNetwork : DirectedGraph { 38 38 39 /// <summary> 40 /// Creates a simple network from a matrix of variable impacts (each row represents a target variable, each column represents an input variable) 41 /// For each target variable not more than one row can be defined (no junction nodes are build, cf. FromNmseAndVariableImpacts(..) for building more complex networks). 42 /// The network is acyclic. Values in the diagonal are ignored. 43 /// The algorithm starts with an empty network and incrementally adds next most relevant input variable for each target variable up to a given threshold 44 /// In each iteration cycles are broken by removing the weakest link. 45 /// </summary> 46 /// <param name="nmse">vector of NMSE values for each target variable</param> 47 /// <param name="variableImpacts">Variable impacts (smaller is lower impact). Row names and columns names should be set</param> 48 /// <param name="nmseThreshold">Threshold for NMSE values. Variables with a NMSE value larger than the threshold are considered as independent variables</param> 49 /// <param name="varImpactThreshold">Threshold for variable impact values. Impacts with a value smaller than the threshold are considered as independent</param> 50 /// <returns></returns> 51 public static VariableInteractionNetwork CreateSimpleNetwork(double[] nmse, DoubleMatrix variableImpacts, double nmseThreshold = 0.2, double varImpactThreshold = 0.0) { 39 public static VariableInteractionNetwork CreateSimpleNetwork(double[] nmse, DoubleMatrix variableImpacts, 40 double nmseThreshold = 0.2, double varImpactThreshold = 0.0) { 52 41 if (variableImpacts.Rows != variableImpacts.Columns) throw new ArgumentException(); 53 42 var network = new VariableInteractionNetwork(); … … 58 47 for (int i = 0; i < varNames.Length; i++) { 59 48 var name = varNames[i]; 60 var varVertex = new VariableNetworkNode() {Label = name, Weight = nmse[i]}; 49 var varVertex = new VariableNetworkNode() { Label = name, Weight = nmse[i] }; 50 network.AddVertex(varVertex); 51 if (nmse[i] < nmseThreshold) { 52 targets.Add(name, nmse[i]); 53 } 54 } 55 56 // rel is updated (impacts which are represented in the network are set to zero) 57 var impacts = variableImpacts.CloneAsMatrix(); 58 // make sure the diagonal is not considered 59 for (int i = 0; i < impacts.GetLength(0); i++) impacts[i, i] = double.NegativeInfinity; 60 61 62 for (int row = 0; row < impacts.GetLength(0); row++) { 63 if (!targets.ContainsKey(varNames[row])) continue; 64 65 var rowVector = Enumerable.Range(0, impacts.GetLength(0)).Select(col => impacts[row, col]).ToArray(); 66 for (int col = 0; col < rowVector.Length; col++) { 67 double impact = rowVector[col]; 68 if (impact > varImpactThreshold) { 69 var srcName = varNames[col]; 70 var dstName = varNames[row]; 71 var srcVertex = network.Vertices.Single(v => v.Label == srcName); 72 var dstVertex = network.Vertices.Single(v => v.Label == dstName); 73 var arc = network.AddArc(srcVertex, dstVertex); 74 arc.Weight = impact; 75 } 76 } 77 } 78 79 return network; 80 } 81 82 /// <summary> 83 /// Creates a simple network from a matrix of variable impacts (each row represents a target variable, each column represents an input variable) 84 /// For each target variable not more than one row can be defined (no junction nodes are build, cf. FromNmseAndVariableImpacts(..) for building more complex networks). 85 /// The network is acyclic. Values in the diagonal are ignored. 86 /// The algorithm starts with an empty network and incrementally adds next most relevant input variable for each target variable up to a given threshold 87 /// In each iteration cycles are broken by removing the weakest link. 88 /// </summary> 89 /// <param name="nmse">vector of NMSE values for each target variable</param> 90 /// <param name="variableImpacts">Variable impacts (smaller is lower impact). Row names and columns names should be set</param> 91 /// <param name="nmseThreshold">Threshold for NMSE values. Variables with a NMSE value larger than the threshold are considered as independent variables</param> 92 /// <param name="varImpactThreshold">Threshold for variable impact values. Impacts with a value smaller than the threshold are considered as independent</param> 93 /// <returns></returns> 94 public static VariableInteractionNetwork CreateSimpleAcyclicNetwork(double[] nmse, DoubleMatrix variableImpacts, double nmseThreshold = 0.2, double varImpactThreshold = 0.0) { 95 if (variableImpacts.Rows != variableImpacts.Columns) throw new ArgumentException(); 96 var network = new VariableInteractionNetwork(); 97 var targets = new Dictionary<string, double>(); 98 string[] varNames = variableImpacts.RowNames.ToArray(); 99 if (nmse.Length != varNames.Length) throw new ArgumentException(); 100 101 for (int i = 0; i < varNames.Length; i++) { 102 var name = varNames[i]; 103 var varVertex = new VariableNetworkNode() { Label = name, Weight = nmse[i] }; 61 104 network.AddVertex(varVertex); 62 105 if (nmse[i] < nmseThreshold) { … … 106 149 } 107 150 } 108 109 151 return newArcs; 110 152 } … … 351 393 if (arc.Target != null) { 352 394 var srcVarName = arc.Source.Label; 353 var dstVarName = arc.Target.Label; 395 var dstVarName = arc.Target.Label; 354 396 w[name2idx[dstVarName], name2idx[srcVarName]] = arc.Weight; 355 397 } … … 360 402 361 403 public string ToGraphVizString() { 362 Func<string, string> NodeAndEdgeColor = (str) => 363 { 404 Func<string, string> NodeAndEdgeColor = (str) => { 364 405 if (string.IsNullOrEmpty(str)) return "black"; 365 406 else if (str.Contains("removed")) return "red";
Note: See TracChangeset
for help on using the changeset viewer.