source: src/main/java/agents/uk/ac/soton/ecs/gp4j/util/GaussianProcessUtils.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 1.3 KB
Line 
1package agents.uk.ac.soton.ecs.gp4j.util;
2
3import agents.Jama.CholeskyDecomposition;
4import agents.Jama.Matrix;
5import agents.org.apache.commons.math.random.RandomData;
6import agents.org.apache.commons.math.random.RandomDataImpl;
7import agents.uk.ac.soton.ecs.gp4j.gp.covariancefunctions.CovarianceFunction;
8
9public class GaussianProcessUtils {
10 public static Matrix drawSample(CovarianceFunction function,
11 double[] logHyper, Matrix testX, RandomData data) {
12 Matrix covarianceMatrix = function.calculateCovarianceMatrix(logHyper,
13 testX);
14
15 return drawSample(covarianceMatrix, testX, data);
16 }
17
18 public static Matrix drawSample(CovarianceFunction function,
19 double[] logHyper, Matrix testX) {
20 return drawSample(function, logHyper, testX, new RandomDataImpl());
21 }
22
23 public static Matrix drawSample(Matrix covarianceMatrix, Matrix testX,
24 RandomData data) {
25 Matrix randomVector = new Matrix(testX.getRowDimension(), 1);
26
27 for (int i = 0; i < randomVector.getRowDimension(); i++) {
28 randomVector.set(i, 0, data.nextGaussian(0, 1));
29 }
30
31 CholeskyDecomposition chol = covarianceMatrix.chol();
32
33 return chol.getL().times(randomVector);
34 }
35
36 public static Matrix drawSample(Matrix covarianceMatrix, Matrix testX) {
37 return drawSample(covarianceMatrix, testX, new RandomDataImpl());
38 }
39}
Note: See TracBrowser for help on using the repository browser.