本文整理汇总了Java中org.apache.mahout.math.Matrix.getQuick方法的典型用法代码示例。如果您正苦于以下问题:Java Matrix.getQuick方法的具体用法?Java Matrix.getQuick怎么用?Java Matrix.getQuick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Matrix
的用法示例。
在下文中一共展示了Matrix.getQuick方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateXtXAndYtx
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/***
* Mi = (Yi-Ym)' x (Xi-Xm) = Yi' x (Xi-Xm) - Ym' x (Xi-Xm)
*
* M = Sum(Mi) = Sum(Yi' x (Xi-Xm)) - Ym' x (Sum(Xi)-N*Xm)
*
* The second part is done in this function
*/
public static Matrix updateXtXAndYtx(Matrix realCentralYtx,
Vector realCentralSumX, Vector ym, Vector xm, int nRows) {
for (int yRow = 0; yRow < ym.size(); yRow++) {
double scale = ym.getQuick(yRow);
for (int xCol = 0; xCol < realCentralSumX.size(); xCol++) {
double centeredValue = realCentralSumX.getQuick(xCol) - nRows
* xm.getQuick(xCol);
double currValue = realCentralYtx.getQuick(yRow, xCol);
currValue -= centeredValue * scale;
realCentralYtx.setQuick(yRow, xCol, currValue);
}
}
return realCentralYtx;
}
示例2: sparseVectorTimesMatrix
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/**
* multiply a sparse vector by a matrix
* @param sparseVector
* @param matrix
* @param resArray
*/
static void sparseVectorTimesMatrix(org.apache.spark.mllib.linalg.Vector sparseVector, Matrix matrix,
double[] resArray) {
int matrixCols = matrix.numCols();
int[] indices;
for (int col = 0; col < matrixCols; col++)
{
indices=((SparseVector)sparseVector).indices();
int index = 0, i=0;
double value = 0;
double dotRes = 0;
for(i=0; i <indices.length; i++)
{
index=indices[i];
value=sparseVector.apply(index);
dotRes += matrix.getQuick(index,col) * value;
}
resArray[col] = dotRes;
}
}
示例3: denseVectorTimesMatrix
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
static Vector denseVectorTimesMatrix(DenseVector vector, Matrix matrix,
DenseVector resVector) {
int nRows = matrix.numRows();
int nCols = matrix.numCols();
for (int c = 0; c < nCols; c++) {
double dotres = 0;
for (int r = 0; r < nRows; r++)
dotres += vector.getQuick(r) * matrix.getQuick(r, c);
resVector.set(c, dotres);
}
return resVector;
}
示例4: vectorTimesMatrixTranspose
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
static Vector vectorTimesMatrixTranspose(Vector vector,
Matrix matrix, DenseVector resVector) {
int nRows = matrix.numRows();
int nCols = matrix.numCols();
for (int r = 0; r < nRows; r++) {
double dotres = 0;
for (int c = 0; c < nCols; c++)
dotres += vector.getQuick(c) * matrix.getQuick(r, c);
resVector.set(r, dotres);
}
return resVector;
}
示例5: denseVectorTimesMatrix
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/**
* multiply a dense vector by a matrix
* @param xm_mahout: result vector
* @return
*/
static Vector denseVectorTimesMatrix(Vector vector, Matrix matrix,
Vector xm_mahout) {
int nRows = matrix.numRows();
int nCols = matrix.numCols();
for (int c = 0; c < nCols; c++) {
double dotres = 0;
for (int r = 0; r < nRows; r++)
dotres += vector.getQuick(r) * matrix.getQuick(r, c);
xm_mahout.set(c, dotres);
}
return xm_mahout;
}
示例6: vectorTimesMatrixTranspose
import org.apache.mahout.math.Matrix; //导入方法依赖的package包/类
/**
* multiply a dense vector by the transpose of a matrix
* @param resArray: result array
* @return
*/
static double[] vectorTimesMatrixTranspose(Vector vector, Matrix matrix,
double[] resArray) {
int nRows = matrix.numRows();
int nCols = matrix.numCols();
for (int r = 0; r < nRows; r++) {
double dotres = 0;
for (int c = 0; c < nCols; c++)
dotres += vector.getQuick(c) * matrix.getQuick(r, c);
resArray[r] = dotres;
}
return resArray;
}