本文整理汇总了Java中mikera.matrixx.AMatrix类的典型用法代码示例。如果您正苦于以下问题:Java AMatrix类的具体用法?Java AMatrix怎么用?Java AMatrix使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AMatrix类属于mikera.matrixx包,在下文中一共展示了AMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _decompose
import mikera.matrixx.AMatrix; //导入依赖的package包/类
public SVDResult _decompose(AMatrix _orig) {
// Creating a copy so that original matrix is not modified
Matrix orig = _orig.copy().toMatrix();
setup(orig);
performBidiagonalisation(orig);
computeUSV();
// make sure all the singular values are positive
makeSingularPositive();
// if transposed undo the transposition
undoTranspose();
AVector svs=getSingularValues();
return new SVDResult(getU(), getS(), getV(), svs);
}
示例2: equals
import mikera.matrixx.AMatrix; //导入依赖的package包/类
@Override
public boolean equals(AMatrix m) {
if (m==this) return true;
if (m instanceof IFastRows) return equals((IFastRows)m);
if (!isSameShape(m)) return false;
List<AVector> mrows=m.getRows();
for (int i=0; i<rows; i++) {
AVector v=unsafeGetVector(i);
AVector ov = mrows.get(i);
if (v==null) {
if (!ov.isZero()) return false;
} else {
if (!v.equals(ov)) return false;
}
}
return true;
}
示例3: qualityTriangular
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* Computes the quality of a triangular matrix. In
* this situation the quality is the absolute value of the product of
* each diagonal element divided by the magnitude of the largest diagonal element.
* If all diagonal elements are zero then zero is returned.
*
* @param upper if it is upper triangular or not.
* @param T A matrix. @return product of the diagonal elements.
* @return the quality of the system.
*/
public static double qualityTriangular(boolean upper, AMatrix T)
{
int N = Math.min(T.rowCount(),T.columnCount());
// TODO make faster by just checking the upper triangular portion
double max = T.absCopy().elementMax();
if( max == 0.0d )
return 0.0d;
double quality = 1.0;
for( int i = 0; i < N; i++ ) {
quality *= T.unsafeGet(i,i)/max;
}
return Math.abs(quality);
}
示例4: solve
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* <p>
* Using the decomposition, finds the value of 'X' in the linear equation below:<br>
*
* A*x = b<br>
*
* where A has dimension of n by n, x and b are n by m dimension.
* </p>
* <p>
* *Note* that 'b' and 'x' can be the same matrix instance.
* </p>
*
* @param B A matrix that is n by m. Not modified.
* @param X An n by m matrix where the solution is written to. Modified.
*/
public AMatrix solve(AMatrix B) {
Matrix X = Matrix.create(B.rowCount(), B.columnCount());
if( B.columnCount() != X.columnCount() && B.rowCount() != n && X.rowCount() != n) {
throw new IllegalArgumentException("Unexpected matrix size");
}
int numCols = B.columnCount();
double dataB[] = B.toMatrix().data;
double dataX[] = X.data;
for( int j = 0; j < numCols; j++ ) {
for( int i = 0; i < n; i++ ) vv[i] = dataB[i*numCols+j];
solveInternalL();
for( int i = 0; i < n; i++ ) dataX[i*numCols+j] = vv[i];
}
return X;
}
示例5: Affine34
import mikera.matrixx.AMatrix; //导入依赖的package包/类
public Affine34(AMatrix m, AVector v) {
if ((v.length()!=3)||(m.columnCount()!=3)||(m.rowCount()!=3)) {
throw new IllegalArgumentException("Wrong source sizes for Affine34");
}
m00=m.unsafeGet(0,0);
m01=m.unsafeGet(0,1);
m02=m.unsafeGet(0,2);
m10=m.unsafeGet(1,0);
m11=m.unsafeGet(1,1);
m12=m.unsafeGet(1,2);
m20=m.unsafeGet(2,0);
m21=m.unsafeGet(2,1);
m22=m.unsafeGet(2,2);
tr0=v.unsafeGet(0);
tr1=v.unsafeGet(1);
tr2=v.unsafeGet(2);
}
示例6: equals
import mikera.matrixx.AMatrix; //导入依赖的package包/类
@Override
public boolean equals(AMatrix a) {
if (a==this) return true;
if (!isSameShape(a)) return false;
if (a instanceof ADenseArrayMatrix) {
ADenseArrayMatrix da=(ADenseArrayMatrix)a;
return equalsArray(da.getArray(),da.getArrayOffset());
}
for (int j = 0; j < cols; j++) {
int end=Math.min(j,rows-1);
for (int i = 0; i <= end; i++) {
if (data[internalIndex(i, j)] != a.unsafeGet(i, j)) return false;
}
// TODO: factor out using isRangeZero on rows / cols of a?
for (int i = j+1; i < rows; i++) {
if (a.unsafeGet(i, j)!=0.0) return false;
}
}
return true;
}
示例7: getV
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* Returns the orthogonal V matrix.
*
* @return The extracted Q matrix.
*/
private AMatrix getV() {
Matrix V = handleV(m,n,min);
// UBV.print();
// todo the very first multiplication can be avoided by setting to the rank1update output
for( int j = min-1; j >= 0; j-- ) {
u[j+1] = 1;
for( int i = j+2; i < n; i++ ) {
u[i] = UBV.get(j,i);
}
QRHelperFunctions.rank1UpdateMultR(V,u,gammasV[j],j+1,j+1,n,this.b);
}
return V;
}
示例8: _decompose
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* <p>
* Performs Choleksy decomposition on the provided matrix.
* </p>
*
* <p>
* If the matrix is not positive definite then this function will return
* null since it can't complete its computations. Not all errors will be
* found. This is an efficient way to check for positive definiteness.
* </p>
* @param mat A symmetric positive definite matrix
* @return CholeskyResult if decomposition is successful, null otherwise
*/
@Override
protected ICholeskyResult _decompose( AMatrix mat ) {
int rc=mat.rowCount();
int cc=mat.columnCount();
if( rc != cc ) {
throw new IllegalArgumentException("Must be a square matrix.");
}
n = mat.rowCount();
this.vv = new double[n];
t=mat.toDoubleArray();
T = Matrix.wrap(rc, cc, t);
if(mat.rowCount() < blockWidth) {
B = Matrix.create(0,0);
}
else {
B = Matrix.create(blockWidth,n);
}
chol = new CholeskyHelper(blockWidth);
return decomposeLower();
}
示例9: computeL
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* Returns the lower triangular matrix.
*/
private AMatrix computeL()
{
int numRows = LU.rowCount();
int numCols = Math.min(LU.rowCount(), LU.columnCount());
Matrix lower = Matrix.create(numRows,numCols);
for( int i = 0; i < numCols; i++ ) {
lower.set(i,i,1.0);
for( int j = 0; j < i; j++ ) {
lower.set(i,j, LU.get(i,j));
}
}
if( numRows > numCols ) {
for( int i = numCols; i < numRows; i++ ) {
for( int j = 0; j < numCols; j++ ) {
lower.set(i,j, LU.get(i,j));
}
}
}
return lower;
}
示例10: computeU
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* Returns the upper triangular matrix.
*/
private AMatrix computeU()
{
int numRows = Math.min(LU.rowCount(), LU.columnCount());
int numCols = LU.columnCount();
Matrix upper = Matrix.create(numRows, numCols);
for( int i = 0; i < numRows; i++ ) {
for( int j = i; j < numCols; j++ ) {
upper.set(i,j, LU.get(i,j));
}
}
return upper;
}
示例11: innerProduct
import mikera.matrixx.AMatrix; //导入依赖的package包/类
@Override
public INDArray innerProduct(INDArray a) {
if (a instanceof AVector) {
return innerProduct((AVector)a);
} else if (a instanceof AScalar) {
return innerProduct((AScalar)a);
} else if (a instanceof AMatrix) {
return innerProduct((AMatrix)a);
} else if (a.dimensionality()<=2) {
return innerProduct(Arrayz.create(a));
}
int len=checkLength(a.sliceCount());
List<INDArray> al=a.getSliceViews();
INDArray result=Arrayz.newArray(al.get(0).getShape());
for (int i=0; i<len; i++) {
double v=unsafeGet(i);
if (v!=0.0) result.addMultiple(al.get(i),v);
}
return result;
}
示例12: getT
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* Extracts the tridiagonal matrix found in the decomposition.
*
* @return The extracted T matrix.
*/
public AMatrix getT() {
Matrix T = Matrix.create(N,N);
T.data[0] = QT.data[0];
for( int i = 1; i < N; i++ ) {
T.set(i,i, QT.get(i,i));
double a = QT.get(i-1,i);
T.set(i-1,i,a);
T.set(i,i-1,a);
}
if( N > 1 ) {
T.data[(N-1)*N+N-1] = QT.data[(N-1)*N+N-1];
T.data[(N-1)*N+N-2] = QT.data[(N-2)*N+N-1];
}
return T;
}
示例13: set
import mikera.matrixx.AMatrix; //导入依赖的package包/类
@Override
public void set(AMatrix m) {
checkSameShape(m);
for (int i=0; i<cols; i++) {
m.copyColumnTo(i, data, index(0,i));
}
}
示例14: testInnerProductMM
import mikera.matrixx.AMatrix; //导入依赖的package包/类
@Test public void testInnerProductMM() {
BlasMatrix m1=BlasMatrix.create(Matrix.create(new double[][] {{1,2,3},{4,5,6}}));
BlasMatrix m2=BlasMatrix.create(Matrix.create(new double[][] {{0,1,2,3},{1,2,3,4},{2,3,4,5}}));
AMatrix result=m1.innerProduct(m2);
assertEquals(Matrix.create(new double[][] {{8,14,20,26},{17,32,47,62}}),result);
// test that transposed versions work correctly
// using identity A.B = (B^t.A^t)^t
assertEquals(result,m2.getTranspose().innerProduct(m1.getTranspose()).getTranspose());
}
示例15: addInnerProduct
import mikera.matrixx.AMatrix; //导入依赖的package包/类
/**
* Adds the inner product of the arguments (matrix a and vector b) to this vector.
*
* @param a A matrix with the same number or rows as this vector
* @param b A vector with the same lengths as the number of columns in the parameter a
*/
public void addInnerProduct(AMatrix a, AVector b) {
int length=this.length();
if (length!=a.rowCount()) throw new IllegalArgumentException(ErrorMessages.incompatibleShapes(this, a));
if (b.length()!=a.columnCount()) throw new IllegalArgumentException(ErrorMessages.incompatibleShapes(a, b));
for (int i=0; i<length; i++) {
double v=a.rowDotProduct(i,b);
addAt(i,v);
}
}