Examples of DenseMatrix64F


Examples of org.ejml.data.DenseMatrix64F

   * @return an array of two matrices containing {Q, L}
   */
  public static double[][][] eig(double[][] A) {
    int n = A.length;
    EigenDecomposition<DenseMatrix64F> dec = DecompositionFactory.eig(n, true, true);
    DenseMatrix64F G_ejml = new DenseMatrix64F(A);
    dec.decompose(G_ejml);
    double[][] lambda = new double[n][n];
    double[][] U = new double[n][];
    for(int i = 0 ; i < n ; i++) {
      lambda[i][i] = dec.getEigenvalue(i).getMagnitude();
      DenseMatrix64F u = dec.getEigenVector(i);
      U[i] = Arrays.copyOf(u.data, n);
     
    }
    return new double[][][]{ThreadedMatrixOperations.transi(U), lambda};
  }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

   * @param A input matrix
   * @return inverse of A
   */
  public static double[][] inv(final double[][] A) {
    int n = A.length;
    DenseMatrix64F A_ejml = new DenseMatrix64F(A);
   
    if(!CommonOps.invert(A_ejml))
      return null;
    double[][] A_inv = new double[n][n];
    for(int i = 0 ; i < n ; i++) {
      for(int j = 0 ; j < n ; j++) {
        A_inv[i][j] = A_ejml.get(i, j);
      }
    }
    return A_inv;
  }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

            for (int j = 3; j < neuroCount; j++) {
                matrix[i][j - 2] = this.getWeight(j, i + 2);
            }
        }
       
        DenseMatrix64F mx = this.solveLinearEquationSystem(matrix, freeMembers);
       
        this.getNeuron(INPUT_NEURON_ID).setNetOutput(this.getNeuron(INPUT_NEURON_ID).getActFct().activationPhi(mx.get(0, 0)));
        for (int i = 1; i < neuroCount - 2; i++) {
            this.getNeuron(i + 2).setNetOutput(this.getNeuron(i + 2).getActFct().activationPhi(mx.get(i, 0)));
        }
       
