Changeset 14251 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SolutionComparisonView.cs
- Timestamp:
- 08/10/16 20:10:25 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SolutionComparisonView.cs
r14249 r14251 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.Linq; … … 53 54 if (!problemData.TrainingIndices.Any()) return null; // don't create an comparison models if the problem does not have a training set (e.g. loaded into an existing model) 54 55 55 var usedDoubleVariables = 56 symbolicSolution.Model.SymbolicExpressionTree.IterateNodesPostfix() 57 .OfType<VariableTreeNode>() 58 .Select(node => node.VariableName) 59 .Concat( 60 symbolicSolution.Model.SymbolicExpressionTree.IterateNodesPostfix() 61 .OfType<VariableConditionTreeNode>() 62 .Select(node => node.VariableName) 63 ) 56 var usedVariables = Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 57 .OfType<IVariableTreeNode>() 58 .Select(node => node.VariableName).ToArray(); 59 60 var usedDoubleVariables = usedVariables 61 .Where(name => problemData.Dataset.VariableHasType<double>(name)) 64 62 .Distinct(); 65 63 66 var usedFactorVariables = 67 symbolicSolution.Model.SymbolicExpressionTree.IterateNodesPostfix() 68 .OfType<BinaryFactorVariableTreeNode>() 69 .Select(node => Tuple.Create(node.VariableName, node.VariableValue)) 64 var usedFactorVariables = usedVariables 65 .Where(name => problemData.Dataset.VariableHasType<string>(name)) 70 66 .Distinct(); 67 68 // gkronber: for binary factors we actually produce a binary variable in the new dataset 69 // but only if the variable is not used as a full factor anyway (LR creates binary columns anyway) 70 var usedBinaryFactors = 71 Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<BinaryFactorVariableTreeNode>() 72 .Where(node => !usedFactorVariables.Contains(node.VariableName)) 73 .Select(node => Tuple.Create(node.VariableValue, node.VariableValue)); 71 74 72 75 // create a new problem and dataset 73 76 var variableNames = 74 77 usedDoubleVariables 75 .Concat(usedFactorVariables.Select(t => t.Item1 + "=" + t.Item2)) 78 .Concat(usedFactorVariables) 79 .Concat(usedBinaryFactors.Select(t => t.Item1 + "=" + t.Item2)) 76 80 .Concat(new string[] { problemData.TargetVariable }) 77 81 .ToArray(); 78 82 var variableValues = 79 usedDoubleVariables.Select(name => problemData.Dataset.GetDoubleValues(name).ToList()) 83 usedDoubleVariables.Select(name => (IList)problemData.Dataset.GetDoubleValues(name).ToList()) 84 .Concat(usedFactorVariables.Select(name => problemData.Dataset.GetStringValues(name).ToList())) 80 85 .Concat( 81 // create binary variable82 used FactorVariables.Select(t => problemData.Dataset.GetReadOnlyStringValues(t.Item1).Select(val => val == t.Item2 ? 1.0 : 0.0).ToList())86 // create binary variable 87 usedBinaryFactors.Select(t => problemData.Dataset.GetReadOnlyStringValues(t.Item1).Select(val => val == t.Item2 ? 1.0 : 0.0).ToList()) 83 88 ) 84 89 .Concat(new[] { problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList() });
Note: See TracChangeset
for help on using the changeset viewer.