Package Jama

Examples of Jama.Matrix


      return false;
    }

    final TranslationTransform t1t2 = t1.concatenate( t2 );

    final Matrix mt1 = new Matrix( t1.getMatrix() );
    final Matrix mt2 = new Matrix( t2.getMatrix() );
    final Matrix mt1t2 = new Matrix( t1t2.getMatrix() );

    if ( mt1.times( mt2 ).minus( mt1t2 ).normF() > 0.1 )
    {
      System.out.println( "=======================" );
      System.out.println( "t1: " + t1.numSourceDimensions() + " -> " + t1.numTargetDimensions() + " (n -> m)" );
      System.out.println( "t2: " + t2.numSourceDimensions() + " -> " + t2.numTargetDimensions() + " (n -> m)" );
      System.out.println( "t1t2: " + t1t2.numSourceDimensions() + " -> " + t1t2.numTargetDimensions() + " (n -> m)" );

      System.out.print( "t1 = " );
      mt1.print( 1, 0 );
      System.out.print( "t2 = " );
      mt2.print( 1, 0 );
      System.out.print( "t1t2 = " );
      mt1t2.print( 1, 0 );
      System.out.print( "t1 x t2 = " );
      mt1.times( mt2 ).print( 1, 0 );

      System.out.println( "wrong result" );
      System.out.println( "=======================" );
View Full Code Here


      return false;
    }

    final TranslationTransform t1t2 = t2.preConcatenate( t1 );

    final Matrix mt1 = new Matrix( t1.getMatrix() );
    final Matrix mt2 = new Matrix( t2.getMatrix() );
    final Matrix mt1t2 = new Matrix( t1t2.getMatrix() );

    if ( mt1.times( mt2 ).minus( mt1t2 ).normF() > 0.1 )
    {
      System.out.println( "=======================" );
      System.out.println( "t1: " + t1.numSourceDimensions() + " -> " + t1.numTargetDimensions() + " (n -> m)" );
      System.out.println( "t2: " + t2.numSourceDimensions() + " -> " + t2.numTargetDimensions() + " (n -> m)" );
      System.out.println( "t1t2: " + t1t2.numSourceDimensions() + " -> " + t1t2.numTargetDimensions() + " (n -> m)" );

      System.out.print( "t1 = " );
      mt1.print( 1, 0 );
      System.out.print( "t2 = " );
      mt2.print( 1, 0 );
      System.out.print( "t1t2 = " );
      mt1t2.print( 1, 0 );
      System.out.print( "t1 x t2 = " );
      mt1.times( mt2 ).print( 1, 0 );

      System.out.println( "wrong result" );
      System.out.println( "=======================" );
View Full Code Here

     * This is a horrible cludge to use the jama matrix class for
     * inversion/qr decomposition until the preferable
     * Apache commons class catches up. Matrix is the Jama version
     * RealMatrixImpl is the commons version.
     */
    Matrix v = new Matrix(new VandermondeMatrix(x,order+1).getMatrix().getData());
    QRDecomposition qr = new QRDecomposition(v);
    rMatrix = new RealMatrixImpl(qr.getR().getArray());
    qMatrix = new RealMatrixImpl(qr.getQ().getArray());
    RealMatrix qMatrixTransposed = qMatrix.transpose();
    RealMatrix qByY = qMatrixTransposed.multiply(yMatrix);
    RealMatrix  rMatrixInverse = new RealMatrixImpl(new Matrix(rMatrix.getData()).inverse().getArray());
    RealMatrix resultMatrix = rMatrixInverse.multiply(qByY);
    coefficiants= resultMatrix.getColumn(0);

    //System.out.println(stdDev+" "+mean);
  }