//        StaticMethods.showImage(this.generateNeuroImage(600), "");
//        try {Thread.sleep(1000000000);} catch (InterruptedException e) {}
    }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

     */
    public double propagateBackwards() {
        final int neuroCount = this.getNeuronCount();
       
        this.generateLinearEquationSystem();
        DenseMatrix64F mx = this.solveLinearEquationSystem(this.matrix, this.freeMembers);

//        StaticMethods.showImage(this.generateNeuroImage(700), "(" + this.getNeuronCount() + " neurons)");
//        try {Thread.sleep(1000000000);} catch (InterruptedException e) {}
       
        // Set neurons at accurate values.
       
        this.getNeuron(INPUT_NEURON_ID).setNetOutput(mx.get(2, 0));
        try {
            this.getNeuron(INPUT_NEURON_ID).setInput(this.getNeuron(INPUT_NEURON_ID).getActFct().inverseActivationPhi(mx.get(2, 0)));
        } catch (InversionNotSupportedException e) {
            throw new RuntimeException("All non-bias neurons should be invertible.");
        }
       
        for (int j = 0; j < neuroCount; j++) {
            this.getNeuron(j).setNetOutput(mx.get(j, 0));
        }
       
        return this.getNeuron(INPUT_NEURON_ID).getInput();
    }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

            }
        }
    }

    private DenseMatrix64F solveLinearEquationSystem(double[][] matrix, double[][] freeMembers) {
        DenseMatrix64F mA = new DenseMatrix64F(matrix);
        DenseMatrix64F mb = new DenseMatrix64F(freeMembers);
        DenseMatrix64F mx = new DenseMatrix64F(mA.numCols, 1);
       
        LinearSolver<DenseMatrix64F> solver = LinearSolverFactory.leastSquaresQrPivot(true, false);
        solver.setA(mA);
        solver.solve(mb, mx);
       
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

        checkMatrix(5,5);
        checkMatrix(7,7);
    }

    private void checkMatrix( int numRows , int numCols ) {
        DenseMatrix64F A = RandomMatrices.createRandom(numRows,numCols,-1,1,rand);

        QRExampleOps alg = new QRExampleOps();

        alg.decompose(A);

        DenseMatrix64F Q = alg.getQ();
        DenseMatrix64F R = alg.getR();

        DenseMatrix64F A_found = new DenseMatrix64F(numRows,numCols);
        CommonOps.mult(Q,R,A_found);

        assertTrue( MatrixFeatures.isIdentical(A,A_found,1e-8));
    }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

     */
    @Test
    public void testNumericalJacobian() {
        JacobianTestFunction func = new JacobianTestFunction();

        DenseMatrix64F param = new DenseMatrix64F(3,1, true, 2, -1, 4);

        LevenbergMarquardt alg = new LevenbergMarquardt(func);

        DenseMatrix64F X = RandomMatrices.createRandom(NUM_PTS,1,rand);

        DenseMatrix64F numJacobian = new DenseMatrix64F(3,NUM_PTS);
        DenseMatrix64F analyticalJacobian = new DenseMatrix64F(3,NUM_PTS);

        alg.configure(param,X,new DenseMatrix64F(NUM_PTS,1));
        alg.computeNumericalJacobian(param,X,numJacobian);
        func.deriv(X,analyticalJacobian);

        EjmlUnitTests.assertEquals(analyticalJacobian,numJacobian,1e-6);
    }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

     * @param numPoints How many sample points there are.
     */
    public void runTrivial( int numPoints ) {
        JacobianTestFunction func = new JacobianTestFunction();

        DenseMatrix64F paramInit = new DenseMatrix64F(3,1);
        DenseMatrix64F param = new DenseMatrix64F(3,1, true, 2, -1, 4);

        LevenbergMarquardt alg = new LevenbergMarquardt(func);

        DenseMatrix64F X = RandomMatrices.createRandom(numPoints,1,rand);
        DenseMatrix64F Y = new DenseMatrix64F(numPoints,1);
        func.compute(param,X,Y);

        alg.optimize(paramInit,X,Y);

        DenseMatrix64F foundParam = alg.getParameters();

        assertEquals(0,alg.getFinalCost(),1e-8);
        EjmlUnitTests.assertEquals(param,foundParam,1e-6);
    }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

        List<KalmanFilter> all = new ArrayList<KalmanFilter>();
        all.add( new KalmanFilterOps() );
        all.add( new KalmanFilterAlg() );
        all.add( simple );

        DenseMatrix64F priorX = new DenseMatrix64F(9,1, true, 0.5, -0.2, 0, 0, 0.2, -0.9, 0, 0.2, -0.5);
        DenseMatrix64F priorP = CommonOps.identity(9);

        DenseMatrix64F F = BenchmarkKalmanPerformance.createF(T);
        DenseMatrix64F Q = BenchmarkKalmanPerformance.createQ(T,0.1);
        DenseMatrix64F H = BenchmarkKalmanPerformance.createH();


        for( KalmanFilter f : all ) {
            f.configure(F,Q,H);
            f.setState(priorX,priorP);
            f.predict();
        }

        for( KalmanFilter f : all ) {
            compareFilters(simple,f);
        }

        DenseMatrix64F z = new DenseMatrix64F(H.numRows,1);
        DenseMatrix64F R = CommonOps.identity(H.numRows);

        for( KalmanFilter f : all ) {
            f.update(z,R);
        }
View Full Code Here

Examples of org.ejml.data.DenseMatrix64F

            compareFilters(simple,f);
        }
    }

    private void compareFilters( KalmanFilter a, KalmanFilter b ) {
            DenseMatrix64F testX = b.getState();
            DenseMatrix64F testP = b.getCovariance();

            DenseMatrix64F X = a.getState();
            DenseMatrix64F P = a.getCovariance();

            EjmlUnitTests.assertEquals(testX,X,1e-8);
            EjmlUnitTests.assertEquals(testP,P,1e-8);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.