Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views
- Property svn:mergeinfo changed
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionErrorCharacteristicsCurveView.cs
r13003 r15973 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.Linq; … … 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 usedVariables = Content.Model.VariablesUsedForPrediction; 52 50 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 } 51 var usedDoubleVariables = usedVariables 52 .Where(name => problemData.Dataset.VariableHasType<double>(name)) 53 .Distinct(); 61 54 62 var solution = LinearRegression.CreateLinearRegressionSolution(problemData, out rmse, out cvRmsError); 55 var usedFactorVariables = usedVariables 56 .Where(name => problemData.Dataset.VariableHasType<string>(name)) 57 .Distinct(); 58 59 // gkronber: for binary factors we actually produce a binary variable in the new dataset 60 // but only if the variable is not used as a full factor anyway (LR creates binary columns anyway) 61 var usedBinaryFactors = 62 Content.Model.SymbolicExpressionTree.IterateNodesPostfix().OfType<BinaryFactorVariableTreeNode>() 63 .Where(node => !usedFactorVariables.Contains(node.VariableName)) 64 .Select(node => Tuple.Create(node.VariableValue, node.VariableValue)); 65 66 // create a new problem and dataset 67 var variableNames = 68 usedDoubleVariables 69 .Concat(usedFactorVariables) 70 .Concat(usedBinaryFactors.Select(t => t.Item1 + "=" + t.Item2)) 71 .Concat(new string[] { problemData.TargetVariable }) 72 .ToArray(); 73 var variableValues = 74 usedDoubleVariables.Select(name => (IList)problemData.Dataset.GetDoubleValues(name).ToList()) 75 .Concat(usedFactorVariables.Select(name => problemData.Dataset.GetStringValues(name).ToList())) 76 .Concat( 77 // create binary variable 78 usedBinaryFactors.Select(t => problemData.Dataset.GetReadOnlyStringValues(t.Item1).Select(val => val == t.Item2 ? 1.0 : 0.0).ToList()) 79 ) 80 .Concat(new[] { problemData.Dataset.GetDoubleValues(problemData.TargetVariable).ToList() }); 81 82 var newDs = new Dataset(variableNames, variableValues); 83 var newProblemData = new RegressionProblemData(newDs, variableNames.Take(variableNames.Length - 1), variableNames.Last()); 84 newProblemData.TrainingPartition.Start = problemData.TrainingPartition.Start; 85 newProblemData.TrainingPartition.End = problemData.TrainingPartition.End; 86 newProblemData.TestPartition.Start = problemData.TestPartition.Start; 87 newProblemData.TestPartition.End = problemData.TestPartition.End; 88 89 var solution = LinearRegression.CreateLinearRegressionSolution(newProblemData, out rmse, out cvRmsError); 63 90 solution.Name = "Baseline (linear subset)"; 64 91 return solution; … … 68 95 protected override IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 69 96 foreach (var sol in base.CreateBaselineSolutions()) yield return sol; 97 98 // does not support lagged variables 99 if (Content.Model.SymbolicExpressionTree.IterateNodesPrefix().OfType<LaggedVariableTreeNode>().Any()) yield break; 100 70 101 yield return CreateLinearRegressionSolution(); 71 102 }
Note: See TracChangeset
for help on using the changeset viewer.