1 | package agents.uk.ac.soton.ecs.gp4j.util;
|
---|
2 |
|
---|
3 | import agents.Jama.CholeskyDecomposition;
|
---|
4 | import agents.Jama.Matrix;
|
---|
5 | import agents.org.apache.commons.math.random.RandomData;
|
---|
6 | import agents.org.apache.commons.math.random.RandomDataImpl;
|
---|
7 | import agents.uk.ac.soton.ecs.gp4j.gp.covariancefunctions.CovarianceFunction;
|
---|
8 |
|
---|
9 | public 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 | }
|
---|