Changes between Version 32 and Version 33 of Documentation/Reference/GPDL
- Timestamp:
- 11/02/13 09:51:25 (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Documentation/Reference/GPDL
v32 v33 87 87 double[,] x; 88 88 double[] y; 89 int[] rows; 89 90 string[] variableNames; 91 double[] randomConsts; 92 90 93 Dictionary<string,int> nameToCol; 91 94 … … 102 105 103 106 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 } 109 137 >> 110 138 111 139 INIT << 112 // generate 500 case of poly-10 benchmark function140 // generate 500 cases of poly-10 benchmark function 113 141 int n = 500; 114 142 variableNames = new string[] {"x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10" }; … … 116 144 x = new double[n, 10]; 117 145 y = new double[n]; 118 for(int row = 0; row < 500; row++) {146 for(int row = 0; row < n; row++) { 119 147 for(int col = 0; col < 10; col++) { 120 148 x[row, col] = rand.NextDouble() * 2.0 - 1.0; … … 126 154 x[row, 2] * x[row, 5] + x[row, 9]; 127 155 } 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(); 128 161 >> 129 162 130 /* non-terminals of the problem */131 163 NONTERMINALS 132 164 Model<<int row, out double val>>. … … 137 169 Division<<int row, out double val>>. 138 170 139 /* terminals of the problem: random constants (ERC) and variables */140 171 TERMINALS 141 172 ERC<<out double val>> 142 173 CONSTRAINTS 143 val IN RANGE <<-100>> .. <<100>>174 val IN SET << randomConsts >> 144 175 . 145 176 146 177 Var<<out string varName>> 147 178 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 152 182 RULES 153 183 Model<<int row, out double val>> = … … 160 190 | Multiplication<<row, out val>> 161 191 | Var<<out varName>> SEM << val = GetValue(x, varName, row); >> 162 | ERC<<out val>>192 /* | ERC<<out val>> */ 163 193 . 164 194 … … 176 206 . 177 207 178 /* objective function */ 179 MAXIMIZE /* could also use the keyword MINIMIZE here */ 208 MAXIMIZE 180 209 << 181 var rows = System.Linq.Enumerable.Range(0, x.GetLength(0));182 210 var predicted = rows.Select(r => { 183 211 double result;