Changeset 13870


Ignore:
Timestamp:
06/01/16 17:59:36 (5 years ago)
Author:
gkronber
Message:

#2608: simplified grammar by removing unnecessary symbols: exprch, exprins, exprgluc and added constants

Location:
branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction
Files:
3 edited

Legend:

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

    r13867 r13870  
    33using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    44using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     5using HeuristicLab.Problems.DataAnalysis.Symbolic;
    56
    67namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction {
     
    6061      var curvedIns = new CurvedInsVariableSymbol("CurvedIns", "");
    6162      var realInsVar = new RealInsulineVariableSymbol();
     63
     64      var constSy = new Constant();
    6265      // var cteCh = new CteSymbol();
    6366
     
    98101      AddSymbol(logIns);
    99102      AddSymbol(realInsVar);
     103      AddSymbol(constSy);
    100104
    101105      // <func> ::= <exprgluc> + <exprch> - <exprins>
     
    111115                    |realData(k-<idx2hOrMore>)
    112116      */
    113       var opGlucSet = new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc, expGluc, sinGluc, cosGluc, logGluc };
     117      var opGlucSet = new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc, expGluc, sinGluc, cosGluc, logGluc, predGlucData, realGlucData, constSy };
    114118      foreach (var opGluc in opGlucSet) {
    115119        AddAllowedChildSymbol(exprGluc, opGluc);
    116120      }
    117121
    118       // <exprgluc> ::= (<exprgluc> <op> <exprgluc>)
    119       // <exprgluc> ::= (<cte> <op> <exprgluc>)
    120       foreach (var op in new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc }) {
    121         AddAllowedChildSymbol(op, exprGluc, 0);
    122         // AddAllowedChildSymbol(op, cteGluc, 0); // cte is only allowed as first child
    123         AddAllowedChildSymbol(op, exprGluc, 1);
     122
     123      foreach (var parentOp in new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc }) {
     124        foreach (var childOp in opGlucSet) {
     125          AddAllowedChildSymbol(parentOp, childOp, 0);
     126          AddAllowedChildSymbol(parentOp, childOp, 1);
     127        }
    124128      }
    125129      // <exprgluc> ::= <preop> (<exprgluc>)
    126       foreach (var op in new Symbol[] { expGluc, sinGluc, cosGluc, logGluc }) {
    127         AddAllowedChildSymbol(op, exprGluc, 0);
    128       }
    129 
    130       AddAllowedChildSymbol(exprGluc, predGlucData); // <exprgluc> ::= predictedData(k-<idxCurr2h>)
    131       AddAllowedChildSymbol(exprGluc, realGlucData); // <exprgluc> ::= realData(k-<idx2hOrMore>)
    132 
     130      foreach (var parentOp in new Symbol[] { expGluc, sinGluc, cosGluc, logGluc }) {
     131        foreach (var childOp in opGlucSet) {
     132          AddAllowedChildSymbol(parentOp, childOp, 0);
     133        }
     134      }
    133135
    134136      /*
     
    150152              |beta(0.02*Math.min(48,getPrevDataDistance(1,k,1)),5,2)
    151153      */
    152       var opChSet = new Symbol[] { plusCh, minusCh, prodCh, divCh, expCh, sinCh, cosCh, logCh };
     154      var opChSet = new Symbol[] { plusCh, minusCh, prodCh, divCh, expCh, sinCh, cosCh, logCh, curvedCh, constSy };
    153155      foreach (var opCh in opChSet) {
    154156        AddAllowedChildSymbol(exprCh, opCh);
    155157      }
    156158
    157       // <exprch> ::= (<exprch> <op> <exprch>)
    158       // <exprch> ::= (<cte> <op> <exprch>)
    159       foreach (var op in new Symbol[] { plusCh, minusCh, prodCh, divCh }) {
    160         AddAllowedChildSymbol(op, exprCh, 0);
    161         // AddAllowedChildSymbol(op, cteCh, 0); // cte is only allowed as first child
    162         AddAllowedChildSymbol(op, exprCh, 1);
     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        }
    163164      }
    164165      // <exprch> ::= <preop> (<exprch>)
    165       foreach (var op in new Symbol[] { expCh, sinCh, cosCh, logCh }) {
    166         AddAllowedChildSymbol(op, exprCh, 0);
    167       }
    168       // <exprch> ::= (getPrevData(1,k,1) * <cte> * <curvedCH>)
    169       AddAllowedChildSymbol(exprCh, curvedCh);
    170 
     166      foreach (var parentOp in new Symbol[] { expCh, sinCh, cosCh, logCh }) {
     167        foreach (var childOp in opChSet) {
     168          AddAllowedChildSymbol(parentOp, childOp, 0);
     169        }
     170      }
    171171
    172172      /*
     
    192192
    193193      */
    194       var opInsSet = new Symbol[] { plusIns, minusIns, prodIns, divIns, expIns, sinIns, cosIns, logIns };
     194      var opInsSet = new Symbol[] { plusIns, minusIns, prodIns, divIns, expIns, sinIns, cosIns, logIns, realInsVar, curvedIns, constSy };
    195195      foreach (var opIns in opInsSet) {
    196196        AddAllowedChildSymbol(exprIns, opIns);
     
    199199      // <exprins> ::= (<exprins> <op> <exprins>)
    200200      // <exprins> ::= (<cte> <op> <exprins>)   
    201       foreach (var op in new Symbol[] { plusIns, minusIns, prodIns, divIns }) {
    202         AddAllowedChildSymbol(op, exprIns, 0);
    203         // AddAllowedChildSymbol(op, cteIns, 0); // cte is only allowed as first child
    204         AddAllowedChildSymbol(op, exprIns, 1);
     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        }
    205206      }
    206207      // <exprins> ::= <preop> (<exprins>)
    207208      foreach (var op in new Symbol[] { expIns, sinIns, cosIns, logIns }) {
    208         AddAllowedChildSymbol(op, exprIns, 0);
    209       }
    210 
    211       // <exprIns> ::= getVariable(2,k-<idx>)
    212       AddAllowedChildSymbol(exprIns, realInsVar);
    213 
    214       AddAllowedChildSymbol(exprIns, curvedIns);
     209        foreach (var childOp in opInsSet) {
     210          AddAllowedChildSymbol(op, childOp, 0);
     211        }
     212      }
    215213
    216214      // root is func
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction-3.3.csproj

    r13865 r13870  
    135135      <HintPath>..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
    136136    </Reference>
     137    <Reference Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4, Version=3.4.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     138      <SpecificVersion>False</SpecificVersion>
     139      <HintPath>..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll</HintPath>
     140    </Reference>
    137141    <Reference Include="HeuristicLab.Problems.Instances-3.3">
    138142      <HintPath>..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
  • branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Interpreter.cs

    r13867 r13870  
    77using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    88using HeuristicLab.Problems.DataAnalysis;
     9using HeuristicLab.Problems.DataAnalysis.Symbolic;
    910
    1011namespace HeuristicLab.Problems.GeneticProgramming.GlucosePrediction {
     
    2627      };
    2728      data.predGluc = new double[data.realGluc.Length];
     29      Array.Copy(data.realGluc, data.predGluc, data.predGluc.Length);
    2830      for (int k = 0; k < data.predGluc.Length; k++) {
    2931        if (double.IsNaN(targetGluc[k])) {
     
    122124        GetMaxValueAndDistance(data.realIns, k, out maxVal, out maxValDistance, maxDistance: 48);
    123125        return n.Weight * (sum - maxVal) * maxVal * Beta(maxValDistance / 48.0, n.Alpha, n.Beta);
     126      } else if (node.Symbol is Constant) {
     127        var n = (ConstantTreeNode)node;
     128        return n.Value;
    124129      } else {
    125130        throw new InvalidProgramException("found unknown symbol " + node.Symbol);
Note: See TracChangeset for help on using the changeset viewer.