Changeset 14238 for branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
- Timestamp:
- 08/05/16 17:34:16 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r14185 r14238 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Diagnostics.Contracts; 24 25 using System.Linq; 25 26 using HeuristicLab.Algorithms.DataAnalysis; … … 46 47 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 48 48 //clear checked inputVariables 49 foreach (var inputVariable in problemData.InputVariables.CheckedItems) { 50 problemData.InputVariables.SetItemCheckedState(inputVariable.Value, false); 51 } 49 var usedDoubleVariables = 50 Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 51 .OfType<VariableTreeNode>() 52 .Select(node => node.VariableName) 53 .Concat( 54 Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 55 .OfType<VariableConditionTreeNode>() 56 .Select(node => node.VariableName) 57 ) 58 .Distinct(); 52 59 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 } 60 var usedFactorVariables = 61 Content.Model.SymbolicExpressionTree.IterateNodesPostfix() 62 .OfType<FactorVariableTreeNode>() 63 .Select(node => Tuple.Create(node.VariableName, node.VariableValue)) 64 .Distinct(); 61 65 62 var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError); 66 // create a new problem and dataset 67 var variableNames = 68 usedDoubleVariables 69 .Concat(usedFactorVariables.Select(t => t.Item1 + "=" + t.Item2)) 70 .Concat(new string[] { problemData.TargetVariable }) 71 .ToArray(); 72 var variableValues = 73 usedDoubleVariables.Select(name => problemData.Dataset.GetDoubleValues(name).ToList()) 74 .Concat( 75 // create binary variable 76 usedFactorVariables.Select(t => problemData.Dataset.GetReadOnlyStringValues(t.Item1).Select(val => val == t.Item2 ? 1.0 : 0.0).ToList()) 77 ) 78 .Concat(new[] { problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList() }); 79 80 var newDs = new Dataset(variableNames, variableValues); 81 var newProblemData = new RegressionProblemData(newDs, variableNames.Take(variableNames.Length - 1), variableNames.Last()); 82 newProblemData.TrainingPartition.Start = problemData.TrainingPartition.Start; 83 newProblemData.TrainingPartition.End = problemData.TrainingPartition.End; 84 newProblemData.TestPartition.Start = problemData.TestPartition.Start; 85 newProblemData.TestPartition.End = problemData.TestPartition.End; 86 87 var solution = LinearRegression.CreateLinearRegressionSolution(newProblemData, out rmse, out cvRmsError); 63 88 solution.Name = "Baseline (linear subset)"; 64 89 return solution; … … 68 93 protected override IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 69 94 foreach (var sol in base.CreateBaselineSolutions()) yield return sol; 95 96 // does not support lagged variables 97 if (Content.Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>().Any()) yield break; 98 70 99 yield return CreateLinearRegressionSolution(); 71 100 }
Note: See TracChangeset
for help on using the changeset viewer.