View Full Code Here

   */
 
  private static void ComputeSparseCode(double[] desc, ArrayList<Integer> cl, double[][] centers){
   
    // Matrix S : initial SIFT vector to approximate : S = C*Alpha + epsilon
    Matrix S = new Matrix(desc, desc.length);
    // Matrix S : Matrix containing coordinates of the k-nn Centers from S  
    double [][] ClosestCenters = new double[centers[0].length][knn];
    for(int i=0;i<knn;i++){
      for(int j=0;j<centers[0].length;j++){
        ClosestCenters[j][i] = centers[cl.get(i)][j];
      }
    }
    Matrix C = new Matrix(ClosestCenters);
    // Least-square Optimisation
    Matrix Ct = C.transpose();
    Matrix Gamma = (Ct.times(C)).inverse();
    Matrix SC = (Gamma.times(Ct)).times(S);
   
    SparseCode = new double[knn];
    for(int i=0;i<knn;i++){
      SparseCode[i] = Math.abs(SC.get(i,0));
   
     
//    // Debog
//    System.out.println("********************* Sparse code computation ********************");
//    Matrix Sr = C.times(SC);
View Full Code Here

  }
 
  private static void ComputeConstrainedSparseCode(double[] desc, ArrayList<Integer> cl, double[][] centers){
   
    // Matrix S : initial SIFT vector to approximate : S = C*Alpha + epsilon
    Matrix S = new Matrix(desc, desc.length);
    // Matrix S : Matrix containing coordinates of the k-nn Centers from S  
    double [][] ClosestCenters = new double[centers[0].length][knn];
    for(int i=0;i<knn;i++){
      for(int j=0;j<centers[0].length;j++){
        ClosestCenters[j][i] = centers[cl.get(i)][j];
      }
    }
    Matrix C = new Matrix(ClosestCenters);
    // Contraint R*Alpha=r - Here we choose the constraint Sum Alpha = 1
    // R : row vector (1,...,1) - r scalar value (1)
    double [] constraints = new double[knn];
    for(int i=0;i<knn;i++){
      constraints[i] = 1.0;
    }
    Matrix R = new Matrix(constraints, 1);
    Matrix Rt = R.transpose();
    Matrix r = new Matrix(1, 1);
    r.set(0, 0,1.0);
    // Least-square Optimisation
    Matrix Ct = C.transpose();
    Matrix Gamma = (Ct.times(C)).inverse();
    // Least square solution without constraints
    Matrix SC = (Gamma.times(Ct)).times(S);
    // Least square solution with constraint R*Alpha=r
    Matrix SCc = SC.minus( (Gamma.times(Rt)).times( (R.times(Gamma).times(Rt) ).inverse() ).times((R.times(SC)).minus(r)) ) ;
   
    // Sparse code : abs(Alpha)
    SparseCode = new double[knn];
    for(int i=0;i<knn;i++){
      SparseCode[i] = Math.abs(SCc.get(i,0));
    }

    // Debog
    //System.out.println("********************* Constrained Sparse code computation ********************");
//    Matrix Src = C.times(SCc);
View Full Code Here

      matrixVal[0][col] = (vertices[col].getx() - mixColor.getx()) / vertices[col].gety();
      matrixVal[1][col] = (vertices[col].gety() - mixColor.gety()) / vertices[col].gety();
      matrixVal[2][col] = 1;
    }

    Matrix matrix = new Matrix(matrixVal);
    Matrix invMatrix = matrix.inverse();

    // the needed luminances of the light sources to produce the color mix
    double[] outLumi = new double[3];

    for(int i=0; i<3; i++){
      outLumi[i] = invMatrix.get(i, 2) * mixColor.getYlumi();
      // check if the luminance is negative
      if(outLumi[i] < 0){
        return null;
      }
    }
View Full Code Here

    /**
     * Initializes the {@link #matrix} and {@link #reference} matrices to random values.
     */
    private void createMatrices(final int numRow, final int numCol, final Random random) {
        matrix = new GeneralMatrix(numRow, numCol, false, 1);
        reference = new Matrix(numRow, numCol);
        for (int j=0; j<numRow; j++) {
            for (int i=0; i<numCol; i++) {
                final double e = random.nextDouble() * 1000;
                matrix.setElement(j, i, e);
                reference.set(j, i, e);
View Full Code Here

            random = TestUtilities.createRandomNumberGenerator();
        }
        for (int k=0; k<MatrixTestCase.NUMBER_OF_REPETITIONS; k++) {
            final int size = random.nextInt(16) + 1;
            createMatrices(size, random.nextInt(16) + 1, random);
            final Matrix referenceArg = this.reference;
            final MatrixSIS matrixArg = this.matrix;
            createMatrices(size, size, random);
            final Matrix jama;
            try {
                jama = reference.solve(referenceArg);
            } catch (RuntimeException e) {
                out.println(e); // "Matrix is singular."
                continue;
View Full Code Here

        validate(matrix);
        /*
         * The JAMA constructor uses column-major array (FORTRAN convention), while SIS uses
         * row-major array. So we have to transpose the JAMA matrix after construction.
         */
        assertEqualsJAMA(new Matrix(elements, numCol).transpose(), matrix, STRICT);
        assertArrayEquals("getElements", elements, matrix.getElements(), STRICT);
    }
View Full Code Here

        prepareNewMatrixSize(random);
        final int numRow = getNumRow();
        final int numCol = getNumCol();
        final MatrixSIS matrix = Matrices.createZero(numRow, numCol);
        validate(matrix);
        final Matrix reference = new Matrix(numRow, numCol);
        /*
         * End of initialization - now perform the actual test.
         */
        assertEqualsJAMA(reference, matrix, STRICT);
        for (int k=0; k<50; k++) {
            final int    j = random.nextInt(numRow);
            final int    i = random.nextInt(numCol);
            final double e = random.nextDouble() * 100;
            reference.set(j, i, e);
            matrix.setElement(j, i, e);
            assertEqualsJAMA(reference, matrix, STRICT);
        }
    }
View Full Code Here

TOP

Related Classes of Jama.Matrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.