Changeset 13867


Ignore:
Timestamp:
05/31/16 17:05:49 (5 years ago)
Author:
gkronber
Message:

#2608 worked on glucose prediction problem

Location:
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedChVariableSymbol.cs

    r13865 r13867  
    3434    #region Properties
    3535
    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 
    6036    private const int minimumArity = 0;
    6137    private const int maximumArity = 0;
     
    7046    #endregion
    7147
     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    }
    7294    [StorableHook(HookType.AfterDeserialization)]
    7395    private void AfterDeserialization() {
     
    81103    protected CurvedChVariableSymbol(CurvedChVariableSymbol original, Cloner cloner)
    82104      : 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;
    85109    }
    86110
    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)
    88112      : 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;
    91117    }
    92118
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedChVariableTreeNode.cs

    r13865 r13867  
    3232      get { return (CurvedChVariableSymbol)base.Symbol; }
    3333    }
     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    }
    3454    [StorableConstructor]
    3555    protected CurvedChVariableTreeNode(bool deserializing) : base(deserializing) { }
    3656    protected CurvedChVariableTreeNode(CurvedChVariableTreeNode original, Cloner cloner)
    3757      : base(original, cloner) {
     58      this.alpha = original.alpha;
     59      this.beta = original.beta;
     60      this.weight = original.weight;
    3861    }
    3962    protected CurvedChVariableTreeNode() { }
     
    4164
    4265    public override bool HasLocalParameters {
    43       get { return false; }
     66      get { return true; }
    4467    }
    4568
    4669    public override void ResetLocalParameters(IRandom random) {
    4770      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);
    4874    }
    4975
    5076    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    5177      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));
    5284    }
    5385
     
    5789
    5890    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);
    6092    }
    6193  }
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedInsVariableSymbol.cs

    r13865 r13867  
    3535
    3636    [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; }
    4040      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;
    4354          OnChanged(EventArgs.Empty);
    4455        }
     
    4758
    4859    [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; }
    5263      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;
    5578          OnChanged(EventArgs.Empty);
    5679        }
     
    81104    protected CurvedInsVariableSymbol(CurvedInsVariableSymbol original, Cloner cloner)
    82105      : 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;
    85110    }
    86111
    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)
    88113      : 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;
    91118    }
    92119
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/CurvedInsVariableTreeNode.cs

    r13865 r13867  
    3232      get { return (CurvedInsVariableSymbol)base.Symbol; }
    3333    }
     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    }
    3455    [StorableConstructor]
    3556    protected CurvedInsVariableTreeNode(bool deserializing) : base(deserializing) { }
    3657    protected CurvedInsVariableTreeNode(CurvedInsVariableTreeNode original, Cloner cloner)
    3758      : base(original, cloner) {
     59      this.alpha = original.alpha;
     60      this.beta = original.beta;
     61      this.weight = original.weight;
    3862    }
    3963    protected CurvedInsVariableTreeNode() { }
     
    4165
    4266    public override bool HasLocalParameters {
    43       get { return false; }
     67      get { return true; }
    4468    }
    4569
    4670    public override void ResetLocalParameters(IRandom random) {
    4771      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);
    4875    }
    4976
    5077    public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    5178      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));
    5285    }
    5386
     
    5790
    5891    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);
    6093    }
    6194  }
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Grammar.cs

    r13865 r13867  
    4646      var cosCh = new SimpleSymbol("CosCh", "Cos", 1, 1);
    4747      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", "");
    5149      // var cteCh = new CteSymbol();
    5250
     
    6058      var cosIns = new SimpleSymbol("CosIns", "Cos", 1, 1);
    6159      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", "");
    6561      var realInsVar = new RealInsulineVariableSymbol();
    6662      // var cteCh = new CteSymbol();
     
    8177      AddSymbol(logGluc);
    8278
    83       AddSymbol(curvedChShape1);
    84       AddSymbol(curvedChShape2);
    85       AddSymbol(curvedChShape3);
     79      AddSymbol(curvedCh);
     80
    8681      AddSymbol(plusCh);
    8782      AddSymbol(minusCh);
     
    9388      AddSymbol(logCh);
    9489
    95       AddSymbol(curvedInsShape1);
    96       AddSymbol(curvedInsShape2);
    97       AddSymbol(curvedInsShape3);
     90      AddSymbol(curvedIns);
    9891      AddSymbol(plusIns);
    9992      AddSymbol(minusIns);
     
    174167      }
    175168      // <exprch> ::= (getPrevData(1,k,1) * <cte> * <curvedCH>)
    176       AddAllowedChildSymbol(exprCh, curvedChShape1);
    177       AddAllowedChildSymbol(exprCh, curvedChShape2);
    178       AddAllowedChildSymbol(exprCh, curvedChShape3);
     169      AddAllowedChildSymbol(exprCh, curvedCh);
     170
    179171
    180172      /*
     
    220212      AddAllowedChildSymbol(exprIns, realInsVar);
    221213
    222       AddAllowedChildSymbol(exprIns, curvedInsShape1);
    223       AddAllowedChildSymbol(exprIns, curvedInsShape2);
    224       AddAllowedChildSymbol(exprIns, curvedInsShape3);
     214      AddAllowedChildSymbol(exprIns, curvedIns);
    225215
    226216      // root is func
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Interpreter.cs

    r13865 r13867  
    101101      } else if (node.Symbol is PredictedGlucoseVariableSymbol) {
    102102        var n = (PredictedGlucoseVariableTreeNode)node;
    103         return data.predGluc[k + n.RowOffset];
     103        return n.Weight * data.predGluc[k + n.RowOffset];
    104104      } else if (node.Symbol is RealGlucoseVariableSymbol) {
    105105        var n = (RealGlucoseVariableTreeNode)node;
    106         return data.realGluc[k + n.RowOffset];
     106        return n.Weight * data.realGluc[k + n.RowOffset];
    107107      } else if (node.Symbol is CurvedChVariableSymbol) {
    108108        var n = (CurvedChVariableTreeNode)node;
     
    110110        int prevValDistance;
    111111        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);
    113113      } else if (node.Symbol is RealInsulineVariableSymbol) {
    114114        var n = (RealInsulineVariableTreeNode)node;
    115         return data.realIns[k + n.RowOffset];
     115        return n.Weight * data.realIns[k + n.RowOffset];
    116116      } else if (node.Symbol is CurvedInsVariableSymbol) {
    117117        var n = (CurvedInsVariableTreeNode)node;
     
    121121
    122122        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);
    124124      } else {
    125125        throw new InvalidProgramException("found unknown symbol " + node.Symbol);
     
    128128
    129129    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);
    131131    }
    132132
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/PredictedGlucoseVariableTreeNode.cs

    r13865 r13867  
    3838      set { rowOffset = value; }
    3939    }
     40
     41    [Storable]
     42    private double weight;
     43    public double Weight {
     44      get { return weight; }
     45      set { weight = value; }
     46    }
     47
    4048    [StorableConstructor]
    4149    protected PredictedGlucoseVariableTreeNode(bool deserializing) : base(deserializing) { }
     
    4351      : base(original, cloner) {
    4452      rowOffset = original.rowOffset;
     53      weight = original.weight;
    4554    }
    4655    protected PredictedGlucoseVariableTreeNode() { }
     
    5463      base.ResetLocalParameters(random);
    5564      rowOffset = random.Next(Symbol.MinRowOffset, Symbol.MaxRowOffset + 1);
     65      weight = NormalDistributedRandom.NextDouble(random, 0, 10);
    5666    }
    5767
     
    6373      rowOffset = Math.Max(rowOffset, Symbol.MinRowOffset);
    6474      rowOffset = Math.Min(rowOffset, Symbol.MaxRowOffset);
     75
     76      weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor);
    6577    }
    6678
     
    7082
    7183    public override string ToString() {
    72       return "predGluc(k" + rowOffset + ")";
     84      return string.Format("{0:N2}*predGluc(k{1})", weight, rowOffset);
    7385    }
    7486  }
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/RealGlucoseVariableTreeNode.cs

    r13865 r13867  
    2525using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Random;
    2728
    2829namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction {
     
    3839      set { rowOffset = value; }
    3940    }
     41
     42    [Storable]
     43    private double weight;
     44    public double Weight {
     45      get { return weight; }
     46      set { weight = value; }
     47    }
    4048    [StorableConstructor]
    4149    protected RealGlucoseVariableTreeNode(bool deserializing) : base(deserializing) { }
     
    4351      : base(original, cloner) {
    4452      rowOffset = original.rowOffset;
     53      weight = original.weight;
    4554    }
    4655    protected RealGlucoseVariableTreeNode() { }
     
    5463      base.ResetLocalParameters(random);
    5564      rowOffset = random.Next(Symbol.MinRowOffset, Symbol.MaxRowOffset + 1);
     65      weight = NormalDistributedRandom.NextDouble(random, 0, 10);
    5666    }
    5767
     
    6373      rowOffset = Math.Max(rowOffset, Symbol.MinRowOffset);
    6474      rowOffset = Math.Min(rowOffset, Symbol.MaxRowOffset);
     75      weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor);
    6576    }
    6677
     
    7081
    7182    public override string ToString() {
    72       return "realGluc(k" + rowOffset + ")";
     83      return string.Format("{0:N3} * realGluc(k{1})", weight, rowOffset);
    7384    }
    7485  }
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/RealInsulineVariableTreeNode.cs

    r13865 r13867  
    2525using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Random;
    2728
    2829namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction {
     
    3839      set { rowOffset = value; }
    3940    }
     41    [Storable]
     42    private double weight;
     43    public double Weight {
     44      get { return weight; }
     45      set { weight = value; }
     46    }
    4047    [StorableConstructor]
    4148    protected RealInsulineVariableTreeNode(bool deserializing) : base(deserializing) { }
     
    4350      : base(original, cloner) {
    4451      rowOffset = original.rowOffset;
     52      weight = original.weight;
    4553    }
    4654    protected RealInsulineVariableTreeNode() { }
     
    5462      base.ResetLocalParameters(random);
    5563      rowOffset = random.Next(Symbol.MinRowOffset, Symbol.MaxRowOffset + 1);
     64      weight = NormalDistributedRandom.NextDouble(random, 0, 10);
    5665    }
    5766
     
    6372      rowOffset = Math.Max(rowOffset, Symbol.MinRowOffset);
    6473      rowOffset = Math.Min(rowOffset, Symbol.MaxRowOffset);
     74      weight += NormalDistributedRandom.NextDouble(random, 0, 1.0 * shakingFactor);
    6575    }
    6676
     
    7080
    7181    public override string ToString() {
    72       return "realIns(k" + rowOffset + ")";
     82      return string.Format("{0:N3}*realIns(k{1})", weight, rowOffset);
    7383    }
    7484  }
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Solution.cs

    r13865 r13867  
    11using System;
    22using System.Collections.Generic;
    3 using System.Drawing;
    43using System.Linq;
    5 using System.Text;
    6 using System.Threading.Tasks;
    74using HeuristicLab.Common;
    85using HeuristicLab.Core;
    96using HeuristicLab.Data;
    10 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    117using HeuristicLab.Optimization;
    128using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
Note: See TracChangeset for help on using the changeset viewer.