- Timestamp:
- 09/28/16 12:53:51 (8 years ago)
- Location:
- branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Grammar.cs
r14310 r14311 19 19 20 20 public void Initialize() { 21 var func = new SimpleSymbol("Func", "The root for the blood glucose forecasting model.", 3, 3);21 // var func = new SimpleSymbol("Func", "The root for the blood glucose forecasting model.", 3, 3); 22 22 var exprGluc = new SimpleSymbol("ExprGluc", string.Empty, 1, 1); 23 var exprIns = new SimpleSymbol("ExprIns", string.Empty, 1, 1);24 var exprCh = new SimpleSymbol("ExprCh", string.Empty, 1, 1);23 // var exprIns = new SimpleSymbol("ExprIns", string.Empty, 1, 1); 24 // var exprCh = new SimpleSymbol("ExprCh", string.Empty, 1, 1); 25 25 26 26 // var predGlucData = new PredictedGlucoseVariableSymbol(); … … 39 39 40 40 // operators for exprCh 41 var plusCh = new SimpleSymbol("+Ch", "+", 2, 2);42 var minusCh = new SimpleSymbol("-Ch", "-", 2, 2);43 var prodCh = new SimpleSymbol("*Ch", "*", 2, 2);44 var divCh = new SimpleSymbol("/Ch", "/", 2, 2);45 var expCh = new SimpleSymbol("ExpCh", "Exp", 1, 1);46 var sinCh = new SimpleSymbol("SinCh", "Sin", 1, 1);47 var cosCh = new SimpleSymbol("CosCh", "Cos", 1, 1);48 var logCh = new SimpleSymbol("LogCh", "Log", 1, 1);41 // var plusCh = new SimpleSymbol("+Ch", "+", 2, 2); 42 // var minusCh = new SimpleSymbol("-Ch", "-", 2, 2); 43 // var prodCh = new SimpleSymbol("*Ch", "*", 2, 2); 44 // var divCh = new SimpleSymbol("/Ch", "/", 2, 2); 45 // var expCh = new SimpleSymbol("ExpCh", "Exp", 1, 1); 46 // var sinCh = new SimpleSymbol("SinCh", "Sin", 1, 1); 47 // var cosCh = new SimpleSymbol("CosCh", "Cos", 1, 1); 48 // var logCh = new SimpleSymbol("LogCh", "Log", 1, 1); 49 49 var curvedCh = new CurvedChVariableSymbol("CurvedCh", ""); 50 50 // var cteCh = new CteSymbol(); 51 51 52 52 // operators for exprIns 53 var plusIns = new SimpleSymbol("+Ins", "+", 2, 2);54 var minusIns = new SimpleSymbol("-Ins", "-", 2, 2);55 var prodIns = new SimpleSymbol("*Ins", "*", 2, 2);56 var divIns = new SimpleSymbol("/Ins", "/", 2, 2);57 var expIns = new SimpleSymbol("ExpIns", "Exp", 1, 1);58 var sinIns = new SimpleSymbol("SinIns", "Sin", 1, 1);59 var cosIns = new SimpleSymbol("CosIns", "Cos", 1, 1);60 var logIns = new SimpleSymbol("LogIns", "Log", 1, 1);53 // var plusIns = new SimpleSymbol("+Ins", "+", 2, 2); 54 // var minusIns = new SimpleSymbol("-Ins", "-", 2, 2); 55 // var prodIns = new SimpleSymbol("*Ins", "*", 2, 2); 56 // var divIns = new SimpleSymbol("/Ins", "/", 2, 2); 57 // var expIns = new SimpleSymbol("ExpIns", "Exp", 1, 1); 58 // var sinIns = new SimpleSymbol("SinIns", "Sin", 1, 1); 59 // var cosIns = new SimpleSymbol("CosIns", "Cos", 1, 1); 60 // var logIns = new SimpleSymbol("LogIns", "Log", 1, 1); 61 61 var curvedIns = new CurvedInsVariableSymbol("CurvedIns", ""); 62 62 // var realInsVar = new RealInsulineVariableSymbol(); … … 65 65 // var cteCh = new CteSymbol(); 66 66 67 AddSymbol(func);67 // AddSymbol(func); 68 68 AddSymbol(exprGluc); 69 AddSymbol(exprIns);70 AddSymbol(exprCh);69 // AddSymbol(exprIns); 70 // AddSymbol(exprCh); 71 71 // AddSymbol(predGlucData); 72 72 AddSymbol(realGlucData); … … 82 82 AddSymbol(curvedCh); 83 83 84 AddSymbol(plusCh);85 AddSymbol(minusCh);86 AddSymbol(prodCh);87 AddSymbol(divCh);88 AddSymbol(expCh);89 AddSymbol(sinCh);90 AddSymbol(cosCh);91 AddSymbol(logCh);84 // AddSymbol(plusCh); 85 // AddSymbol(minusCh); 86 // AddSymbol(prodCh); 87 // AddSymbol(divCh); 88 // AddSymbol(expCh); 89 // AddSymbol(sinCh); 90 // AddSymbol(cosCh); 91 // AddSymbol(logCh); 92 92 93 93 AddSymbol(curvedIns); 94 AddSymbol(plusIns);95 AddSymbol(minusIns);96 AddSymbol(prodIns);97 AddSymbol(divIns);98 AddSymbol(expIns);99 AddSymbol(sinIns);100 AddSymbol(cosIns);101 AddSymbol(logIns);94 // AddSymbol(plusIns); 95 // AddSymbol(minusIns); 96 // AddSymbol(prodIns); 97 // AddSymbol(divIns); 98 // AddSymbol(expIns); 99 // AddSymbol(sinIns); 100 // AddSymbol(cosIns); 101 // AddSymbol(logIns); 102 102 // AddSymbol(realInsVar); 103 103 AddSymbol(constSy); 104 104 105 105 // <func> ::= <exprgluc> + <exprch> - <exprins> 106 AddAllowedChildSymbol(func, exprGluc, 0);107 AddAllowedChildSymbol(func, exprCh, 1);108 AddAllowedChildSymbol(func, exprIns, 2);106 // AddAllowedChildSymbol(func, exprGluc, 0); 107 // AddAllowedChildSymbol(func, exprCh, 1); 108 // AddAllowedChildSymbol(func, exprIns, 2); 109 109 110 110 /* # Glucose … … 115 115 |realData(k-<idx2hOrMore>) 116 116 */ 117 var opGlucSet = new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc, expGluc, sinGluc, cosGluc, logGluc, /*predGlucData, */ realGlucData, constSy };117 var opGlucSet = new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc, expGluc, sinGluc, cosGluc, logGluc, /*predGlucData, */ realGlucData, constSy, curvedCh, curvedIns }; 118 118 foreach (var opGluc in opGlucSet) { 119 119 AddAllowedChildSymbol(exprGluc, opGluc); … … 152 152 |beta(0.02*Math.min(48,getPrevDataDistance(1,k,1)),5,2) 153 153 */ 154 var opChSet = new Symbol[] { plusCh, minusCh, prodCh, divCh, expCh, sinCh, cosCh, logCh, curvedCh, constSy };155 foreach (var opCh in opChSet) {156 AddAllowedChildSymbol(exprCh, opCh);157 }158 159 foreach (var parentOp in new Symbol[] { plusCh, minusCh, prodCh, divCh }) {160 foreach (var childOp in opChSet) {161 AddAllowedChildSymbol(parentOp, childOp, 0);162 AddAllowedChildSymbol(parentOp, childOp, 1);163 }164 }165 // <exprch> ::= <preop> (<exprch>)166 foreach (var parentOp in new Symbol[] { expCh, sinCh, cosCh, logCh }) {167 foreach (var childOp in opChSet) {168 AddAllowedChildSymbol(parentOp, childOp, 0);169 }170 }154 // var opChSet = new Symbol[] { plusCh, minusCh, prodCh, divCh, expCh, sinCh, cosCh, logCh, curvedCh, constSy }; 155 // foreach (var opCh in opChSet) { 156 // AddAllowedChildSymbol(exprCh, opCh); 157 // } 158 // 159 // foreach (var parentOp in new Symbol[] { plusCh, minusCh, prodCh, divCh }) { 160 // foreach (var childOp in opChSet) { 161 // AddAllowedChildSymbol(parentOp, childOp, 0); 162 // AddAllowedChildSymbol(parentOp, childOp, 1); 163 // } 164 // } 165 // // <exprch> ::= <preop> (<exprch>) 166 // foreach (var parentOp in new Symbol[] { expCh, sinCh, cosCh, logCh }) { 167 // foreach (var childOp in opChSet) { 168 // AddAllowedChildSymbol(parentOp, childOp, 0); 169 // } 170 // } 171 171 172 172 /* … … 192 192 193 193 */ 194 var opInsSet = new Symbol[] { plusIns, minusIns, prodIns, divIns, expIns, sinIns, cosIns, logIns, /* realInsVar, */ curvedIns, constSy };195 foreach (var opIns in opInsSet) {196 AddAllowedChildSymbol(exprIns, opIns);197 }198 199 // <exprins> ::= (<exprins> <op> <exprins>)200 // <exprins> ::= (<cte> <op> <exprins>)201 foreach (var parentOp in new Symbol[] { plusIns, minusIns, prodIns, divIns }) {202 foreach (var childOp in opInsSet) {203 AddAllowedChildSymbol(parentOp, childOp, 0);204 AddAllowedChildSymbol(parentOp, childOp, 1);205 }206 }207 // <exprins> ::= <preop> (<exprins>)208 foreach (var op in new Symbol[] { expIns, sinIns, cosIns, logIns }) {209 foreach (var childOp in opInsSet) {210 AddAllowedChildSymbol(op, childOp, 0);211 }212 }213 214 // root is func215 AddAllowedChildSymbol(StartSymbol, func);194 // var opInsSet = new Symbol[] { plusIns, minusIns, prodIns, divIns, expIns, sinIns, cosIns, logIns, /* realInsVar, */ curvedIns, constSy }; 195 // foreach (var opIns in opInsSet) { 196 // AddAllowedChildSymbol(exprIns, opIns); 197 // } 198 // 199 // // <exprins> ::= (<exprins> <op> <exprins>) 200 // // <exprins> ::= (<cte> <op> <exprins>) 201 // foreach (var parentOp in new Symbol[] { plusIns, minusIns, prodIns, divIns }) { 202 // foreach (var childOp in opInsSet) { 203 // AddAllowedChildSymbol(parentOp, childOp, 0); 204 // AddAllowedChildSymbol(parentOp, childOp, 1); 205 // } 206 // } 207 // // <exprins> ::= <preop> (<exprins>) 208 // foreach (var op in new Symbol[] { expIns, sinIns, cosIns, logIns }) { 209 // foreach (var childOp in opInsSet) { 210 // AddAllowedChildSymbol(op, childOp, 0); 211 // } 212 // } 213 214 // root is exprGluc 215 AddAllowedChildSymbol(StartSymbol, exprGluc); 216 216 } 217 217 -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Interpreter.cs
r14310 r14311 31 31 var predictions = new double[targetGluc.Length]; 32 32 var rowsEnumerator = rows.GetEnumerator(); 33 rowsEnumerator.MoveNext(); 33 34 for (int k = 0; k < predictions.Length; k++, rowsEnumerator.MoveNext()) { 34 35 if (double.IsNaN(targetGluc[k])) { … … 36 37 } else { 37 38 var rawPred = InterpretRec(model, data, rowsEnumerator.Current); 38 predictions[k] = rawPred; 39 predictions[k] = rawPred; 39 40 } 40 41 } … … 61 62 // d Q1 / dt = ins(t) - alpha * Q1(t) 62 63 // d Q2 / dt = alpha * (Q1(t) - Q2(t)) 63 // S = Q1(t) + Q2(t)64 // d Q3 / dt = alpha * Q2(t) - beta * Q3(t) 64 65 var alpha = node.Alpha; 66 var beta = node.Beta; 65 67 66 68 var ins = dataset.GetReadOnlyDoubleValues("Insuline"); 67 69 var time = dataset.GetReadOnlyDoubleValues("HourMin").ToArray(); 68 70 69 // TODO reset for new time intervals 70 71 double q1, q2, q1_prev, q2_prev; 71 double q1, q2, q3, q1_prev, q2_prev, q3_prev; 72 72 // starting values: zeros 73 q1 = q2 = q 1_prev = q2_prev = 0;73 q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0; 74 74 double[] s = new double[dataset.Rows]; 75 75 76 76 for (int t = 1; t < dataset.Rows; t++) { 77 77 if (IsStartOfNewPeriod(time, t)) { 78 q1 = q2 = q 1_prev = q2_prev = 0;78 q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0; 79 79 } 80 80 q1 = q1_prev + ins[t] - alpha * q1_prev; 81 81 q2 = q2_prev + alpha * (q1_prev - q2_prev); 82 s[t] = q1 + q2; 82 q3 = q3_prev + alpha * q2_prev - beta * q3_prev; 83 s[t] = q3; 83 84 q1_prev = q1; 84 85 q2_prev = q2; 86 q3_prev = q3; 85 87 86 88 } … … 97 99 // d Q1 / dt = ins(t) - alpha * Q1(t) 98 100 // d Q2 / dt = alpha * (Q1(t) - Q2(t)) 99 // S = Q1(t) + Q2(t)101 // d Q3 / dt = alpha * Q2(t) - beta * Q3(t) 100 102 var alpha = node.Alpha; 101 102 var ch = dataset.GetReadOnlyDoubleValues("CH"); 103 var beta = node.Beta; 104 105 var ins = dataset.GetReadOnlyDoubleValues("CH"); 103 106 var time = dataset.GetReadOnlyDoubleValues("HourMin").ToArray(); 104 107 105 // TODO reset for new time intervals 106 107 double q1, q2, q1_prev, q2_prev; 108 double q1, q2, q3, q1_prev, q2_prev, q3_prev; 108 109 // starting values: zeros 109 q1 = q2 = q 1_prev = q2_prev = 0;110 q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0; 110 111 double[] s = new double[dataset.Rows]; 111 112 112 113 for (int t = 1; t < dataset.Rows; t++) { 113 114 if (IsStartOfNewPeriod(time, t)) { 114 q1 = q2 = q 1_prev = q2_prev = 0;115 } 116 q1 = q1_prev + ch[t] - alpha * q1_prev;115 q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0; 116 } 117 q1 = q1_prev + ins[t] - alpha * q1_prev; 117 118 q2 = q2_prev + alpha * (q1_prev - q2_prev); 118 s[t] = q1 + q2; 119 q3 = q3_prev + alpha * q2_prev - beta * q3_prev; 120 s[t] = q3; 119 121 q1_prev = q1; 120 122 q2_prev = q2; 123 q3_prev = q3; 121 124 122 125 } … … 206 209 } 207 210 208 private static double Beta(double x, double alpha, double beta) {209 return 1.0 / alglib.beta(alpha, beta) * Math.Pow(x, alpha - 1) * Math.Pow(1 - x, beta - 1);210 }211 211 } 212 212 } -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Model.cs
r14310 r14311 18 18 public sealed class Model : NamedItem, IRegressionModel { 19 19 [Storable] 20 private readonly IRegressionProblemData problemData;21 [Storable]22 20 private readonly ISymbolicExpressionTree tree; 23 21 [Storable] … … 26 24 private string[] variablesUsedForPrediction; 27 25 26 [StorableConstructor] 27 private Model(bool deserializing) : base(deserializing) { 28 } 29 28 30 private Model(Model original, Cloner cloner) { 29 this.problemData = cloner.Clone(original.problemData);30 31 this.tree = cloner.Clone(original.tree); 31 32 this.variablesUsedForPrediction = original.variablesUsedForPrediction; … … 33 34 } 34 35 35 public Model(IRegressionProblemData problemData, ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) { 36 this.problemData = problemData; 36 public Model(ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) { 37 37 this.tree = tree; 38 38 this.variablesUsedForPrediction = variablesUsedForPrediction; … … 45 45 46 46 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 47 return Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), problemData.Dataset, rows);47 return Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), dataset, rows); 48 48 } 49 49 -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Problem.cs
r14310 r14311 32 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 33 using HeuristicLab.Problems.DataAnalysis; 34 using HeuristicLab.Problems.DataAnalysis.Symbolic; 34 35 using HeuristicLab.Problems.Instances; 35 36 … … 98 99 public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) { 99 100 var problemData = ProblemData; 100 var rows = problemData.TrainingIndices.ToArray(); 101 var target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 102 var predicted0 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(0), problemData.Dataset, rows); 103 var predicted1 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(1), problemData.Dataset, rows); 104 var predicted2 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(2), problemData.Dataset, rows); 105 106 var pred0_rsq = Rsq(predicted0, target); 107 var pred1_rsq = Rsq(predicted1, target); 108 var pred2_rsq = Rsq(predicted2, target); 109 return pred0_rsq + pred1_rsq + pred2_rsq; 101 var target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices); 102 var allPredicted = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), problemData.Dataset, problemData.AllIndices).ToArray(); 103 var predicted = problemData.TrainingIndices.Select(r => allPredicted[r]); 104 105 // var predicted1 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(1), problemData.Dataset, rows); 106 // var predicted2 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(2), problemData.Dataset, rows); 107 108 var pred0_rsq = Rsq(predicted, target); 109 // var pred1_rsq = Rsq(predicted1, target); 110 // var pred2_rsq = Rsq(predicted2, target); 111 return pred0_rsq; // + pred1_rsq + pred2_rsq; 110 112 } 111 113 … … 129 131 results.Add(new Result("Solution", typeof(IRegressionSolution))); 130 132 } 131 if (!results.ContainsKey(" Terms")) {132 results.Add(new Result(" Terms", typeof(DataTable)));133 if (!results.ContainsKey("ScaledTree")) { 134 results.Add(new Result("ScaledTree", typeof(ISymbolicExpressionTree))); 133 135 } 136 // if (!results.ContainsKey("Terms")) { 137 // results.Add(new Result("Terms", typeof(DataTable))); 138 // } 134 139 135 140 var bestTree = trees.First(); … … 142 147 } 143 148 144 145 var clonedProblemData = (IRegressionProblemData)ProblemData.Clone(); 146 var rows = clonedProblemData.TrainingIndices.ToArray(); 147 var target = clonedProblemData.Dataset.GetDoubleValues(clonedProblemData.TargetVariable, rows).ToArray(); 148 var predicted0 = 149 Interpreter.Apply(bestTree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(0), clonedProblemData.Dataset, rows) 149 bestTree = (ISymbolicExpressionTree)bestTree.Clone(); 150 var expressionNode = bestTree.Root.GetSubtree(0).GetSubtree(0); 151 // scale 152 153 var problemData = ProblemData; 154 var rows = problemData.AllIndices.ToArray(); 155 var target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows).ToArray(); 156 var predicted = 157 Interpreter.Apply(expressionNode.GetSubtree(0), problemData.Dataset, rows) 150 158 .ToArray(); 151 var predicted1 = 152 Interpreter.Apply(bestTree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(1), clonedProblemData.Dataset, rows) 153 .ToArray(); 154 var predicted2 = 155 Interpreter.Apply(bestTree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(2), clonedProblemData.Dataset, rows) 156 .ToArray(); 157 158 var termsTable = new HeuristicLab.Analysis.DataTable("Terms"); 159 var r0 = new DataRow("GlucTerm", "GlucTerm", predicted0); 160 var r1 = new DataRow("InsTerm", "InsTerm", predicted1); 161 r1.VisualProperties.SecondYAxis = true; 162 var r2 = new DataRow("ChTerm", "ChTerm", predicted2); 163 r2.VisualProperties.SecondYAxis = true; 164 var r3 = new DataRow("Target", "Target", target); 165 termsTable.Rows.Add(r0); 166 termsTable.Rows.Add(r1); 167 termsTable.Rows.Add(r2); 168 termsTable.Rows.Add(r3); 169 results["Terms"].Value = termsTable; 170 171 172 var filteredPredicted0 = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted0[r]).ToArray(); 173 var filteredPredicted1 = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted1[r]).ToArray(); 174 var filteredPredicted2 = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted2[r]).ToArray(); 159 160 var filteredPredicted = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted[r]).ToArray(); 175 161 var filteredTarget = target.Where(t => !double.IsNaN(t)).ToArray(); 176 177 178 var ds = new ModifiableDataset(new string[] { "pred0", "pred1", "pred2", "target" }, 179 new List<IList> 180 { 181 filteredPredicted0.ToList(), 182 filteredPredicted1.ToList(), 183 filteredPredicted2.ToList(), 184 filteredTarget.ToList() 185 }); 186 var lrProbData = new RegressionProblemData(ds, new string[] { "pred0", "pred1", "pred2" }, "target"); 187 lrProbData.TrainingPartition.Start = clonedProblemData.TrainingPartition.Start; 188 lrProbData.TrainingPartition.End = clonedProblemData.TrainingPartition.End; 189 lrProbData.TestPartition.Start = clonedProblemData.TestPartition.Start; 190 lrProbData.TestPartition.End = clonedProblemData.TestPartition.End; 191 192 try { 193 double rmsError, cvRmsError; 194 var lrSolution = HeuristicLab.Algorithms.DataAnalysis.LinearRegression.CreateLinearRegressionSolution( 195 lrProbData, out rmsError, out cvRmsError); 196 results["Solution"].Value = lrSolution; 197 } catch (Exception) { 198 // ignore 199 } 162 OnlineCalculatorError error; 163 double alpha; 164 double beta; 165 OnlineLinearScalingParameterCalculator.Calculate(filteredPredicted, filteredTarget, out alpha, out beta, out error); 166 167 var prod = new SimpleSymbol("*", "*", 2, 2).CreateTreeNode(); 168 var sum = new SimpleSymbol("+", "+", 2, 2).CreateTreeNode(); 169 var constAlpha = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 170 constAlpha.Value = alpha; 171 var constBeta = (ConstantTreeNode)(new Constant()).CreateTreeNode(); 172 constBeta.Value = beta; 173 174 var originalTree = expressionNode.GetSubtree(0); 175 expressionNode.RemoveSubtree(0); 176 expressionNode.AddSubtree(sum); 177 sum.AddSubtree(prod); 178 sum.AddSubtree(constAlpha); 179 prod.AddSubtree(originalTree); 180 prod.AddSubtree(constBeta); 181 182 var model = new Model(bestTree, problemData.TargetVariable, problemData.AllowedInputVariables.ToArray()); 183 model.Name = "Scaled Model"; 184 model.Description = "Scaled Model"; 185 results["Solution"].Value = model.CreateRegressionSolution(problemData); 186 results["ScaledTree"].Value = bestTree; 187 200 188 } 201 189 -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Solution.cs
r13867 r14311 132 132 } 133 133 public IEnumerable<double> EstimatedTrainingValues { 134 get { return GetEstimatedValues(ProblemData.TrainingIndices); } 134 get { 135 var all = EstimatedValues.ToArray(); 136 return ProblemData.TrainingIndices.Select(r => all[r]); 137 } 135 138 } 136 139 public IEnumerable<double> EstimatedTestValues { 137 get { return GetEstimatedValues(ProblemData.TestIndices); } 140 get { 141 var all = EstimatedValues.ToArray(); 142 return ProblemData.TestIndices.Select(r => all[r]); 143 } 138 144 } 139 145 140 146 public IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 141 return Model.GetEstimatedValues(ProblemData.Dataset, rows); 147 var all = Model.GetEstimatedValues(ProblemData.Dataset, ProblemData.AllIndices).ToArray(); 148 return rows.Select(r => all[r]); 142 149 } 143 150
Note: See TracChangeset
for help on using the changeset viewer.