本文整理汇总了Java中org.apache.mahout.math.Matrix.set方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.set方法的具体用法?Java Matrix.set怎么用?Java Matrix.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Matrix
的用法示例。
在下文中一共展示了Matrix.set方法的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: getMatrix
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
public Matrix getMatrix() {
int length = confusionMatrix.length;
Matrix m = new DenseMatrix(length, length);
for (int r = 0; r < length; r++) {
for (int c = 0; c < length; c++) {
m.set(r, c, confusionMatrix[r][c]);
}
}
Map<String,Integer> labels = Maps.newHashMap();
for (Map.Entry<String, Integer> entry : labelMap.entrySet()) {
labels.put(entry.getKey(), entry.getValue());
}
m.setRowLabelBindings(labels);
m.setColumnLabelBindings(labels);
return m;
}