cern.colt.matrix.DoubleFactory2D Java Examples
The following examples show how to use
cern.colt.matrix.DoubleFactory2D.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Statistic.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** * Demonstrates usage of this class. */ public static void demo3(VectorVectorFunction norm) { double[][] values = { { -0.9611052, -0.25421095 }, { 0.4308269, -0.69932648 }, { -1.2071029, 0.62030596 }, { 1.5345166, 0.02135884}, {-1.1341542, 0.20388430} }; System.out.println("\n\ninitializing..."); DoubleFactory2D factory = DoubleFactory2D.dense; DoubleMatrix2D A = factory.make(values).viewDice(); System.out.println("\nA="+A.viewDice()); System.out.println("\ndist="+distance(A,norm).viewDice()); }
Example #2
Source File: EigenvalueDecomposition.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** Returns the block diagonal eigenvalue matrix, <tt>D</tt>. @return <tt>D</tt> */ public DoubleMatrix2D getD() { double[][] D = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { D[i][j] = 0.0; } D[i][i] = d[i]; if (e[i] > 0) { D[i][i+1] = e[i]; } else if (e[i] < 0) { D[i][i-1] = e[i]; } } return DoubleFactory2D.dense.make(D); }
Example #3
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** */ public static void doubleTest34() { double[][] data = { { 3, 0, 0, 0 }, { 0, 4, 2, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, }; DoubleMatrix2D A = new DenseDoubleMatrix2D(data); Property.DEFAULT.generateNonSingular(A); DoubleMatrix2D inv = Algebra.DEFAULT.inverse(A); System.out.println("\n\n\n"+A); System.out.println("\n"+inv); DoubleMatrix2D B = A.zMult(inv,null); System.out.println(B); if (!(B.equals(DoubleFactory2D.dense.identity(A.rows)))) { throw new InternalError(); } }
Example #4
Source File: RobustEigenDecomposition.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
/** Returns the block diagonal eigenvalue matrix, <tt>D</tt>. @return <tt>D</tt> */ public DoubleMatrix2D getD() { double[][] D = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { D[i][j] = 0.0; } D[i][i] = d[i]; if (e[i] > 0) { D[i][i+1] = e[i]; } else if (e[i] < 0) { D[i][i-1] = e[i]; } } return DoubleFactory2D.dense.make(D); }
Example #5
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest14(int r1, int c, int r2) { double[] values = {0, 1, 2, 3}; DoubleMatrix2D a = DoubleFactory2D.dense.ascending(r1,c); DoubleMatrix2D b = Transform.mult(DoubleFactory2D.dense.ascending(c,r2), -1); //System.out.println(a); //System.out.println(b); //System.out.println(Basic.product(a,b)); a.assign(0); b.assign(0); cern.colt.Timer timer = new cern.colt.Timer().start(); LinearAlgebra.mult(a,b); timer.stop().display(); }
Example #6
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** */ public static void doubleTest29(DoubleFactory2D f) { double[][] data = { { 6, 5, 4 }, { 7, 6, 3 }, { 6, 5, 4 }, { 7, 6, 3 }, { 6, 5, 4 }, { 7, 6, 3 } }; double[][] arrMatrix = { { 1, 2, 3, 4, 5, 6}, { 2, 3, 4, 5, 6, 7} }; DoubleMatrix2D x = new DenseDoubleMatrix2D(data); DoubleMatrix2D matrix = f.make(arrMatrix); DoubleMatrix2D res = matrix.zMult(x,null); System.out.println(res); }
Example #7
Source File: Statistic.java From database with GNU General Public License v2.0 | 6 votes |
/** * Demonstrates usage of this class. */ public static void demo2(int rows, int columns, boolean print) { System.out.println("\n\ninitializing..."); DoubleFactory2D factory = DoubleFactory2D.dense; DoubleMatrix2D A = factory.ascending(rows,columns); //double value = 1; //DoubleMatrix2D A = factory.make(rows,columns); //A.assign(value); System.out.println("benchmarking correlation..."); cern.colt.Timer timer = new cern.colt.Timer().start(); DoubleMatrix2D corr = correlation(covariance(A)); timer.stop().display(); if (print) { System.out.println("printing result..."); System.out.println(corr); } System.out.println("done."); }
Example #8
Source File: Statistic.java From database with GNU General Public License v2.0 | 6 votes |
/** * Demonstrates usage of this class. */ public static void demo1() { double[][] values = { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 }, { 4, -8, -10 } }; DoubleFactory2D factory = DoubleFactory2D.dense; DoubleMatrix2D A = factory.make(values); System.out.println("\n\nmatrix="+A); System.out.println("\ncovar1="+covariance(A)); //System.out.println(correlation(covariance(A))); //System.out.println(distance(A,EUCLID)); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(A.toString())); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(covariance(A).toString())); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(correlation(covariance(A)).toString())); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(distance(A,EUCLID).toString())); }
Example #9
Source File: MassPreconditioner.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
public double[] transformMatrix(double[][] inputMatrix, int dim) { Algebra algebra = new Algebra(); DoubleMatrix2D H = new DenseDoubleMatrix2D(inputMatrix); RobustEigenDecomposition decomposition = new RobustEigenDecomposition(H); DoubleMatrix1D eigenvalues = decomposition.getRealEigenvalues(); normalizeEigenvalues(eigenvalues); DoubleMatrix2D V = decomposition.getV(); transformEigenvalues(eigenvalues); double[][] negativeHessianInverse = algebra.mult( algebra.mult(V, DoubleFactory2D.dense.diagonal(eigenvalues)), algebra.inverse(V) ).toArray(); double[] massArray = new double[dim * dim]; for (int i = 0; i < dim; i++) { System.arraycopy(negativeHessianInverse[i], 0, massArray, i * dim, dim); } return massArray; }
Example #10
Source File: BBFreeBlock.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
private DoubleMatrix2D getOrthogVectors(DoubleMatrix2D M){ //Get a matrix whose columns are orthogonal to the row space of M //which expected to be nonsingular DoubleMatrix2D Maug = DoubleFactory2D.dense.make(M.columns(), M.columns()); Maug.viewPart(0, 0, M.rows(), M.columns()).assign(M); SingularValueDecomposition svd = new SingularValueDecomposition(Maug); int numOrthVecs = M.columns() - M.rows(); if(svd.rank() != M.rows()){ throw new RuntimeException("ERROR: Singularity in constr jac. Rank: "+svd.rank()); } DoubleMatrix2D orthVecs = svd.getV().viewPart(0, M.rows(), M.columns(), numOrthVecs); //DEBUG!!! Should be 0 and identity respecitvely /*DoubleMatrix2D check = Algebra.DEFAULT.mult(M, orthVecs); DoubleMatrix2D checkOrth = Algebra.DEFAULT.mult( Algebra.DEFAULT.transpose(orthVecs), orthVecs); */ return orthVecs; }
Example #11
Source File: MinVolEllipse.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
DoubleMatrix2D homMatrix(){ //Return M, where this ellipse is represented as [x^T 1]M[x;1]=0 int n = c.size(); DoubleMatrix2D ans = DoubleFactory2D.dense.make(n+1,n+1); DoubleMatrix1D Qnc = A.zMult(nc, null); for(int a=0; a<n; a++){ for(int b=0; b<n; b++) ans.setQuick( a, b, A.get(a,b) ); ans.setQuick(a, n, Qnc.get(a)); ans.setQuick(n, a, Qnc.get(a)); } ans.setQuick(n, n, Qnc.zDotProduct(nc)-1 ); return ans; }
Example #12
Source File: MinVolEllipse.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
static DoubleMatrix2D QuQt(DoubleMatrix2D Q, DoubleMatrix1D u){ //Return matrix product of Q * diagonal version of u * Q^T //answer = \sum_i ( u_i * q_i * q_i') is a (d+1)x(d+1) matrix int m = Q.rows(); int n = Q.columns(); if(u.size()!=n){ throw new Error("Size mismatch in QuQt: "+n+" columns in Q, u length="+u.size()); } DoubleMatrix2D ans = DoubleFactory2D.dense.make(m,m); for(int i=0; i<m; i++){ for(int j=0; j<m; j++){ double s = 0; for(int k=0; k<n; k++) s += Q.getQuick(i,k)*Q.getQuick(j,k)*u.get(k); ans.setQuick(i, j, s); } } return ans; }
Example #13
Source File: Statistic.java From database with GNU General Public License v2.0 | 6 votes |
/** * Demonstrates usage of this class. */ public static void demo3(VectorVectorFunction norm) { double[][] values = { { -0.9611052, -0.25421095 }, { 0.4308269, -0.69932648 }, { -1.2071029, 0.62030596 }, { 1.5345166, 0.02135884}, {-1.1341542, 0.20388430} }; System.out.println("\n\ninitializing..."); DoubleFactory2D factory = DoubleFactory2D.dense; DoubleMatrix2D A = factory.make(values).viewDice(); System.out.println("\nA="+A.viewDice()); System.out.println("\ndist="+distance(A,norm).viewDice()); }
Example #14
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** */ public static void doubleTest28() { double[] data={1,2,3,4,5,6}; double[][] arrMatrix = { { 1, 2, 3, 4, 5, 6}, { 2, 3, 4, 5, 6, 7} }; DoubleFactory2D f = DoubleFactory2D.dense; DoubleMatrix1D vector = new DenseDoubleMatrix1D(data); DoubleMatrix2D matrix = f.make(arrMatrix); DoubleMatrix1D res = vector.like(matrix.rows()); matrix.zMult(vector,res); System.out.println(res); }
Example #15
Source File: PepPlaneLinModel.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
public PepPlaneLinModel(Residue res1, Residue res2){ //construct from the current conformations //of the residue involved in this peptide plane if(res1.template.name.equalsIgnoreCase("PRO") || res2.template.name.equalsIgnoreCase("PRO")) throw new RuntimeException("ERROR: CATS doesn't handle proline"); double CA1[] = res1.getCoordsByAtomName("CA"); double CA2[] = res2.getCoordsByAtomName("CA"); double N[] = res2.getCoordsByAtomName("N"); double C[] = res1.getCoordsByAtomName("C"); double O[] = res1.getCoordsByAtomName("O"); double H[] = res2.getCoordsByAtomName("H"); DoubleMatrix2D M = makeAxisMatrix(CA1,N,CA2); DoubleMatrix2D vec = DoubleFactory2D.dense.make(3,1); vec.viewColumn(0).assign(VectorAlgebra.subtract(C, CA1)); CCoeffs = Algebra.DEFAULT.solve(M, vec).viewColumn(0); vec.viewColumn(0).assign(VectorAlgebra.subtract(O, CA1)); OCoeffs = Algebra.DEFAULT.solve(M, vec).viewColumn(0); vec.viewColumn(0).assign(VectorAlgebra.subtract(H, CA1)); HCoeffs = Algebra.DEFAULT.solve(M, vec).viewColumn(0); }
Example #16
Source File: VoxelVDWListChecker.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
public static DoubleMatrix2D getOrthogVectors(DoubleMatrix2D M){ //Get a matrix whose columns are orthogonal to the row space of M //which expected to be nonsingular DoubleMatrix2D Maug = DoubleFactory2D.dense.make(M.columns(), M.columns()); Maug.viewPart(0, 0, M.rows(), M.columns()).assign(M); SingularValueDecomposition svd = new SingularValueDecomposition(Maug); int numOrthVecs = M.columns() - M.rows(); if(svd.rank() != M.rows()){ throw new RuntimeException("ERROR: Singularity in constr jac. Rank: "+svd.rank()); } DoubleMatrix2D orthVecs = svd.getV().viewPart(0, M.rows(), M.columns(), numOrthVecs); //DEBUG!!! Should be 0 and identity respecitvely /*DoubleMatrix2D check = Algebra.DEFAULT.mult(M, orthVecs); DoubleMatrix2D checkOrth = Algebra.DEFAULT.mult( Algebra.DEFAULT.transpose(orthVecs), orthVecs); */ return orthVecs; }
Example #17
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest28() { double[] data={1,2,3,4,5,6}; double[][] arrMatrix = { { 1, 2, 3, 4, 5, 6}, { 2, 3, 4, 5, 6, 7} }; DoubleFactory2D f = DoubleFactory2D.dense; DoubleMatrix1D vector = new DenseDoubleMatrix1D(data); DoubleMatrix2D matrix = f.make(arrMatrix); DoubleMatrix1D res = vector.like(matrix.rows()); matrix.zMult(vector,res); System.out.println(res); }
Example #18
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest28(DoubleFactory2D f) { double[] data={1,2,3,4,5,6}; double[][] arrMatrix = { { 1, 2, 3, 4, 5, 6}, { 2, 3, 4, 5, 6, 7} }; DoubleMatrix1D vector = new DenseDoubleMatrix1D(data); DoubleMatrix2D matrix = f.make(arrMatrix); DoubleMatrix1D res = vector.like(matrix.rows()); matrix.zMult(vector,res); System.out.println(res); }
Example #19
Source File: SeriesFitter.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
static DoubleMatrix2D getHessian(double coeffs[], int numDOFs, boolean includeConst){ //Extract the Hessian from the given series coeffs, //which are expected to have order>=2 int count = numDOFs;//start at first index in coeffs for a second-order coefficient if(includeConst) count++; DoubleMatrix2D hess = DoubleFactory2D.dense.make(numDOFs,numDOFs); for(int a=0; a<numDOFs; a++){ for(int b=0; b<=a; b++){ double hessVal = coeffs[count]; if(b==a) hessVal *= 2; hess.set(a, b, hessVal); hess.set(b, a, hessVal); count++; } } return hess; }
Example #20
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest29(DoubleFactory2D f) { double[][] data = { { 6, 5, 4 }, { 7, 6, 3 }, { 6, 5, 4 }, { 7, 6, 3 }, { 6, 5, 4 }, { 7, 6, 3 } }; double[][] arrMatrix = { { 1, 2, 3, 4, 5, 6}, { 2, 3, 4, 5, 6, 7} }; DoubleMatrix2D x = new DenseDoubleMatrix2D(data); DoubleMatrix2D matrix = f.make(arrMatrix); DoubleMatrix2D res = matrix.zMult(x,null); System.out.println(res); }
Example #21
Source File: TestMatrix2D.java From database with GNU General Public License v2.0 | 6 votes |
/** */ public static void doubleTest34() { double[][] data = { { 3, 0, 0, 0 }, { 0, 4, 2, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, }; DoubleMatrix2D A = new DenseDoubleMatrix2D(data); Property.DEFAULT.generateNonSingular(A); DoubleMatrix2D inv = Algebra.DEFAULT.inverse(A); System.out.println("\n\n\n"+A); System.out.println("\n"+inv); DoubleMatrix2D B = A.zMult(inv,null); System.out.println(B); if (!(B.equals(DoubleFactory2D.dense.identity(A.rows)))) { throw new InternalError(); } }
Example #22
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** */ public static void doubleTest14(int r1, int c, int r2) { double[] values = {0, 1, 2, 3}; DoubleMatrix2D a = DoubleFactory2D.dense.ascending(r1,c); DoubleMatrix2D b = Transform.mult(DoubleFactory2D.dense.ascending(c,r2), -1); //System.out.println(a); //System.out.println(b); //System.out.println(Basic.product(a,b)); a.assign(0); b.assign(0); cern.colt.Timer timer = new cern.colt.Timer().start(); LinearAlgebra.mult(a,b); timer.stop().display(); }
Example #23
Source File: EigenvalueDecomposition.java From database with GNU General Public License v2.0 | 6 votes |
/** Returns the block diagonal eigenvalue matrix, <tt>D</tt>. @return <tt>D</tt> */ public DoubleMatrix2D getD() { double[][] D = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { D[i][j] = 0.0; } D[i][i] = d[i]; if (e[i] > 0) { D[i][i+1] = e[i]; } else if (e[i] < 0) { D[i][i-1] = e[i]; } } return DoubleFactory2D.dense.make(D); }
Example #24
Source File: Statistic.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** * Demonstrates usage of this class. */ public static void demo1() { double[][] values = { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 }, { 4, -8, -10 } }; DoubleFactory2D factory = DoubleFactory2D.dense; DoubleMatrix2D A = factory.make(values); System.out.println("\n\nmatrix="+A); System.out.println("\ncovar1="+covariance(A)); //System.out.println(correlation(covariance(A))); //System.out.println(distance(A,EUCLID)); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(A.toString())); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(covariance(A).toString())); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(correlation(covariance(A)).toString())); //System.out.println(cern.colt.matrixpattern.Converting.toHTML(distance(A,EUCLID).toString())); }
Example #25
Source File: PositionConfSpace.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
private ArrayList<EllipseCoordDOF> makeEllCoords(boolean useEllipses, double dihValues[], ArrayList<DegreeOfFreedom> dofListForRot){ //build the ellipsoidal coordinates for an RC. Empty list if not using ellipses. ArrayList<EllipseCoordDOF> ellCoords = new ArrayList<>(); if(useEllipses){ // generate the list of ellipsoidal DOFs // TODO: move getellipsoidalcoords to ellipsetransform double[] ellValues = getEllipsoidalCoords(dihValues); DoubleMatrix2D A = DoubleFactory2D.dense.identity(ellValues.length); for (int i=0; i<ellValues.length; i++) { EllipseCoordDOF ellDOF = new EllipseCoordDOF( (i==0), i, ellValues[i], A, dofListForRot, dihValues); ellCoords.add(ellDOF); } } return ellCoords; }
Example #26
Source File: Statistic.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** * Demonstrates usage of this class. */ public static void demo2(int rows, int columns, boolean print) { System.out.println("\n\ninitializing..."); DoubleFactory2D factory = DoubleFactory2D.dense; DoubleMatrix2D A = factory.ascending(rows,columns); //double value = 1; //DoubleMatrix2D A = factory.make(rows,columns); //A.assign(value); System.out.println("benchmarking correlation..."); cern.colt.Timer timer = new cern.colt.Timer().start(); DoubleMatrix2D corr = correlation(covariance(A)); timer.stop().display(); if (print) { System.out.println("printing result..."); System.out.println(corr); } System.out.println("done."); }
Example #27
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 6 votes |
/** */ public static void doubleTest28(DoubleFactory2D f) { double[] data={1,2,3,4,5,6}; double[][] arrMatrix = { { 1, 2, 3, 4, 5, 6}, { 2, 3, 4, 5, 6, 7} }; DoubleMatrix1D vector = new DenseDoubleMatrix1D(data); DoubleMatrix2D matrix = f.make(arrMatrix); DoubleMatrix1D res = vector.like(matrix.rows()); matrix.zMult(vector,res); System.out.println(res); }
Example #28
Source File: MinVolEllipse.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
static DoubleMatrix2D unflattenMatrix(double serCoeffs[], int nd, boolean removeLast, boolean coeffForm){ //nd = number of dimensions int count=0; DoubleMatrix2D hess = DoubleFactory2D.dense.make(nd,nd); for(int a=0; a<nd; a++){ for(int b=0; b<=a; b++){ if(b==a){ if(removeLast && a==nd-1) hess.set(a,a,1); else hess.set(a,a,serCoeffs[count]); } else{ double co = serCoeffs[count]; if(!coeffForm) co /= 2; hess.set(a,b,co);//Hessian is symmetric hess.set(b,a,co);//but computing by Hessian double-counts off-diagonal series coefficients } count++; } } return hess; }
Example #29
Source File: QuadraticApproximator.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
public LinearSystem(List<Minimizer.Result> samples) { this.samples = samples; A = DoubleFactory2D.dense.make(samples.size(), coefficients.size()); b = DoubleFactory2D.dense.make(samples.size(), 1); for (int i=0; i<samples.size(); i++) { DoubleMatrix1D x = samples.get(i).dofValues; double energy = samples.get(i).energy; b.set(i, 0, energy); // degree 0 term A.set(i, 0, 1.0); // degree 1 terms for (int d1=0; d1<numDofs; d1++) { A.set(i, index1(d1), x.get(d1)); } // degree 2 terms for (int d1=0; d1<numDofs; d1++) { for (int d2=0; d2<=d1; d2++) { A.set(i, index2(d1, d2), x.get(d1)*x.get(d2)); } } } }
Example #30
Source File: TestMatrix2D.java From jAudioGIT with GNU Lesser General Public License v2.1 | 5 votes |
/** */ public static void doubleTest25(int size) { System.out.println("\n\n"); System.out.println("initializing..."); boolean dense = true; DoubleMatrix2D A; DoubleFactory2D factory; if (dense) factory = Factory2D.dense; else factory = Factory2D.sparse; double value = 0.5; A = factory.make(size,size,value); Property.generateNonSingular(A); cern.colt.Timer timer = new cern.colt.Timer().start(); System.out.println(A); System.out.println(Algebra.ZERO.inverse(A)); timer.stop().display(); System.out.println("done."); }