本文整理汇总了Java中org.apache.mahout.math.Matrix.get方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.get方法的具体用法?Java Matrix.get怎么用?Java Matrix.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Matrix
的用法示例。
在下文中一共展示了Matrix.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCovarianceMatrix
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/**
* Computes the inverse covariance from the input covariance matrix given in input.
*
* @param m A covariance matrix.
* @throws IllegalArgumentException if <tt>eigen values equal to 0 found</tt>.
*/
public void setCovarianceMatrix(Matrix m) {
if (m.numRows() != m.numCols()) {
throw new CardinalityException(m.numRows(), m.numCols());
}
// See http://www.mlahanas.de/Math/svd.htm for details,
// which specifically details the case of covariance matrix inversion
// Complexity: O(min(nm2,mn2))
SingularValueDecomposition svd = new SingularValueDecomposition(m);
Matrix sInv = svd.getS();
// Inverse Diagonal Elems
for (int i = 0; i < sInv.numRows(); i++) {
double diagElem = sInv.get(i, i);
if (diagElem > 0.0) {
sInv.set(i, i, 1 / diagElem);
} else {
throw new IllegalStateException("Eigen Value equals to 0 found.");
}
}
inverseCovarianceMatrix = svd.getU().times(sInv.times(svd.getU().transpose()));
Preconditions.checkArgument(inverseCovarianceMatrix != null, "inverseCovarianceMatrix not initialized");
}
示例2: convertMahoutToSparkMatrix
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/**
* Convert org.apache.mahout.math.Matrix object to org.apache.spark.mllib.linalg.Matrix object to be used in Spark Programs
*/
public static org.apache.spark.mllib.linalg.Matrix convertMahoutToSparkMatrix(Matrix mahoutMatrix)
{
int rows=mahoutMatrix.numRows();
int cols=mahoutMatrix.numCols();
int arraySize= rows*cols;
int arrayIndex=0;
double[] colMajorArray= new double[arraySize];
for(int i=0;i<cols; i++)
{
for(int j=0; j< rows; j++)
{
colMajorArray[arrayIndex] = mahoutMatrix.get(j, i);
arrayIndex++;
}
}
org.apache.spark.mllib.linalg.Matrix sparkMatrix = Matrices.dense(rows, cols, colMajorArray);
return sparkMatrix;
}