@Override public long process(BenchmarkMatrix[] inputs, BenchmarkMatrix[] outputs, long numTrials) { SimpleMatrix matA = inputs[0].getOriginal(); SimpleMatrix matB = inputs[1].getOriginal(); SimpleMatrix result = null; long prev = System.nanoTime(); for( long i = 0; i < numTrials; i++ ) { result = matA.solve(matB); } long elapsedTime = System.nanoTime()-prev; if( outputs != null ) { outputs[0] = new EjmlSimpleBenchmarkMatrix(result); } return elapsedTime; } }
/** * Finds the values of a,b,c which minimize * * sum (a*x(+)_i + b*y(+)_i + c - x(-)_i)^2 * * See page 306 * * @return Affine transform */ private SimpleMatrix computeAffineH( List<AssociatedPair> observations , DenseMatrix64F H , DenseMatrix64F Hzero ) { SimpleMatrix A = new SimpleMatrix(observations.size(),3); SimpleMatrix b = new SimpleMatrix(A.numRows(),1); Point2D_F64 c = new Point2D_F64(); Point2D_F64 k = new Point2D_F64(); for( int i = 0; i < observations.size(); i++ ) { AssociatedPair a = observations.get(i); GeometryMath_F64.mult(Hzero, a.p1, k); GeometryMath_F64.mult(H,a.p2,c); A.setRow(i,0,k.x,k.y,1); b.set(i,0,c.x); } SimpleMatrix x = A.solve(b); SimpleMatrix Ha = SimpleMatrix.identity(3); Ha.setRow(0,0,x.getMatrix().data); return Ha; }
/** * Finds the values of a,b,c which minimize * * sum (a*x(+)_i + b*y(+)_i + c - x(-)_i)^2 * * See page 306 * * @return Affine transform */ private SimpleMatrix computeAffineH( List<AssociatedPair> observations , DMatrixRMaj H , DMatrixRMaj Hzero ) { SimpleMatrix A = new SimpleMatrix(observations.size(),3); SimpleMatrix b = new SimpleMatrix(A.numRows(),1); Point2D_F64 c = new Point2D_F64(); Point2D_F64 k = new Point2D_F64(); for( int i = 0; i < observations.size(); i++ ) { AssociatedPair a = observations.get(i); GeometryMath_F64.mult(Hzero, a.p1, k); GeometryMath_F64.mult(H,a.p2,c); A.setRow(i,0,k.x,k.y,1); b.set(i,0,c.x); } SimpleMatrix x = A.solve(b); SimpleMatrix Ha = SimpleMatrix.identity(3); Ha.setRow(0,0,x.getDDRM().data); return Ha; }
x = A.solve(b); System.out.println(x); } catch ( SingularMatrixException e ) {
/** * Examines the matrix structure to determine how to parameterize F. */ @Override public void encode(DenseMatrix64F F, double[] param) { // see if which columns are to be used selectColumns(F); // set the largest element in the first two columns and normalize // using that value double v[] = new double[]{F.get(0,col0),F.get(1,col0),F.get(2,col0), F.get(0,col1),F.get(1,col1),F.get(2,col1)}; double divisor = selectDivisor(v,param); // solve for alpha and beta and put into param SimpleMatrix A = new SimpleMatrix(3,2); SimpleMatrix y = new SimpleMatrix(3,1); for( int i = 0; i < 3; i++ ) { A.set(i,0,v[i]); A.set(i,1,v[i+3]); y.set(i,0,F.get(i,col2)/divisor); } SimpleMatrix x = A.solve(y); param[5] = x.get(0); param[6] = x.get(1); }
/** * Examines the matrix structure to determine how to parameterize F. */ @Override public void encode(DMatrixRMaj F, double[] param) { // see if which columns are to be used selectColumns(F); // set the largest element in the first two columns and normalize // using that value double v[] = new double[]{F.get(0,col0),F.get(1,col0),F.get(2,col0), F.get(0,col1),F.get(1,col1),F.get(2,col1)}; double divisor = selectDivisor(v,param); // solve for alpha and beta and put into param SimpleMatrix A = new SimpleMatrix(3,2); SimpleMatrix y = new SimpleMatrix(3,1); for( int i = 0; i < 3; i++ ) { A.set(i,0,v[i]); A.set(i,1,v[i+3]); y.set(i,0,F.get(i,col2)/divisor); } SimpleMatrix x = A.solve(y); param[5] = x.get(0); param[6] = x.get(1); }
BBB = B.transpose().mult(B).solve(B.transpose()); } else { BBB = B.invert();