- Timestamp:
- 08/11/12 14:45:15 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs
r8473 r8475 130 130 double[] m = meanFunction.GetMean(x); 131 131 for (int i = 0; i < n; i++) { 132 133 132 for (int j = i; j < n; j++) { 134 133 l[j, i] = covarianceFunction.GetCovariance(i, j) / sqrSigmaNoise; … … 163 162 int info; 164 163 alglib.matinvreport matInvRep; 165 166 alglib.spdmatrixcholeskyinverse(ref l, n, false, out info, out matInvRep); 164 double[,] lCopy = new double[l.GetLength(0), l.GetLength(1)]; 165 Array.Copy(l, lCopy, lCopy.Length); 166 167 alglib.spdmatrixcholeskyinverse(ref lCopy, n, false, out info, out matInvRep); 167 168 if (info != 1) throw new ArgumentException("Can't invert matrix to calculate gradients."); 168 169 for (int i = 0; i < n; i++) { 169 170 for (int j = 0; j <= i; j++) 170 l [i, j] = l[i, j] / sqrSigmaNoise - alpha[i] * alpha[j];171 } 172 173 double noiseGradient = sqrSigmaNoise * Enumerable.Range(0, n).Select(i => l [i, i]).Sum();171 lCopy[i, j] = lCopy[i, j] / sqrSigmaNoise - alpha[i] * alpha[j]; 172 } 173 174 double noiseGradient = sqrSigmaNoise * Enumerable.Range(0, n).Select(i => lCopy[i, i]).Sum(); 174 175 175 176 double[] meanGradients = new double[meanFunction.GetNumberOfParameters(nAllowedVariables)]; … … 184 185 for (int k = 0; k < covGradients.Length; k++) { 185 186 for (int j = 0; j < i; j++) { 186 covGradients[k] += l [i, j] * covarianceFunction.GetGradient(i, j, k);187 covGradients[k] += lCopy[i, j] * covarianceFunction.GetGradient(i, j, k); 187 188 } 188 covGradients[k] += 0.5 * l [i, i] * covarianceFunction.GetGradient(i, i, k);189 covGradients[k] += 0.5 * lCopy[i, i] * covarianceFunction.GetGradient(i, i, k); 189 190 } 190 191 } … … 264 265 double[,] sWKs = new double[n, newN]; 265 266 266 267 267 // for stddev 268 268 covarianceFunction.SetData(newX); … … 271 271 272 272 covarianceFunction.SetData(x, newX); 273 for (int i = 0; i < n ; i++) {274 for (int j = 0; j < n ewN; j++) {275 sWKs[ i, j] = covarianceFunction.GetCovariance(i, j) / Math.Sqrt(sqrSigmaNoise);273 for (int i = 0; i < newN; i++) { 274 for (int j = 0; j < n; j++) { 275 sWKs[j, i] = covarianceFunction.GetCovariance(j, i) / Math.Sqrt(sqrSigmaNoise); 276 276 } 277 277 } … … 281 281 alglib.densesolverreport denseSolveRep; 282 282 double[,] v; 283 double[,] lTrans = new double[l.GetLength(1), l.GetLength(0)]; 284 for (int i = 0; i < lTrans.GetLength(0); i++) 285 for (int j = 0; j < lTrans.GetLength(1); j++) 286 lTrans[i, j] = l[j, i]; 287 alglib.rmatrixsolvem(lTrans, n, sWKs, newN, true, out info, out denseSolveRep, out v); // not working! 288 // alglib.spdmatrixcholeskysolvem(lTrans, n, true, sWKs, newN, out info, out denseSolveRep, out v); 283 284 alglib.rmatrixsolvem(l, n, sWKs, newN, false, out info, out denseSolveRep, out v); 289 285 290 286 for (int i = 0; i < newN; i++) { 291 var sumV2 = Util.ScalarProd(Util.GetCol(v, i), Util.GetCol(v, i)); 292 yield return kss[i] - sumV2; 293 } 287 var sumV = Util.ScalarProd(Util.GetCol(v, i), Util.GetCol(v, i)); 288 kss[i] -= sumV; 289 if (kss[i] < 0) kss[i] = 0; 290 } 291 return kss; 294 292 } 295 293 }
Note: See TracChangeset
for help on using the changeset viewer.