Last change
on this file was 1, checked in by Wouter Pasman, 6 years ago |
Initial import : Genius 9.0.0
|
File size:
888 bytes
|
Line | |
---|
1 | package agents.uk.ac.soton.ecs.gp4j.util;
|
---|
2 |
|
---|
3 | import agents.Jama.Matrix;
|
---|
4 | import agents.org.apache.commons.lang.Validate;
|
---|
5 |
|
---|
6 | public class MathUtils {
|
---|
7 | public static double normPDF(double x, double mean, double standardDeviation) {
|
---|
8 | return Math.exp(-(Math.pow((x - mean) / standardDeviation, 2)) / 2)
|
---|
9 | / (Math.sqrt(2 * Math.PI) * standardDeviation);
|
---|
10 | }
|
---|
11 |
|
---|
12 | public static double mvnPDF(double[] x, double[] mu, double[][] sigma) {
|
---|
13 | double N = x.length;
|
---|
14 |
|
---|
15 | Validate.isTrue(N == mu.length);
|
---|
16 | Validate.isTrue(N == sigma.length);
|
---|
17 |
|
---|
18 | Matrix sigmaMat = new Matrix(sigma);
|
---|
19 | Matrix xMat = new Matrix(x, 1);
|
---|
20 | Matrix muMat = new Matrix(mu, 1);
|
---|
21 |
|
---|
22 | double constant = 1 / Math.sqrt(Math.pow(2 * Math.PI, N)
|
---|
23 | * sigmaMat.det());
|
---|
24 |
|
---|
25 | Matrix xMinMu = xMat.minus(muMat);
|
---|
26 |
|
---|
27 | double d = xMinMu.times(sigmaMat.inverse()).times(xMinMu.transpose())
|
---|
28 | .get(0, 0);
|
---|
29 |
|
---|
30 | return constant * Math.exp(-0.5 * d);
|
---|
31 | }
|
---|
32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.