本文整理汇总了Java中org.apache.mahout.math.Matrix.assignRow方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.assignRow方法的具体用法?Java Matrix.assignRow怎么用?Java Matrix.assignRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Matrix
的用法示例。
在下文中一共展示了Matrix.assignRow方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runSequential
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/***
* PPCA: sequential PPCA based on the paper from Tipping and Bishop
*
* @param conf
* the configuration
* @param input
* the path to the input matrix Y
* @param output
* the output path (not used currently)
* @param nRows
* number or rows in Y
* @param nCols
* number of columns in Y
* @param nPCs
* number of desired principal components
* @return the error
* @throws Exception
*/
double runSequential(Configuration conf, Path input, Path output,
final int nRows, final int nCols, final int nPCs) throws Exception {
Matrix centralY = new DenseMatrix(nRows, nCols);
FileSystem fs = FileSystem.get(input.toUri(), conf);
if (fs.listStatus(input).length == 0) {
System.err.println("No file under " + input);
return 0;
}
int row = 0;
for (VectorWritable vw : new SequenceFileDirValueIterable<VectorWritable>(
input, PathType.LIST, null, conf)) {
centralY.assignRow(row, vw.get());
row++;
}
Matrix centralC = PCACommon.randomMatrix(nCols, nPCs);
double ss = PCACommon.randSS();
InitialValues initVal = new InitialValues(centralC, ss);
// Matrix sampledYe = sample(centralY);
// runSequential(conf, sampledYe, initVal, 100);
double error = runSequential(conf, centralY, initVal, 100);
return error;
}
示例2: runSequential_JacobVersion
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/**
* PPCA: sequential PPCA based on the matlab implementation of Jacob Verbeek
*
* @param conf
* the configuration
* @param input
* the path to the input matrix Y
* @param output
* the output path (not used currently)
* @param nRows
* number or rows in Y
* @param nCols
* number of columns in Y
* @param nPCs
* number of desired principal components
* @return the error
* @throws Exception
*/
double runSequential_JacobVersion(Configuration conf, Path input,
Path output, final int nRows, final int nCols, final int nPCs) throws Exception {
Matrix centralY = new DenseMatrix(nRows, nCols);
FileSystem fs = FileSystem.get(input.toUri(), conf);
if (fs.listStatus(input).length == 0) {
System.err.println("No file under " + input);
return 0;
}
int row = 0;
for (VectorWritable vw : new SequenceFileDirValueIterable<VectorWritable>(
input, PathType.LIST, null, conf)) {
centralY.assignRow(row, vw.get());
row++;
}
Matrix C = PCACommon.randomMatrix(nCols, nPCs);
double ss = PCACommon.randSS();
InitialValues initVal = new InitialValues(C, ss);
double error = runSequential_JacobVersion(conf, centralY, initVal, 100);
return error;
}
示例3: crossTestIterationOfMapReducePPCASequentialPPCA
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
@Test
public void crossTestIterationOfMapReducePPCASequentialPPCA() throws Exception {
Matrix C_central = PCACommon.randomMatrix(D, d);
double ss = PCACommon.randSS();
InitialValues initValSeq = new InitialValues(C_central, ss);
InitialValues initValMR = new InitialValues(C_central.clone(), ss);
//1. run sequential
Matrix Ye_central = new DenseMatrix(N, D);
int row = 0;
for (VectorWritable vw : new SequenceFileDirValueIterable<VectorWritable>(
input, PathType.LIST, null, conf)) {
Ye_central.assignRow(row, vw.get());
row++;
}
double bishopSeqErr = ppcaDriver.runSequential(conf, Ye_central, initValSeq, 1);
//2. run mapreduce
DistributedRowMatrix Ye = new DistributedRowMatrix(input, tmp, N, D);
Ye.setConf(conf);
double bishopMRErr = ppcaDriver.runMapReduce(conf, Ye, initValMR, output, N, D, d, 1, 1, 1, 1);
Assert.assertEquals(
"ss value is different in sequential and mapreduce PCA", initValSeq.ss,
initValMR.ss, EPSILON);
double seqCTrace = PCACommon.trace(initValSeq.C);
double mrCTrace = PCACommon.trace(initValMR.C);
Assert.assertEquals(
"C value is different in sequential and mapreduce PCA", seqCTrace,
mrCTrace, EPSILON);
Assert.assertEquals(
"The PPCA error between sequntial and mapreduce methods is too different: "
+ bishopSeqErr + "!= " + bishopMRErr, bishopSeqErr, bishopMRErr, EPSILON);
}
示例4: classify
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/**
* Returns n-1 probabilities, one for each category but the last, for each row of a matrix. The
* probability of the missing 0-th category is 1 - rowSum(this result).
*
* @param data The matrix whose rows are vectors to classify
* @return A matrix of scores, one row per row of the input matrix, one column for each but the
* last category.
*/
public Matrix classify(Matrix data) {
Matrix r = new DenseMatrix(data.numRows(), numCategories() - 1);
for (int row = 0; row < data.numRows(); row++) {
r.assignRow(row, classify(data.viewRow(row)));
}
return r;
}