当前位置: 首页>>代码示例>>Java>>正文


Java AMatrix.toMatrix方法代码示例

本文整理汇总了Java中mikera.matrixx.AMatrix.toMatrix方法的典型用法代码示例。如果您正苦于以下问题:Java AMatrix.toMatrix方法的具体用法?Java AMatrix.toMatrix怎么用?Java AMatrix.toMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mikera.matrixx.AMatrix的用法示例。


在下文中一共展示了AMatrix.toMatrix方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:34,代码来源:CholeskySolver.java

示例2: 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;
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:34,代码来源:CholeskyLDUSolver.java

示例3: decompose

import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
/**
     * Decomposes a submatrix.  The results are written to the submatrix
     * and to its internal matrix L.
     *
     * @param mat A matrix which has a submatrix that needs to be inverted
     * @param indexStart the first index of the submatrix
     * @param n The width of the submatrix that is to be inverted.
     * @return True if it was able to finish the decomposition.
     */
    public boolean decompose( AMatrix mat , int indexStart , int n ) {
        double m[] = mat.toMatrix().data;

        double el_ii;
        double div_el_ii=0;

        for( int i = 0; i < n; i++ ) {
            for( int j = i; j < n; j++ ) {
                double sum = m[indexStart+i*mat.rowCount()+j];

                int iEl = i*n;
                int jEl = j*n;
                int end = iEl+i;
                // k = 0:i-1
                for( ; iEl<end; iEl++,jEl++ ) {
//                    sum -= el[i*n+k]*el[j*n+k];
                    sum -= el[iEl]*el[jEl];
                }

                if( i == j ) {
                    // is it positive-definate?
                    if( sum <= 0.0 )
                        return false;

                    el_ii = Math.sqrt(sum);
                    el[i*n+i] = el_ii;
                    m[indexStart+i*mat.columnCount()+i] = el_ii;
                    div_el_ii = 1.0/el_ii;
                } else {
                    double v = sum*div_el_ii;
                    el[j*n+i] = v;
                    m[indexStart+j*mat.columnCount()+i] = v;
                }
            }
        }

        return true;
    }
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:48,代码来源:CholeskyHelper.java

示例4: setUt

import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public void setUt(AMatrix ut) {
	if (ut == null) {
		Ut = null;
	}
	else {
		Ut = ut.toMatrix();
	}
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:9,代码来源:SvdImplicitQrAlgorithm.java

示例5: setVt

import mikera.matrixx.AMatrix; //导入方法依赖的package包/类
public void setVt(AMatrix vt) {
	if (vt == null) {
		Vt = null;
	}
	else {
		Vt = vt.toMatrix();
	}
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:9,代码来源:SvdImplicitQrAlgorithm.java

示例6: _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.
 * </p>
 * @param mat A symmetric n by n positive definite matrix.
 * @return ICholeskyLDUResult if decomposition is successful, null otherwise.
 */
private ICholeskyLDUResult _decompose( AMatrix mat ) {
    if( mat.rowCount() != mat.columnCount() ) {
        throw new RuntimeException("Can only decompose square matrices");
    }
    n = mat.rowCount();
    this.vv = new double[n];
    this.d = new double[n];
    L = mat.toMatrix();
    this.el = L.data;

    double d_inv=0;
    for( int i = 0; i < n; i++ ) {
        for( int j = i; j < n; j++ ) {
            double sum = el[i*n+j];

            for( int k = 0; k < i; k++ ) {
                sum -= el[i*n+k]*el[j*n+k]*d[k];
            }

            if( i == j ) {
                // is it positive-definate?
                if( sum <= 0.0 )
                    return null;

                d[i] = sum;
                d_inv = 1.0/sum;
                el[i*n+i] = 1;
            } else {
                el[j*n+i] = sum*d_inv;
            }
        }
    }
    // zero the top right corner.
    for( int i = 0; i < n; i++ ) {
        for( int j = i+1; j < n; j++ ) {
            el[i*n+j] = 0.0;
        }
    }

    return new CholeskyResult(L, DiagonalMatrix.create(d), L.getTranspose());
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:55,代码来源:CholeskyLDU.java

示例7: _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 ICholeskyResult if decomposition is successful, null otherwise.
 */
protected ICholeskyResult _decompose( AMatrix mat ) {
    if( mat.rowCount() != mat.columnCount() ) {
        throw new IllegalArgumentException("Must be a square matrix.");
    }

    n = mat.rowCount();
    this.vv = new double[n];
    T = mat.toMatrix();
    t = T.data;

    return decomposeLower();
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:26,代码来源:CholeskyCommon.java


注:本文中的mikera.matrixx.AMatrix.toMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。