本文整理汇总了Java中mikera.matrixx.AMatrix.columnCount方法的典型用法代码示例。如果您正苦于以下问题:Java AMatrix.columnCount方法的具体用法?Java AMatrix.columnCount怎么用?Java AMatrix.columnCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mikera.matrixx.AMatrix
的用法示例。
在下文中一共展示了AMatrix.columnCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decompose
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
/**
* <p>
* To decompose the matrix 'A' it must have full rank. 'A' is a 'm' by 'n' matrix.
* It requires about 2n*m<sup>2</sup>-2m<sup>2</sup>/3 flops.
* </p>
*
* <p>
* The matrix provided here can be of different
* dimension than the one specified in the constructor. It just has to be smaller than or equal
* to it.
* </p>
*/
@Override
public QRResult decompose( AMatrix A ) {
this.numCols = A.columnCount();
this.numRows = A.rowCount();
minLength = Math.min(numCols,numRows);
int maxLength = Math.max(numCols,numRows);
dataQR = new double[ numCols ][ numRows ];
v = new double[ maxLength ];
gammas = new double[ minLength ];
convertToColumnMajor(A);
error = false;
for( int j = 0; j < minLength; j++ ) {
householder(j);
updateA(j);
}
// if (error)
// return null;
// else
return new QRResult(getQ(), getR());
}
示例2: _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();
}
示例3: setA
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
/**
* Performs QR decomposition on A
*
* @param A not modified.
*/
public boolean setA(AMatrix A) {
if( A.rowCount() > maxRows || A.columnCount() > maxCols )
setMaxSize(A.rowCount(),A.columnCount());
a = Matrix.create(A.rowCount(),1);
temp = Matrix.create(A.rowCount(),1);
_setA(A);
result = decomposer.decompose(A);
if( result == null )
return false;
gammas = decomposer.getGammas();
QR = decomposer.getQR();
R = result.getR().toMatrix();
return true;
}
示例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 writen 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];
solveInternal();
for( int i = 0; i < n; i++ ) dataX[i*numCols+j] = vv[i];
}
return X;
}
示例5: wrapOrCreate
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
/**
* Wraps data wrom source matrix in a BlasMatrix if possible, otherwise creates a nwew BlasMatrix
* @param m
* @return
*/
public static BlasMatrix wrapOrCreate(AMatrix m) {
if (m instanceof AStridedMatrix) {
AStridedMatrix sm=(AStridedMatrix)m;
if (sm.getArrayOffset()==0) {
if (sm.columnStride()==1) {
return new BlasMatrix(sm.getArray(),m.rowCount(),m.columnCount(),0,sm.rowStride(),1);
}
if (sm.rowStride()==1) {
return new BlasMatrix(sm.getArray(),m.rowCount(),m.columnCount(),0,1,sm.columnStride());
}
}
}
return create(m);
}
示例6: create
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public static SparseColumnMatrix create(AMatrix source) {
if (source instanceof SparseRowMatrix) return ((SparseRowMatrix)source).toSparseColumnMatrix();
int cc=source.columnCount();
int rc=source.rowCount();
AVector[] data = new AVector[cc];
for (int i=0; i<cc; i++) {
AVector col = source.getColumn(i);
if (!col.isZero())
data[i] = Vectorz.createSparse(col);
}
return new SparseColumnMatrix(data,rc,cc);
}
示例7: createFrom
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public static LowerTriangularMatrix createFrom(AMatrix m) {
int rc=m.rowCount();
int cc=m.columnCount();
LowerTriangularMatrix r = new LowerTriangularMatrix(rc,cc);
for (int j=0; j<cc; j++) {
for (int i=j; i<rc; i++) {
r.unsafeSet(i, j, m.unsafeGet(i, j));
}
}
return r;
}
示例8: innerProduct
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
@Override
public AVector innerProduct(AMatrix m) {
int rc=m.rowCount();
int cc=m.columnCount();
this.checkLength(rc);
AVector r=Vector.createLength(cc);
List<AVector> cols=m.getColumns();
for (int i=0; i<cc; i++) {
AVector col=cols.get(i);
r.unsafeSet(i, value*col.elementSum());
}
return r;
}
示例9: Affine23
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public Affine23(AMatrix m, AVector v) {
if ((v.length()!=2)||(m.columnCount()!=2)||(m.rowCount()!=2)) {
throw new IllegalArgumentException("Wrong source sizes for Affine23");
}
m00=m.unsafeGet(0,0);
m01=m.unsafeGet(0,1);
m10=m.unsafeGet(1,0);
m11=m.unsafeGet(1,1);
tr0=v.unsafeGet(0);
tr1=v.unsafeGet(1);
}
示例10: AffineMN
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public AffineMN(AMatrix matrix, ATranslation translation) {
this.matrix=matrix;
this.translation=translation;
inputDimensions=matrix.columnCount();
outputDimensions=matrix.rowCount();
if (outputDimensions!=translation.inputDimensions()) {
throw new IllegalArgumentException("matrix and translation have incompatible dimensionality");
}
}
示例11: create
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public static VectorMatrixMN create(AMatrix source) {
int rc=source.rowCount();
VectorMatrixMN m=new VectorMatrixMN(source.rowCount(),source.columnCount());
for (int i=0; i<rc; i++) {
m.rowData[i].set(source.getRow(i));
}
return m;
}
示例12: innerProduct
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
@Override
public AVector innerProduct(AMatrix m) {
if (m instanceof SparseRowMatrix) {
return this.innerProduct((SparseRowMatrix) m);
}
if (m instanceof SparseColumnMatrix) {
return this.innerProduct((SparseColumnMatrix) m);
}
int cc = m.columnCount();
int rc = m.rowCount();
checkLength(rc);
AVector result = SparseIndexedVector.createLength(cc);
int nzc = 0;
for (int i = 0; i < cc; i++) {
double v=this.dotProduct(m.getColumn(i));
if (v==0.0) continue;
nzc++;
if ((i>20)&&(nzc>(i/4))) {
// switch to dense vector
result=result.toVector();
}
result.unsafeSet(i, v);
}
return result;
}
示例13: improveSol
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
/**
* This attempts to improve upon the solution generated by account
* for numerical imprecisions. See numerical recipes for more information. It
* is assumed that solve has already been run on 'b' and 'x' at least once.
*
* @param b A matrix. Not modified.
* @param x A matrix. Modified.
*/
public void improveSol( AMatrix b , AMatrix x )
{
if( b.columnCount() != x.columnCount() ) {
throw new IllegalArgumentException("bad shapes");
}
double dataA[] = A.asDoubleArray();
double dataB[] = b.asDoubleArray();
double dataX[] = x.asDoubleArray();
final int nc = b.columnCount();
final int n = b.columnCount();
double []vv = decomp._getVV();
// AMatrix LU = decomp.getLU();
// BigDecimal sdp = new BigDecimal(0);
for( int k = 0; k < nc; k++ ) {
for( int i = 0; i < n; i++ ) {
// *NOTE* in the book this is a long double. extra precision might be required
double sdp = -dataB[ i * nc + k];
// BigDecimal sdp = new BigDecimal(-dataB[ i * nc + k]);
for( int j = 0; j < n; j++ ) {
sdp += dataA[i* n +j] * dataX[ j * nc + k];
// sdp = sdp.add( BigDecimal.valueOf(dataA[i* n +j] * dataX[ j * nc + k]));
}
vv[i] = sdp;
// vv[i] = sdp.doubleValue();
}
decomp._solveVectorInternal(vv);
for( int i = 0; i < n; i++ ) {
dataX[i*nc + k] -= vv[i];
}
}
}
示例14: broadcastLike
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
@Override
public AStridedMatrix broadcastLike(AMatrix target) {
if (length()==target.columnCount()) {
return StridedMatrix.wrap(getArray(), target.rowCount(), length(), getArrayOffset(), 0, getStride());
} else {
throw new IllegalArgumentException(ErrorMessages.incompatibleBroadcast(this, target));
}
}
示例15: create
import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public static DenseColumnMatrix create(AMatrix m) {
DenseColumnMatrix dm= new DenseColumnMatrix(m.rowCount(), m.columnCount());
dm.set(m);
return dm;
}