- Timestamp:
- 07/06/17 10:19:37 (7 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
- Property svn:mergeinfo changed
/branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views (added) merged: 14232,14238,14249,14251,14277,14497,14499,14591-14592
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r14186 r15131 48 48 } 49 49 50 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {51 return tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToDictionary(52 n => n,53 n => calculator.CalculateReplacementValue(Content.Model, n, Content.ProblemData, Content.ProblemData.TrainingIndices)54 );55 }56 57 protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree) {58 var values = CalculateImpactAndReplacementValues(tree);59 return values.ToDictionary(x => x.Key, x => x.Value.Item1);60 }61 50 62 51 protected override Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) { -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r14186 r15131 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 25 using System.Diagnostics.Contracts; 24 26 using System.Linq; 25 27 using HeuristicLab.Algorithms.DataAnalysis; … … 46 48 if (!problemData.TrainingIndices.Any()) return null; // don't create an LR model if the problem does not have a training set (e.g. loaded into an existing model) 47 49 48 //clear checked inputVariables 49 foreach (var inputVariable in problemData.InputVariables.CheckedItems) { 50 problemData.InputVariables.SetItemCheckedState(inputVariable.Value, false); 51 } 50 var usedVariables = Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 51 .OfType<IVariableTreeNode>() 52 .Select(node => node.VariableName).ToArray(); 52 53 53 //check inputVariables used in the symbolic regression model 54 var usedVariables = 55 Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<VariableTreeNode>().Select( 56 node => node.VariableName).Distinct(); 57 foreach (var variable in usedVariables) { 58 problemData.InputVariables.SetItemCheckedState( 59 problemData.InputVariables.First(x => x.Value == variable), true); 60 } 54 var usedDoubleVariables = usedVariables 55 .Where(name => problemData.Dataset.VariableHasType<double>(name)) 56 .Distinct(); 61 57 62 var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError); 58 var usedFactorVariables = usedVariables 59 .Where(name => problemData.Dataset.VariableHasType<string>(name)) 60 .Distinct(); 61 62 // gkronber: for binary factors we actually produce a binary variable in the new dataset 63 // but only if the variable is not used as a full factor anyway (LR creates binary columns anyway) 64 var usedBinaryFactors = 65 Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<BinaryFactorVariableTreeNode>() 66 .Where(node => !usedFactorVariables.Contains(node.VariableName)) 67 .Select(node => Tuple.Create(node.VariableValue, node.VariableValue)); 68 69 // create a new problem and dataset 70 var variableNames = 71 usedDoubleVariables 72 .Concat(usedFactorVariables) 73 .Concat(usedBinaryFactors.Select(t => t.Item1 + "=" + t.Item2)) 74 .Concat(new string[] { problemData.TargetVariable }) 75 .ToArray(); 76 var variableValues = 77 usedDoubleVariables.Select(name => (IList)problemData.Dataset.GetDoubleValues(name).ToList()) 78 .Concat(usedFactorVariables.Select(name => problemData.Dataset.GetStringValues(name).ToList())) 79 .Concat( 80 // create binary variable 81 usedBinaryFactors.Select(t => problemData.Dataset.GetReadOnlyStringValues(t.Item1).Select(val => val == t.Item2 ? 1.0 : 0.0).ToList()) 82 ) 83 .Concat(new[] { problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList() }); 84 85 var newDs = new Dataset(variableNames, variableValues); 86 var newProblemData = new RegressionProblemData(newDs, variableNames.Take(variableNames.Length - 1), variableNames.Last()); 87 newProblemData.TrainingPartition.Start = problemData.TrainingPartition.Start; 88 newProblemData.TrainingPartition.End = problemData.TrainingPartition.End; 89 newProblemData.TestPartition.Start = problemData.TestPartition.Start; 90 newProblemData.TestPartition.End = problemData.TestPartition.End; 91 92 var solution = LinearRegression.CreateLinearRegressionSolution(newProblemData, out rmse, out cvRmsError); 63 93 solution.Name = "Baseline (linear subset)"; 64 94 return solution; … … 68 98 protected override IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 69 99 foreach (var sol in base.CreateBaselineSolutions()) yield return sol; 100 101 // does not support lagged variables 102 if (Content.Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>().Any()) yield break; 103 70 104 yield return CreateLinearRegressionSolution(); 71 105 }
Note: See TracChangeset
for help on using the changeset viewer.