CholeskyDecomposition c = new Matrix(arr).chol(); fchol.setSPD(c.isSPD()); arr = c.getL().getArray();
public void test () { Log.info("CholTest::test enter"); for (int sz = 6000; sz < 10000; sz+=2000) { Log.info("CholTest::test sz is " + sz); DataSetup data = new DataSetup(sz, 12345); long start = System.currentTimeMillis(); CholeskyDecomposition jamaChol = new Matrix(data.xx).chol(); Log.info("JAMA CHOLESKY [N = " + sz + "] TAKES " + (System.currentTimeMillis() - start) + " MILLISECONDS."); if (!jamaChol.isSPD()) continue; ForkJoinPool fjp = new ForkJoinPool(32); for (int t = 2; t <= 32; t += 2) { for (int step : STEPS) fjp.invoke(new TestSetup(new DataSetup(data.xx),jamaChol.getL().getArray(),step,t)); } } Log.info("CholTest::test exit"); }
public Matrix chol() { CholeskyDecomposition chol = new CholeskyDecomposition(matrix); Matrix r = new JamaDenseDoubleMatrix2D(chol.getL()); return r; }
public Matrix chol() { CholeskyDecomposition chol = new CholeskyDecomposition(matrix); Matrix r = new JamaDenseDoubleMatrix2D(chol.getL()); return r; }
protected void cacheValues() { inv_covar = covar.inverse(); pdf_const_factor = 1.0 / Math.sqrt((Math.pow((2 * Math.PI), N) * covar.det())); chol = covar.chol().getL(); }
@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { Matrix matA = inputs[0].getOriginal(); Matrix L = null; long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { CholeskyDecomposition chol = matA.chol(); if( !chol.isSPD() ) { throw new DetectedException("Is not SPD"); } L = chol.getL(); } long elapsed = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new JamaBenchmarkMatrix(L); } return elapsed; } }
@Override public double[] sample(Random rng) { final int N = mean.getColumnDimension(); final Matrix chol = getCovariance().chol().getL(); final Matrix vec = new Matrix(N, 1); for (int i = 0; i < N; i++) vec.set(i, 0, rng.nextGaussian()); final Matrix result = this.mean.plus(chol.times(vec).transpose()); return result.getArray()[0]; }
public double [] sample(Random random) { Matrix L = getChol().getL(); // start with a vector of iid std normals Matrix stdNormal = new Matrix(dim(), 1); for (int i = 0; i < dim(); i++) { stdNormal.set(i, 0, SampleUtils.sampleGaussian(random)); } Matrix result = L.times(stdNormal); result.plusEquals(mean); return result.getColumnPackedCopy(); } public double[] sampleObject(Random random) { return sample(random); }
@Override public double[][] sample(int nsamples, Random rng) { if (nsamples == 0) return new double[0][0]; final int N = mean.getColumnDimension(); final Matrix chol = getCovariance().chol().getL(); final Matrix vec = new Matrix(N, nsamples); for (int i = 0; i < N; i++) for (int j = 0; j < nsamples; j++) vec.set(i, j, rng.nextGaussian()); final Matrix result = chol.times(vec).transpose(); for (int i = 0; i < result.getRowDimension(); i++) for (int j = 0; j < result.getColumnDimension(); j++) result.set(i, j, result.get(i, j) + mean.get(0, j)); return result.getArray(); }
throw new RuntimeException("The covariance Matrix is not SDP, check your covariance function (maybe you mess the noise term..)"); } else{ L = cd.getL(); // cholesky factorization of the covariance
Matrix L = Chol.getL(); try { check(A,L.times(L.transpose()));