Changeset 15046
- Timestamp:
- 06/23/17 13:30:46 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Glmnet/3.4/ElasticNetLinearRegression.cs
r15023 r15046 88 88 } 89 89 90 90 private void CreateSolution(double lambda) { 91 91 double trainNMSE; 92 92 double testNMSE; 93 var coeff = C reateElasticNetLinearRegressionSolution(Problem.ProblemData, Penality, lambda, out trainNMSE, out testNMSE);93 var coeff = CalculateModelCoefficients(Problem.ProblemData, Penality, lambda, out trainNMSE, out testNMSE); 94 94 Results.Add(new Result("NMSE (train)", new DoubleValue(trainNMSE))); 95 95 Results.Add(new Result("NMSE (test)", new DoubleValue(testNMSE))); 96 96 97 var ds = Problem.ProblemData.Dataset; 98 var allVariables = Problem.ProblemData.AllowedInputVariables.ToArray(); 97 var solution = CreateSymbolicSolution(coeff, Problem.ProblemData); 98 Results.Add(new Result(solution.Name, solution.Description, solution)); 99 } 100 101 public static IRegressionSolution CreateSymbolicSolution(double[] coeff, IRegressionProblemData problemData) { 102 var ds = problemData.Dataset; 103 var allVariables = problemData.AllowedInputVariables.ToArray(); 99 104 var doubleVariables = allVariables.Where(ds.VariableHasType<double>); 100 105 var factorVariableNames = allVariables.Where(ds.VariableHasType<string>); … … 130 135 } 131 136 var tree = LinearModelToTreeConverter.CreateTree( 132 remainingFactorVariablesAndValues, factorCoeff.ToArray(), 137 remainingFactorVariablesAndValues, factorCoeff.ToArray(), 133 138 remainingDoubleVariables.ToArray(), doubleVarCoeff.ToArray(), 134 139 coeff.Last()); … … 136 141 137 142 SymbolicRegressionSolution solution = new SymbolicRegressionSolution( 138 new SymbolicRegressionModel( Problem.ProblemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter()),139 (IRegressionProblemData) Problem.ProblemData.Clone());143 new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), 144 (IRegressionProblemData)problemData.Clone()); 140 145 solution.Model.Name = "Elastic-net Linear Regression Model"; 141 146 solution.Name = "Elastic-net Linear Regression Solution"; 142 147 143 Results.Add(new Result(solution.Name, solution.Description, solution));148 return solution; 144 149 } 145 150 … … 242 247 } 243 248 244 public static double[] C reateElasticNetLinearRegressionSolution(IRegressionProblemData problemData, double penalty, double lambda,249 public static double[] CalculateModelCoefficients(IRegressionProblemData problemData, double penalty, double lambda, 245 250 out double trainNMSE, out double testNMSE, 246 251 double coeffLowerBound = double.NegativeInfinity, double coeffUpperBound = double.PositiveInfinity) { … … 248 253 double[] testNMSEs; 249 254 // run for exactly one lambda 250 var coeffs = C reateElasticNetLinearRegressionSolution(problemData, penalty, new double[] { lambda }, out trainNMSEs, out testNMSEs, coeffLowerBound, coeffUpperBound);255 var coeffs = CalculateModelCoefficients(problemData, penalty, new double[] { lambda }, out trainNMSEs, out testNMSEs, coeffLowerBound, coeffUpperBound); 251 256 trainNMSE = trainNMSEs[0]; 252 257 testNMSE = testNMSEs[0]; 253 258 return coeffs[0]; 254 259 } 255 public static double[][] C reateElasticNetLinearRegressionSolution(IRegressionProblemData problemData, double penalty, double[] lambda,260 public static double[][] CalculateModelCoefficients(IRegressionProblemData problemData, double penalty, double[] lambda, 256 261 out double[] trainNMSEs, out double[] testNMSEs, 257 262 double coeffLowerBound = double.NegativeInfinity, double coeffUpperBound = double.PositiveInfinity,
Note: See TracChangeset
for help on using the changeset viewer.