Changeset 13867
- Timestamp:
- 05/31/16 17:05:49 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedChVariableSymbol.cs
r13865 r13867 34 34 #region Properties 35 35 36 [Storable]37 private double alpha;38 public double Alpha {39 get { return alpha; }40 set {41 if (value != alpha) {42 alpha = value;43 OnChanged(EventArgs.Empty);44 }45 }46 }47 48 [Storable]49 private double beta;50 public double Beta {51 get { return beta; }52 set {53 if (value != beta) {54 alpha = value;55 OnChanged(EventArgs.Empty);56 }57 }58 }59 60 36 private const int minimumArity = 0; 61 37 private const int maximumArity = 0; … … 70 46 #endregion 71 47 48 [Storable] 49 private double minAlpha; 50 public double MinAlpha { 51 get { return minAlpha; } 52 set { 53 if (value != minAlpha) { 54 minAlpha = value; 55 OnChanged(EventArgs.Empty); 56 } 57 } 58 } 59 [Storable] 60 private double maxAlpha; 61 public double MaxAlpha { 62 get { return maxAlpha; } 63 set { 64 if (value != maxAlpha) { 65 maxAlpha = value; 66 OnChanged(EventArgs.Empty); 67 } 68 } 69 } 70 71 [Storable] 72 private double minBeta; 73 public double MinBeta { 74 get { return minBeta; } 75 set { 76 if (value != minBeta) { 77 minBeta = value; 78 OnChanged(EventArgs.Empty); 79 } 80 } 81 } 82 83 [Storable] 84 private double maxBeta; 85 public double MaxBeta { 86 get { return maxBeta; } 87 set { 88 if (value != maxBeta) { 89 maxBeta = value; 90 OnChanged(EventArgs.Empty); 91 } 92 } 93 } 72 94 [StorableHook(HookType.AfterDeserialization)] 73 95 private void AfterDeserialization() { … … 81 103 protected CurvedChVariableSymbol(CurvedChVariableSymbol original, Cloner cloner) 82 104 : base(original, cloner) { 83 alpha = original.alpha; 84 beta = original.beta; 105 minAlpha = original.minAlpha; 106 maxAlpha = original.maxAlpha; 107 minBeta = original.minBeta; 108 maxBeta = original.maxBeta; 85 109 } 86 110 87 public CurvedChVariableSymbol(string name, string desc, double alpha, double beta)111 public CurvedChVariableSymbol(string name, string desc, double minAlpha = 0.001, double maxAlpha = 10, double minBeta = 0.001, double maxBeta = 10) 88 112 : base(name, desc) { 89 this.alpha = alpha; 90 this.beta = beta; 113 this.minAlpha = minAlpha; 114 this.maxAlpha = maxAlpha; 115 this.minBeta = minBeta; 116 this.maxBeta = maxBeta; 91 117 } 92 118 -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedChVariableTreeNode.cs
r13865 r13867 32 32 get { return (CurvedChVariableSymbol)base.Symbol; } 33 33 } 34 35 [Storable] 36 private double alpha; 37 public double Alpha { 38 get { return alpha; } 39 set { alpha = value; } 40 } 41 42 [Storable] 43 private double beta; 44 public double Beta { 45 get { return beta; } 46 set { beta = value; } 47 } 48 [Storable] 49 private double weight; 50 public double Weight { 51 get { return weight; } 52 set { weight = value; } 53 } 34 54 [StorableConstructor] 35 55 protected CurvedChVariableTreeNode(bool deserializing) : base(deserializing) { } 36 56 protected CurvedChVariableTreeNode(CurvedChVariableTreeNode original, Cloner cloner) 37 57 : base(original, cloner) { 58 this.alpha = original.alpha; 59 this.beta = original.beta; 60 this.weight = original.weight; 38 61 } 39 62 protected CurvedChVariableTreeNode() { } … … 41 64 42 65 public override bool HasLocalParameters { 43 get { return false; }66 get { return true; } 44 67 } 45 68 46 69 public override void ResetLocalParameters(IRandom random) { 47 70 base.ResetLocalParameters(random); 71 weight = NormalDistributedRandom.NextDouble(random, 0, 10); 72 alpha = UniformDistributedRandom.NextDouble(random, Symbol.MinAlpha, Symbol.MaxAlpha); 73 beta = UniformDistributedRandom.NextDouble(random, Symbol.MinBeta, Symbol.MaxBeta); 48 74 } 49 75 50 76 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 51 77 base.ShakeLocalParameters(random, shakingFactor); 78 weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor); 79 alpha += NormalDistributedRandom.NextDouble(random, 0, 1 * shakingFactor); 80 beta += NormalDistributedRandom.NextDouble(random, 0, 1 * shakingFactor); 81 82 alpha = Math.Min(Symbol.MaxAlpha, Math.Max(Symbol.MinAlpha, alpha)); 83 beta = Math.Min(Symbol.MinBeta, Math.Max(Symbol.MinBeta, beta)); 52 84 } 53 85 … … 57 89 58 90 public override string ToString() { 59 return string.Format(" curvedCh(alpha: {0}, beta: {1})", Symbol.Alpha, Symbol.Beta);91 return string.Format("{0:N3}*curvedCh(alpha: {1:N3}, beta: {2:N3})", weight, alpha, beta); 60 92 } 61 93 } -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedInsVariableSymbol.cs
r13865 r13867 35 35 36 36 [Storable] 37 private double alpha;38 public double Alpha {39 get { return alpha; }37 private double minAlpha; 38 public double MinAlpha { 39 get { return minAlpha; } 40 40 set { 41 if (value != alpha) { 42 alpha = value; 41 if (value != minAlpha) { 42 minAlpha = value; 43 OnChanged(EventArgs.Empty); 44 } 45 } 46 } 47 [Storable] 48 private double maxAlpha; 49 public double MaxAlpha { 50 get { return maxAlpha; } 51 set { 52 if (value != maxAlpha) { 53 maxAlpha = value; 43 54 OnChanged(EventArgs.Empty); 44 55 } … … 47 58 48 59 [Storable] 49 private double beta;50 public double Beta {51 get { return beta; }60 private double minBeta; 61 public double MinBeta { 62 get { return minBeta; } 52 63 set { 53 if (value != beta) { 54 alpha = value; 64 if (value != minBeta) { 65 minBeta = value; 66 OnChanged(EventArgs.Empty); 67 } 68 } 69 } 70 71 [Storable] 72 private double maxBeta; 73 public double MaxBeta { 74 get { return maxBeta; } 75 set { 76 if (value != maxBeta) { 77 maxBeta = value; 55 78 OnChanged(EventArgs.Empty); 56 79 } … … 81 104 protected CurvedInsVariableSymbol(CurvedInsVariableSymbol original, Cloner cloner) 82 105 : base(original, cloner) { 83 alpha = original.alpha; 84 beta = original.beta; 106 minAlpha = original.minAlpha; 107 maxAlpha = original.maxAlpha; 108 minBeta = original.minBeta; 109 maxBeta = original.maxBeta; 85 110 } 86 111 87 public CurvedInsVariableSymbol(string name, string desc, double alpha, double beta)112 public CurvedInsVariableSymbol(string name, string desc, double minAlpha = 0.001, double maxAlpha = 10, double minBeta = 0.001, double maxBeta = 10) 88 113 : base(name, desc) { 89 this.alpha = alpha; 90 this.beta = beta; 114 this.minAlpha = minAlpha; 115 this.maxAlpha = maxAlpha; 116 this.minBeta = minBeta; 117 this.maxBeta = maxBeta; 91 118 } 92 119 -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedInsVariableTreeNode.cs
r13865 r13867 32 32 get { return (CurvedInsVariableSymbol)base.Symbol; } 33 33 } 34 35 [Storable] 36 private double alpha; 37 public double Alpha { 38 get { return alpha; } 39 set { alpha = value; } 40 } 41 42 [Storable] 43 private double beta; 44 public double Beta { 45 get { return beta; } 46 set { beta = value; } 47 } 48 49 [Storable] 50 private double weight; 51 public double Weight { 52 get { return weight; } 53 set { weight = value; } 54 } 34 55 [StorableConstructor] 35 56 protected CurvedInsVariableTreeNode(bool deserializing) : base(deserializing) { } 36 57 protected CurvedInsVariableTreeNode(CurvedInsVariableTreeNode original, Cloner cloner) 37 58 : base(original, cloner) { 59 this.alpha = original.alpha; 60 this.beta = original.beta; 61 this.weight = original.weight; 38 62 } 39 63 protected CurvedInsVariableTreeNode() { } … … 41 65 42 66 public override bool HasLocalParameters { 43 get { return false; }67 get { return true; } 44 68 } 45 69 46 70 public override void ResetLocalParameters(IRandom random) { 47 71 base.ResetLocalParameters(random); 72 alpha = UniformDistributedRandom.NextDouble(random, Symbol.MinAlpha, Symbol.MaxAlpha); 73 beta = UniformDistributedRandom.NextDouble(random, Symbol.MinBeta, Symbol.MaxBeta); 74 weight = NormalDistributedRandom.NextDouble(random, 0, 10); 48 75 } 49 76 50 77 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 51 78 base.ShakeLocalParameters(random, shakingFactor); 79 weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor); 80 alpha += NormalDistributedRandom.NextDouble(random, 0, 1 * shakingFactor); 81 beta += NormalDistributedRandom.NextDouble(random, 0, 1 * shakingFactor); 82 83 alpha = Math.Min(Symbol.MaxAlpha, Math.Max(Symbol.MinAlpha, alpha)); 84 beta = Math.Min(Symbol.MinBeta, Math.Max(Symbol.MinBeta, beta)); 52 85 } 53 86 … … 57 90 58 91 public override string ToString() { 59 return string.Format(" curvedIns(alpha: {0}, beta: {1})", Symbol.Alpha, Symbol.Beta);92 return string.Format("{0:N3}*curvedIns(alpha: {1:N3}, beta: {2:N3})", weight, alpha, beta); 60 93 } 61 94 } -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Grammar.cs
r13865 r13867 46 46 var cosCh = new SimpleSymbol("CosCh", "Cos", 1, 1); 47 47 var logCh = new SimpleSymbol("LogCh", "Log", 1, 1); 48 var curvedChShape1 = new CurvedChVariableSymbol("CurvedCh1", "", 2, 5); 49 var curvedChShape2 = new CurvedChVariableSymbol("CurvedCh2", "", 3, 3); 50 var curvedChShape3 = new CurvedChVariableSymbol("CurvedCh3", "", 5, 2); 48 var curvedCh = new CurvedChVariableSymbol("CurvedCh", ""); 51 49 // var cteCh = new CteSymbol(); 52 50 … … 60 58 var cosIns = new SimpleSymbol("CosIns", "Cos", 1, 1); 61 59 var logIns = new SimpleSymbol("LogIns", "Log", 1, 1); 62 var curvedInsShape1 = new CurvedInsVariableSymbol("CurvedIns1", "", 2, 5); 63 var curvedInsShape2 = new CurvedInsVariableSymbol("CurvedIns2", "", 3, 3); 64 var curvedInsShape3 = new CurvedInsVariableSymbol("CurvedIns3", "", 5, 2); 60 var curvedIns = new CurvedInsVariableSymbol("CurvedIns", ""); 65 61 var realInsVar = new RealInsulineVariableSymbol(); 66 62 // var cteCh = new CteSymbol(); … … 81 77 AddSymbol(logGluc); 82 78 83 AddSymbol(curvedChShape1); 84 AddSymbol(curvedChShape2); 85 AddSymbol(curvedChShape3); 79 AddSymbol(curvedCh); 80 86 81 AddSymbol(plusCh); 87 82 AddSymbol(minusCh); … … 93 88 AddSymbol(logCh); 94 89 95 AddSymbol(curvedInsShape1); 96 AddSymbol(curvedInsShape2); 97 AddSymbol(curvedInsShape3); 90 AddSymbol(curvedIns); 98 91 AddSymbol(plusIns); 99 92 AddSymbol(minusIns); … … 174 167 } 175 168 // <exprch> ::= (getPrevData(1,k,1) * <cte> * <curvedCH>) 176 AddAllowedChildSymbol(exprCh, curvedChShape1); 177 AddAllowedChildSymbol(exprCh, curvedChShape2); 178 AddAllowedChildSymbol(exprCh, curvedChShape3); 169 AddAllowedChildSymbol(exprCh, curvedCh); 170 179 171 180 172 /* … … 220 212 AddAllowedChildSymbol(exprIns, realInsVar); 221 213 222 AddAllowedChildSymbol(exprIns, curvedInsShape1); 223 AddAllowedChildSymbol(exprIns, curvedInsShape2); 224 AddAllowedChildSymbol(exprIns, curvedInsShape3); 214 AddAllowedChildSymbol(exprIns, curvedIns); 225 215 226 216 // root is func -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Interpreter.cs
r13865 r13867 101 101 } else if (node.Symbol is PredictedGlucoseVariableSymbol) { 102 102 var n = (PredictedGlucoseVariableTreeNode)node; 103 return data.predGluc[k + n.RowOffset];103 return n.Weight * data.predGluc[k + n.RowOffset]; 104 104 } else if (node.Symbol is RealGlucoseVariableSymbol) { 105 105 var n = (RealGlucoseVariableTreeNode)node; 106 return data.realGluc[k + n.RowOffset];106 return n.Weight * data.realGluc[k + n.RowOffset]; 107 107 } else if (node.Symbol is CurvedChVariableSymbol) { 108 108 var n = (CurvedChVariableTreeNode)node; … … 110 110 int prevValDistance; 111 111 GetPrevDataAndDistance(data.realCh, k, out prevVal, out prevValDistance, maxDistance: 48); 112 return prevVal * Beta(prevValDistance / 48.0, n.Symbol.Alpha, n.Symbol.Beta);112 return n.Weight * prevVal * Beta(prevValDistance / 48.0, n.Alpha, n.Beta); 113 113 } else if (node.Symbol is RealInsulineVariableSymbol) { 114 114 var n = (RealInsulineVariableTreeNode)node; 115 return data.realIns[k + n.RowOffset];115 return n.Weight * data.realIns[k + n.RowOffset]; 116 116 } else if (node.Symbol is CurvedInsVariableSymbol) { 117 117 var n = (CurvedInsVariableTreeNode)node; … … 121 121 122 122 GetMaxValueAndDistance(data.realIns, k, out maxVal, out maxValDistance, maxDistance: 48); 123 return (sum - maxVal) * maxVal * Beta(maxValDistance / 48.0, n.Symbol.Alpha, n.Symbol.Beta);123 return n.Weight * (sum - maxVal) * maxVal * Beta(maxValDistance / 48.0, n.Alpha, n.Beta); 124 124 } else { 125 125 throw new InvalidProgramException("found unknown symbol " + node.Symbol); … … 128 128 129 129 private static double Beta(double x, double alpha, double beta) { 130 return alglib.invincompletebeta(alpha, beta, x);130 return 1.0 / alglib.beta(alpha, beta) * Math.Pow(x, alpha - 1) * Math.Pow(1 - x, beta - 1); 131 131 } 132 132 -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/PredictedGlucoseVariableTreeNode.cs
r13865 r13867 38 38 set { rowOffset = value; } 39 39 } 40 41 [Storable] 42 private double weight; 43 public double Weight { 44 get { return weight; } 45 set { weight = value; } 46 } 47 40 48 [StorableConstructor] 41 49 protected PredictedGlucoseVariableTreeNode(bool deserializing) : base(deserializing) { } … … 43 51 : base(original, cloner) { 44 52 rowOffset = original.rowOffset; 53 weight = original.weight; 45 54 } 46 55 protected PredictedGlucoseVariableTreeNode() { } … … 54 63 base.ResetLocalParameters(random); 55 64 rowOffset = random.Next(Symbol.MinRowOffset, Symbol.MaxRowOffset + 1); 65 weight = NormalDistributedRandom.NextDouble(random, 0, 10); 56 66 } 57 67 … … 63 73 rowOffset = Math.Max(rowOffset, Symbol.MinRowOffset); 64 74 rowOffset = Math.Min(rowOffset, Symbol.MaxRowOffset); 75 76 weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor); 65 77 } 66 78 … … 70 82 71 83 public override string ToString() { 72 return "predGluc(k" + rowOffset + ")";84 return string.Format("{0:N2}*predGluc(k{1})", weight, rowOffset); 73 85 } 74 86 } -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/RealGlucoseVariableTreeNode.cs
r13865 r13867 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Random; 27 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction { … … 38 39 set { rowOffset = value; } 39 40 } 41 42 [Storable] 43 private double weight; 44 public double Weight { 45 get { return weight; } 46 set { weight = value; } 47 } 40 48 [StorableConstructor] 41 49 protected RealGlucoseVariableTreeNode(bool deserializing) : base(deserializing) { } … … 43 51 : base(original, cloner) { 44 52 rowOffset = original.rowOffset; 53 weight = original.weight; 45 54 } 46 55 protected RealGlucoseVariableTreeNode() { } … … 54 63 base.ResetLocalParameters(random); 55 64 rowOffset = random.Next(Symbol.MinRowOffset, Symbol.MaxRowOffset + 1); 65 weight = NormalDistributedRandom.NextDouble(random, 0, 10); 56 66 } 57 67 … … 63 73 rowOffset = Math.Max(rowOffset, Symbol.MinRowOffset); 64 74 rowOffset = Math.Min(rowOffset, Symbol.MaxRowOffset); 75 weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor); 65 76 } 66 77 … … 70 81 71 82 public override string ToString() { 72 return "realGluc(k" + rowOffset + ")";83 return string.Format("{0:N3} * realGluc(k{1})", weight, rowOffset); 73 84 } 74 85 } -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/RealInsulineVariableTreeNode.cs
r13865 r13867 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Random; 27 28 28 29 namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction { … … 38 39 set { rowOffset = value; } 39 40 } 41 [Storable] 42 private double weight; 43 public double Weight { 44 get { return weight; } 45 set { weight = value; } 46 } 40 47 [StorableConstructor] 41 48 protected RealInsulineVariableTreeNode(bool deserializing) : base(deserializing) { } … … 43 50 : base(original, cloner) { 44 51 rowOffset = original.rowOffset; 52 weight = original.weight; 45 53 } 46 54 protected RealInsulineVariableTreeNode() { } … … 54 62 base.ResetLocalParameters(random); 55 63 rowOffset = random.Next(Symbol.MinRowOffset, Symbol.MaxRowOffset + 1); 64 weight = NormalDistributedRandom.NextDouble(random, 0, 10); 56 65 } 57 66 … … 63 72 rowOffset = Math.Max(rowOffset, Symbol.MinRowOffset); 64 73 rowOffset = Math.Min(rowOffset, Symbol.MaxRowOffset); 74 weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor); 65 75 } 66 76 … … 70 80 71 81 public override string ToString() { 72 return "realIns(k" + rowOffset + ")";82 return string.Format("{0:N3}*realIns(k{1})", weight, rowOffset); 73 83 } 74 84 } -
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Solution.cs
r13865 r13867 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Drawing;4 3 using System.Linq; 5 using System.Text;6 using System.Threading.Tasks;7 4 using HeuristicLab.Common; 8 5 using HeuristicLab.Core; 9 6 using HeuristicLab.Data; 10 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;11 7 using HeuristicLab.Optimization; 12 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
Note: See TracChangeset
for help on using the changeset viewer.