Changeset 14560 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
- Timestamp:
- 01/12/17 18:14:19 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r14259 r14560 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 using HeuristicLab.Optimization.Operators;31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 31 … … 52 51 while (dividend > 0) { 53 52 int modulo = (dividend - 1) % 26; 54 columnName = Convert.ToChar(65 + modulo) .ToString()+ columnName;53 columnName = Convert.ToChar(65 + modulo) + columnName; 55 54 dividend = (int)((dividend - modulo) / 26); 56 55 } … … 61 60 private readonly Dictionary<string, string> variableNameMapping = new Dictionary<string, string>(); 62 61 private int currentVariableIndex = 0; 63 private string GetColumnToVariableName(string var iabelName) {64 if (!variableNameMapping.ContainsKey(var iabelName)) {62 private string GetColumnToVariableName(string varName) { 63 if (!variableNameMapping.ContainsKey(varName)) { 65 64 currentVariableIndex++; 66 variableNameMapping.Add(var iabelName, GetExcelColumnName(currentVariableIndex));67 } 68 return string.Format("${0}1", variableNameMapping[var iabelName]);65 variableNameMapping.Add(varName, GetExcelColumnName(currentVariableIndex)); 66 } 67 return string.Format("${0}1", variableNameMapping[varName]); 69 68 } 70 69 public string Format(ISymbolicExpressionTree symbolicExpressionTree) { … … 75 74 public string Format(ISymbolicExpressionTree symbolicExpressionTree, IDataset dataset) { 76 75 var stringBuilder = new StringBuilder(); 77 if (dataset != null) CalculateVariableMapping(symbolicExpressionTree, dataset); 78 76 if (dataset != null) 77 return FormatWithMapping(symbolicExpressionTree, CalculateVariableMapping(symbolicExpressionTree, dataset)); 78 else return FormatWithMapping(symbolicExpressionTree, new Dictionary<string, string>()); 79 80 } 81 public string FormatWithMapping(ISymbolicExpressionTree symbolicExpressionTree, Dictionary<string,string> variableNameMapping) 82 { 83 foreach(var kvp in variableNameMapping) this.variableNameMapping.Add(kvp.Key,kvp.Value); 84 var stringBuilder = new StringBuilder(); 85 79 86 stringBuilder.Append("="); 80 87 stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root)); 81 88 82 foreach (var variable in variableNameMapping) {89 foreach (var variable in this.variableNameMapping) { 83 90 stringBuilder.AppendLine(); 84 91 stringBuilder.Append(variable.Key + " = " + variable.Value); … … 87 94 } 88 95 89 private voidCalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {90 int columnIndex = 0;96 private Dictionary<string,string> CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) { 97 var mapping = new Dictionary<string,string>(); 91 98 int inputIndex = 0; 92 var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct() ;99 var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct().ToArray(); 93 100 foreach (var variable in dataset.VariableNames) { 94 columnIndex++;95 101 if (!usedVariables.Contains(variable)) continue; 96 102 inputIndex++; 97 variableNameMapping[variable] = GetExcelColumnName(inputIndex); 98 } 103 mapping[variable] = GetExcelColumnName(inputIndex); 104 } 105 return mapping; 99 106 } 100 107 … … 192 199 stringBuilder.Append(variableTreeNode.Weight.ToString(CultureInfo.InvariantCulture)); 193 200 stringBuilder.Append("*"); 194 stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName)); // + LagToString(currentLag));201 stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName)); 195 202 } else if (symbol is BinaryFactorVariable) { 196 203 var binFactorNode = node as BinaryFactorVariableTreeNode;
Note: See TracChangeset
for help on using the changeset viewer.