本文整理汇总了Java中org.ejml.ops.CommonOps类的典型用法代码示例。如果您正苦于以下问题:Java CommonOps类的具体用法?Java CommonOps怎么用?Java CommonOps使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommonOps类属于org.ejml.ops包,在下文中一共展示了CommonOps类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MatrixFormulation
import org.ejml.ops.CommonOps; //导入依赖的package包/类
private MatrixFormulation() {
int numRows = response.length;
int numCols = predictors.length + ((hasIntercept) ? 1 : 0);
this.X = createMatrixA(numRows, numCols);
this.Xt = new DenseMatrix64F(numCols, numRows);
CommonOps.transpose(X, Xt);
this.XtXInv = new DenseMatrix64F(numCols, numCols);
this.b = new DenseMatrix64F(numCols, 1);
this.y = new DenseMatrix64F(numRows, 1);
solveSystem(numRows, numCols);
this.fitted = computeFittedValues();
this.residuals = computeResiduals();
this.sigma2 = estimateSigma2(numCols);
this.covarianceMatrix = new DenseMatrix64F(numCols, numCols);
CommonOps.scale(sigma2, XtXInv, covarianceMatrix);
}
示例2: calc
import org.ejml.ops.CommonOps; //导入依赖的package包/类
public Matrix calc(Matrix a, Matrix b) {
DenseMatrix64F a2 = null;
DenseMatrix64F b2 = null;
if (a instanceof EJMLDenseDoubleMatrix2D) {
a2 = ((EJMLDenseDoubleMatrix2D) a).getWrappedObject();
} else {
a2 = new EJMLDenseDoubleMatrix2D(a).getWrappedObject();
}
if (b instanceof EJMLDenseDoubleMatrix2D) {
b2 = ((EJMLDenseDoubleMatrix2D) b).getWrappedObject();
} else {
b2 = new EJMLDenseDoubleMatrix2D(b).getWrappedObject();
}
DenseMatrix64F x = new DenseMatrix64F(a2.numCols, b2.numCols);
CommonOps.solve(a2, b2, x);
return new EJMLDenseDoubleMatrix2D(x);
}
示例3: setDiffusionPrecision
import org.ejml.ops.CommonOps; //导入依赖的package包/类
@Override
public void setDiffusionPrecision(int precisionIndex, final double[] matrix, double logDeterminant) {
super.setDiffusionPrecision(precisionIndex, matrix, logDeterminant);
assert (inverseDiffusions != null);
final int offset = dimTrait * dimTrait * precisionIndex;
DenseMatrix64F precision = wrap(diffusions, offset, dimTrait, dimTrait);
DenseMatrix64F variance = new DenseMatrix64F(dimTrait, dimTrait);
CommonOps.invert(precision, variance);
unwrap(variance, inverseDiffusions, offset);
if (DEBUG) {
System.err.println("At precision index: " + precisionIndex);
System.err.println("precision: " + precision);
System.err.println("variance : " + variance);
}
}
示例4: setDiffusionPrecision
import org.ejml.ops.CommonOps; //导入依赖的package包/类
@Override
public void setDiffusionPrecision(int precisionIndex, final double[] matrix, double logDeterminant) {
super.setDiffusionPrecision(precisionIndex, matrix, logDeterminant);
assert (diffusions != null);
assert (inverseDiffusions != null);
final int offset = dimTrait * dimTrait * precisionIndex;
DenseMatrix64F precision = wrap(diffusions, offset, dimTrait, dimTrait);
DenseMatrix64F variance = new DenseMatrix64F(dimTrait, dimTrait);
CommonOps.invert(precision, variance);
unwrap(variance, inverseDiffusions, offset);
if (DEBUG) {
System.err.println("At precision index: " + precisionIndex);
System.err.println("precision: " + precision);
System.err.println("variance : " + variance);
}
}
示例5: computeDirection
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Compute the direction of optimization from the value vector and the Jacobean. This is where
* Gauss Newton really happens.
*/
private double[] computeDirection() {
DenseMatrix64F jacoMat = new DenseMatrix64F(jacobean);
// J^T J (nrOfCo x nrOfCo)
DenseMatrix64F jacoSquare = new DenseMatrix64F(nrOfVariables, nrOfVariables);
CommonOps.multInner(jacoMat, jacoSquare);
DenseMatrix64F fMat = new DenseMatrix64F(nrOfEquations, 1, true, values);
// J^T value (nrOfCo x 1)
DenseMatrix64F rhs = new DenseMatrix64F(nrOfVariables, 1);
CommonOps.multTransA(jacoMat, fMat, rhs);
// result = (J^TJ)^-1 J^T value (nrOfCo x 1)
// J^TJ result = J^T value
DenseMatrix64F result = new DenseMatrix64F(nrOfVariables, 1);
if (CommonOps.solve(jacoSquare, rhs, result)) {
return result.getData();
} else {
return null;
}
}
示例6: sampleToEigenSpace
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Converts a vector from sample space into eigen space.
*
* @param sampleData Sample space data.
* @return Eigen space projection.
*/
public double[] sampleToEigenSpace(double[] sampleData) {
if (sampleData.length != getDataMatrix().getNumCols()) {
throw new IllegalArgumentException("Unexpected sample length");
}
DenseMatrix64F mean = DenseMatrix64F.wrap(getDataMatrix().getNumCols(), 1, this.getMean());
DenseMatrix64F s = new DenseMatrix64F(getDataMatrix().getNumCols(), 1, true, sampleData);
DenseMatrix64F r = new DenseMatrix64F(getNumPrincipalComponents(), 1);
CommonOps.sub(s, mean, s);
CommonOps.mult(getPrincipalComponentSubspace(), s, r);
return r.data;
}
示例7: eigenToSampleSpace
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Converts a vector from eigen space into sample space.
*
* @param eigenData Eigen space data.
* @return Sample space projection.
*/
public double[] eigenToSampleSpace(double[] eigenData) {
if (eigenData.length != getNumPrincipalComponents()) {
throw new IllegalArgumentException("Unexpected sample length");
}
DenseMatrix64F s = new DenseMatrix64F(getDataMatrix().getNumCols(), 1);
DenseMatrix64F r = DenseMatrix64F.wrap(getNumPrincipalComponents(), 1, eigenData);
CommonOps.multTransA(getPrincipalComponentSubspace(), r, s);
DenseMatrix64F mean = DenseMatrix64F.wrap(getDataMatrix().getNumCols(), 1, this.getMean());
CommonOps.add(s, mean, s);
return s.data;
}
示例8: transformRectToPixel_F32
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* <p>
* Creates a transform that goes from rectified to original distorted pixel coordinates.
* Rectification includes removal of lens distortion. Used for rendering rectified images.
* </p>
*
* <p>
* The original image coordinate system is maintained even if the intrinsic parameter flipY is true.
* </p>
*
* @param param Intrinsic parameters.
* @param rectify Transform for rectifying the image.
* @return Transform from rectified to unrectified pixels
*/
public static PointTransform_F32 transformRectToPixel_F32(IntrinsicParameters param,
DenseMatrix64F rectify)
{
AddRadialPtoP_F32 addDistortion = new AddRadialPtoP_F32();
addDistortion.set(param.fx, param.fy, param.skew, param.cx, param.cy, param.radial);
DenseMatrix64F rectifyInv = new DenseMatrix64F(3,3);
CommonOps.invert(rectify,rectifyInv);
PointTransformHomography_F32 removeRect = new PointTransformHomography_F32(rectifyInv);
if( param.flipY) {
PointTransform_F32 flip = new FlipVertical_F32(param.height);
return new SequencePointTransform_F32(flip,removeRect,addDistortion,flip);
} else {
return new SequencePointTransform_F32(removeRect,addDistortion);
}
}
示例9: transformRectToPixel_F64
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* <p>
* Creates a transform that goes from rectified to original distorted pixel coordinates.
* Rectification includes removal of lens distortion. Used for rendering rectified images.
* </p>
*
* <p>
* The original image coordinate system is maintained even if the intrinsic parameter flipY is true.
* </p>
*
* @param param Intrinsic parameters.
* @param rectify Transform for rectifying the image.
* @return Transform from rectified to unrectified pixels
*/
public static PointTransform_F64 transformRectToPixel_F64(IntrinsicParameters param,
DenseMatrix64F rectify)
{
AddRadialPtoP_F64 addDistortion = new AddRadialPtoP_F64();
addDistortion.set(param.fx, param.fy, param.skew, param.cx, param.cy, param.radial);
DenseMatrix64F rectifyInv = new DenseMatrix64F(3,3);
CommonOps.invert(rectify,rectifyInv);
PointTransformHomography_F64 removeRect = new PointTransformHomography_F64(rectifyInv);
if( param.flipY) {
PointTransform_F64 flip = new FlipVertical_F64(param.height);
return new SequencePointTransform_F64(flip,removeRect,addDistortion,flip);
} else {
return new SequencePointTransform_F64(removeRect,addDistortion);
}
}
示例10: rectifyImage
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Creates an {@link ImageDistort} for rectifying an image given its rectification matrix.
* Lens distortion is assumed to have been previously removed.
*
* @param rectify Transform for rectifying the image.
* @param imageType Type of single band image the transform is to be applied to.
* @return ImageDistort for rectifying the image.
*/
public static <T extends ImageSingleBand> ImageDistort<T>
rectifyImage( DenseMatrix64F rectify , Class<T> imageType)
{
InterpolatePixel<T> interp = FactoryInterpolation.bilinearPixel(imageType);
DenseMatrix64F rectifyInv = new DenseMatrix64F(3,3);
CommonOps.invert(rectify,rectifyInv);
PointTransformHomography_F32 rectifyTran = new PointTransformHomography_F32(rectifyInv);
// don't bother caching the results since it is likely to only be applied once and is cheap to compute
ImageDistort<T> ret = FactoryDistort.distort(interp, null, imageType);
ret.setModel(new PointToPixelTransform_F32(rectifyTran));
return ret;
}
示例11: process
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Computes the homography based on a line and point on the plane
* @param line Line on the plane
* @param point Point on the plane
*/
public void process(PairLineNorm line, AssociatedPair point) {
// t0 = (F*x) cross l'
GeometryMath_F64.mult(F,point.p1,Fx);
GeometryMath_F64.cross(Fx,line.getL2(),t0);
// t1 = x' cross ((f*x) cross l')
GeometryMath_F64.cross(point.p2, t0, t1);
// t0 = x' cross e'
GeometryMath_F64.cross(point.p2,e2,t0);
double top = GeometryMath_F64.dot(t0,t1);
double bottom = t0.normSq()*(line.l1.x*point.p1.x + line.l1.y*point.p1.y + line.l1.z);
// e' * l^T
GeometryMath_F64.outerProd(e2, line.l1, el);
// cross(l')*F
GeometryMath_F64.multCrossA(line.l2, F, lf);
CommonOps.add(lf,top/bottom,el,H);
// pick a good scale and sign for H
adjust.adjust(H, point);
}
示例12: encode
import org.ejml.ops.CommonOps; //导入依赖的package包/类
@Override
public void encode(Se3_F64 input, double[] output) {
// force the "rotation matrix" to be an exact rotation matrix
// otherwise Rodrigues will have issues with the noise
if( !svd.decompose(input.getR()) )
throw new RuntimeException("SVD failed");
DenseMatrix64F U = svd.getU(null,false);
DenseMatrix64F V = svd.getV(null,false);
CommonOps.multTransB(U, V, R);
// extract Rodrigues coordinates
RotationMatrixGenerator.matrixToRodrigues(R,rotation);
output[0] = rotation.unitAxisRotation.x*rotation.theta;
output[1] = rotation.unitAxisRotation.y*rotation.theta;
output[2] = rotation.unitAxisRotation.z*rotation.theta;
Vector3D_F64 T = input.getT();
output[3] = T.x;
output[4] = T.y;
output[5] = T.z;
}
示例13: solveConstraintMatrix
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Apply additional constraints to reduce the number of possible solutions
*
* x(k) = x_{ij} = bi*bj = x0(k) + a1*V0(k) + a2*V1(k) + a3*V2(k)
*
* constraint:
* x_{ii}*x_{jk} = x_{ik}*x_{ji}
*
*/
protected DenseMatrix64F solveConstraintMatrix() {
int rowAA = 0;
for( int i = 0; i < numControl; i++ ) {
for( int j = i+1; j < numControl; j++ ) {
for( int k = j; k < numControl; k++ , rowAA++ ) {
// x_{ii}*x_{jk} = x_{ik}*x_{ji}
extractXaXb(getIndex(i, i), getIndex(j, k), XiiXjk);
extractXaXb(getIndex(i, k), getIndex(j, i), XikXji);
for( int l = 1; l <= AA.numCols; l++ ) {
AA.set(rowAA,l-1,XikXji[l]-XiiXjk[l]);
}
yy.set(rowAA,XiiXjk[0]-XikXji[0]);
}
}
}
// AA.print();
CommonOps.solve(AA, yy, xx);
return xx;
}
示例14: createCameraMatrix
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Create a 3x4 camera matrix. For calibrated camera P = [R|T]. For uncalibrated camera it is P = K*[R|T].
*
* @param R Rotation matrix. 3x3
* @param T Translation vector.
* @param K Optional camera calibration matrix 3x3.
* @param ret Storage for camera calibration matrix. If null a new instance will be created.
* @return Camera calibration matrix.
*/
public static DenseMatrix64F createCameraMatrix( DenseMatrix64F R , Vector3D_F64 T , DenseMatrix64F K ,
DenseMatrix64F ret ) {
if( ret == null )
ret = new DenseMatrix64F(3,4);
CommonOps.insert(R,ret,0,0);
ret.data[3] = T.x;
ret.data[7] = T.y;
ret.data[11] = T.z;
if( K == null )
return ret;
DenseMatrix64F temp = new DenseMatrix64F(3,4);
CommonOps.mult(K,ret,temp);
ret.set(temp);
return ret;
}
示例15: decompose
import org.ejml.ops.CommonOps; //导入依赖的package包/类
/**
* Compute the decomposition given the SVD of E=U*S*V<sup>T</sup>.
*
* @param U Orthogonal matrix from SVD.
* @param S Diagonal matrix containing singular values from SVD.
* @param V Orthogonal matrix from SVD.
*/
public void decompose( DenseMatrix64F U , DenseMatrix64F S , DenseMatrix64F V ) {
// this ensures the resulting rotation matrix will have a determinant of +1 and thus be a real rotation matrix
if( CommonOps.det(U) < 0 ) {
CommonOps.scale(-1,U);
CommonOps.scale(-1,S);
}
if( CommonOps.det(V) < 0 ) {
CommonOps.scale(-1,V);
CommonOps.scale(-1,S);
}
// for possible solutions due to ambiguity in the sign of T and rotation
extractTransform(U, V, S, solutions.get(0), true, true);
extractTransform(U, V, S, solutions.get(1), true, false);
extractTransform(U, V, S, solutions.get(2) , false,false);
extractTransform(U, V, S, solutions.get(3), false, true);
}