Changes between Version 32 and Version 33 of Documentation/Reference/GPDL


Ignore:
Timestamp:
11/02/13 09:51:25 (6 years ago)
Author:
gkronber
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Reference/GPDL

    v32 v33  
    8787  double[,] x;
    8888  double[] y;
     89  int[] rows;
    8990  string[] variableNames;
     91  double[] randomConsts;
     92 
    9093  Dictionary<string,int> nameToCol;
    9194 
     
    102105
    103106  double RSquared(IEnumerable<double> xs, IEnumerable<double> ys) {
    104      HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError error;
    105      var r2 = HeuristicLab.Problems.DataAnalysis.OnlinePearsonsRSquaredCalculator.Calculate(xs, ys, out error);
    106      if(error == HeuristicLab.Problems.DataAnalysis.OnlineCalculatorError.None) return r2;
    107      else return 0.0;
    108   }
     107    // calculate Pearson's correlation in one pass over xs and ys
     108    double sumx = 0.0;
     109    double sumy = 0.0;
     110    double sumxSq = 0.0;
     111    double sumySq = 0.0;
     112    double sumxy = 0.0;
     113    int n = 0;
     114    var xEnum = xs.GetEnumerator();
     115    var yEnum = ys.GetEnumerator();
     116    while(xEnum.MoveNext() & yEnum.MoveNext()) {
     117      sumx += xEnum.Current;
     118      sumy += yEnum.Current;
     119      sumxSq += xEnum.Current * xEnum.Current;
     120      sumySq += yEnum.Current * yEnum.Current;
     121      sumxy += xEnum.Current * yEnum.Current;
     122      n++;
     123    }
     124    System.Diagnostics.Debug.Assert(!(xEnum.MoveNext() | yEnum.MoveNext()));
     125
     126    double num;
     127    double den;
     128    double r = 0.0;
     129    num = sumxy - ( ( sumx * sumy ) / n );
     130    den = Math.Sqrt( ( sumxSq - ( sumx*sumx ) / n ) *
     131                     ( sumySq - ( sumy*sumy ) / n ) );
     132    if(den > 0){
     133      r = num / den;
     134    }
     135    return r*r;
     136  }
    109137>>
    110138
    111139INIT <<
    112   // generate 500 case of poly-10 benchmark function
     140  // generate 500 cases of poly-10 benchmark function
    113141  int n = 500;
    114142  variableNames = new string[] {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" };
     
    116144  x = new double[n, 10];
    117145  y = new double[n];
    118   for(int row = 0; row < 500; row++) {
     146  for(int row = 0; row < n; row++) {
    119147    for(int col = 0; col < 10; col++) {
    120148      x[row, col] = rand.NextDouble() * 2.0 - 1.0;
     
    126154             x[row, 2] * x[row, 5] + x[row, 9];
    127155  }
     156 
     157  rows = System.Linq.Enumerable.Range(0, n).ToArray();
     158 
     159  // generate 100 random constants in [-10.0 .. 10.0[
     160  randomConsts = Enumerable.Range(0, 100).Select(i => rand.NextDouble()*20.0 - 10.0).ToArray();
    128161>>
    129162
    130 /* non-terminals of the problem */
    131163NONTERMINALS
    132164  Model<<int row, out double val>>.
     
    137169  Division<<int row, out double val>>.
    138170
    139 /* terminals of the problem: random constants (ERC) and variables */
    140171TERMINALS
    141172  ERC<<out double val>>
    142173    CONSTRAINTS
    143           val IN RANGE <<-100>> .. <<100>>
     174      val IN SET << randomConsts >>
    144175  .
    145176
    146177  Var<<out string varName>>
    147178    CONSTRAINTS
    148           varName IN SET <<variableNames>>
    149   .
    150 
    151 /* grammar rules for the problem with interleaved semantic actions */
     179      varName IN SET << variableNames >>
     180  .
     181
    152182RULES
    153183  Model<<int row, out double val>> =
     
    160190    | Multiplication<<row, out val>>
    161191    | Var<<out varName>>                                   SEM << val = GetValue(x, varName, row); >>
    162     | ERC<<out val>>
     192    /* | ERC<<out val>> */
    163193  .
    164194
     
    176206  .
    177207
    178 /* objective function */
    179 MAXIMIZE                                                   /* could also use the keyword MINIMIZE here */
     208MAXIMIZE
    180209  <<
    181     var rows = System.Linq.Enumerable.Range(0, x.GetLength(0));
    182210    var predicted = rows.Select(r => {
    183211      double result;