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


Java Matrix.transpose方法代码示例

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


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

示例1: calculateStdErrorOfCoef

import weka.core.matrix.Matrix; //导入方法依赖的package包/类
/**
 * Returns the standard errors of slope and intercept for a simple linear
 * regression model: y = a + bx. The first element is the standard error of
 * slope, the second element is standard error of intercept.
 * 
 * @param data (the data set)
 * @param chosen (chosen x-attribute)
 * @param slope (slope determined by simple linear regression model)
 * @param intercept (intercept determined by simple linear regression model)
 * @param df (number of instances - 2)
 * 
 * @return array of standard errors of slope and intercept
 * @throws Exception if there is a missing class value in data
 */
public static double[] calculateStdErrorOfCoef(Instances data,
  Attribute chosen, double slope, double intercept, int df) throws Exception {
  // calculate sum of squared residuals, mean squared error
  double ssr = calculateSSR(data, chosen, slope, intercept);
  double mse = ssr / df;

  /*
   * put data into 2-D array with 2 columns first column is value of chosen
   * attribute second column is constant (1's)
   */
  double[][] array = new double[data.numInstances()][2];
  for (int i = 0; i < data.numInstances(); i++) {
    array[i][0] = data.instance(i).value(chosen);
    array[i][1] = 1.0;
  }

  /*
   * linear algebra calculation: covariance matrix = mse * (XtX)^-1 diagonal
   * of covariance matrix is square of standard error of coefficients
   */
  Matrix X = new Matrix(array);
  Matrix Xt = X.transpose();
  Matrix XtX = Xt.times(X);
  Matrix inverse = XtX.inverse();
  Matrix cov = inverse.times(mse);

  double[] result = new double[2];
  for (int i = 0; i < 2; i++) {
    result[i] = Math.sqrt(cov.get(i, i));
  }

  return result;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:48,代码来源:RegressionAnalysis.java


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