/** * Sets the eigenvector u for the tensor with specified indices. * The specified vector is assumed to have length one. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param u {u1,u2} of eigenvector components. */ public void setEigenvectorU(int i1, int i2, float[] u) { setEigenvectorU(i1,i2,u[0],u[1]); }
/** * Constructs tensors for specified array dimensions and eigenvalues. * @param u1 array of 1st components of u. * @param u2 array of 2nd components of u. * @param au array of 1D eigenvalues. * @param av array of 2D eigenvalues. */ public EigenTensors2( float[][] u1, float[][] u2, float[][] au, float[][] av) { this(u1[0].length,u1.length); for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { float aui = au[i2][i1]; float avi = av[i2][i1]; float u1i = u1[i2][i1]; float u2i = u2[i2][i1]; setEigenvalues(i1,i2,aui,avi); setEigenvectorU(i1,i2,u1i,u2i); } } }
/** * Sets tensor elements for specified indices. * This method first computes an eigen-decomposition of the specified * tensor, and then stores the computed eigenvectors and eigenvalues. * The eigenvalues are ordered such that au >= av >= 0. * @param i1 index for 1st dimension. * @param i2 index for 2nd dimension. * @param a11 tensor element a11. * @param a12 tensor element a12. * @param a22 tensor element a22. */ public void setTensor(int i1, int i2, float a11, float a12, float a22) { float[][] aa = { {a11,a12}, {a12,a22} }; float[][] vv = new float[2][2]; float[] ev = new float[2]; Eigen.solveSymmetric22(aa,vv,ev); float[] u = vv[0]; float au = ev[0]; if (au<0.0f) au = 0.0f; float av = ev[1]; if (av<0.0f) av = 0.0f; setEigenvectorU(i1,i2,u); setEigenvalues(i1,i2,au,av); }
private static void testRandom(double errorAngle, double errorCoeff) { int n1 = 13, n2 = 14; EigenTensors2 et = new EigenTensors2(n1,n2); for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { float[] a = makeRandomEigenvalues(); float[] u = makeRandomEigenvector(); et.setEigenvalues(i1,i2,a); et.setEigenvectorU(i1,i2,u); float[] c; c = et.getEigenvectorU(i1,i2); checkEigenvectors(u,c,errorAngle); c = et.getEigenvalues(i1,i2); checkEigenvalues(c,a,errorCoeff); et.setTensor(i1,i2,et.getTensor(i1,i2)); c = et.getEigenvectorU(i1,i2); checkEigenvectors(u,c,errorAngle); c = et.getEigenvalues(i1,i2); checkEigenvalues(c,a,errorCoeff); } } }