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


Java RealMatrix.scalarMultiply方法代码示例

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


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

示例1: main

import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
public static void main(String[] args) {
  // test wishart
  double[][] s = {{2.0,1.0,0.0},{1.0,2.0,1.0},{0.0,1.0,2.0}};
  RealMatrix S = new Array2DRowRealMatrix(s);
  Cholesky C = new Cholesky(S);
  double df = 2.4;
  RealMatrix sum = new Array2DRowRealMatrix(3,3);
  for (int i=0; i<100000; i++) {
    RealMatrix sample = generator.nextWishart(df, C);
    sum = sum.add(sample);
  }
  sum = sum.scalarMultiply(1.0/100000.0);
  System.out.println(sum.getRowVector(0));
  System.out.println(sum.getRowVector(1));
  System.out.println(sum.getRowVector(2));
}
 
开发者ID:BigBayes,项目名称:BNPMix.java,代码行数:17,代码来源:Generator.java

示例2: computeBeta

import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
/**
 *
 * @param y     the response vector
 * @param x     the design matrix
 */
private RealMatrix computeBeta(RealVector y, RealMatrix x) {
    if (solver == Solver.QR) {
        return computeBetaQR(y, x);
    } else {
        final int n = x.getRowDimension();
        final int p = x.getColumnDimension();
        final int offset = hasIntercept() ? 1 : 0;
        final RealMatrix xT = x.transpose();
        final RealMatrix xTxInv = new LUDecomposition(xT.multiply(x)).getSolver().getInverse();
        final RealVector betaVector = xTxInv.multiply(xT).operate(y);
        final RealVector residuals = y.subtract(x.operate(betaVector));
        this.rss = residuals.dotProduct(residuals);
        this.errorVariance = rss / (n - p);
        this.stdError = Math.sqrt(errorVariance);
        this.residuals = createResidualsFrame(residuals);
        final RealMatrix covMatrix = xTxInv.scalarMultiply(errorVariance);
        final RealMatrix result = new Array2DRowRealMatrix(p, 2);
        if (hasIntercept()) {
            result.setEntry(0, 0, betaVector.getEntry(0));      //Intercept coefficient
            result.setEntry(0, 1, covMatrix.getEntry(0, 0));    //Intercept variance
        }
        for (int i = 0; i < getRegressors().size(); i++) {
            final int index = i + offset;
            final double variance = covMatrix.getEntry(index, index);
            result.setEntry(index, 1, variance);
            result.setEntry(index, 0, betaVector.getEntry(index));
        }
        return result;
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:36,代码来源:XDataFrameLeastSquares.java


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