本文整理汇总了Java中org.apache.mahout.math.Vector.getQuick方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.getQuick方法的具体用法?Java Vector.getQuick怎么用?Java Vector.getQuick使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Vector
的用法示例。
在下文中一共展示了Vector.getQuick方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AtBMapper
import org.apache.mahout.math.Vector; //导入方法依赖的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 first part is done in mapper and the second in the combiner
*/
private void AtBMapper(Vector yi, Vector ym, Vector xi, Vector xm,
DenseMatrix resMatrix) {
// 1. Sum(Yi' x (Xi-Xm))
int xSize = xi.size();
Iterator<Vector.Element> nonZeroElements = yi.nonZeroes().iterator();
while (nonZeroElements.hasNext()) {
Vector.Element e = nonZeroElements.next();
int yRow = e.index();
double yScale = e.get();
for (int xCol = 0; xCol < xSize; xCol++) {
double centeredValue = xi.getQuick(xCol) - xm.getQuick(xCol);
double currValue = resMatrix.getQuick(yRow, xCol);
currValue += centeredValue * yScale;
resMatrix.setQuick(yRow, xCol, currValue);
}
}
}
示例2: AtxBCombiner
import org.apache.mahout.math.Vector; //导入方法依赖的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 first part is done in mapper and the second in the combiner
*/
private void AtxBCombiner(DenseMatrix resMatrix, Vector ym, Vector xm,
Vector xsum, int nRows) {
// 2. - Ym' x (Sum(Xi)-N*Xm)
int ysize = ym.size();
int xsize = xsum.size();
for (int yRow = 0; yRow < ysize; yRow++) {
double scale = ym.getQuick(yRow);
for (int xCol = 0; xCol < xsize; xCol++) {
double centeredValue = xsum.getQuick(xCol) - nRows
* xm.getQuick(xCol);
double currValue = resMatrix.getQuick(yRow, xCol);
currValue -= centeredValue * scale;
resMatrix.setQuick(yRow, xCol, currValue);
}
}
}
示例3: updateMinMax
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* Man and Max over sparse vector skip over zero elements. We take the zero
* elements into account in this method.
*
* @param minV
* the min
* @param maxV
* the max
* @param cntV
* the number of non-zero elements
* @param total
* number of processed rows
*/
private void updateMinMax(Vector minV, Vector maxV, Vector cntV, int total) {
for (int i = 0; i < cntV.size(); i++) {
int cnt = (int) cntV.getQuick(i);
if (cnt != total) {
// this implies that there was a zero element not counted in
// computing min and max. So, we count it in now.
double min = minV.getQuick(i);
double max = maxV.getQuick(i);
min = Math.min(min, 0);
max = Math.max(max, 0);
minV.setQuick(i, min);
maxV.setQuick(i, max);
}
}
}
示例4: vectorAssign
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* This method overrides the Vector.assign method to allow optimization for
* ZeroIndifferent functions
*
* @param vector
* the vector to be updated
* @param other
* the other vector
* @param function
* the function that operates on elements of the two vectors
* @return the modified vector
*/
static public Vector vectorAssign(Vector vector, Vector other, ZeroIndifferentFunc function) {
if (vector.size() != other.size()) {
throw new CardinalityException(vector.size(), other.size());
}
// special case: iterate only over the non-zero elements of the vector to
// add
Iterator<Element> it = other.nonZeroes().iterator();
Element e;
while (it.hasNext() && (e = it.next()) != null) {
double val = vector.getQuick(e.index());
double newVal = function.apply(val, e.get());
vector.setQuick(e.index(), newVal);
}
return vector;
}
示例5: outerProductWithIndices
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* computes the outer (tensor) product of two vectors. The result of applying the outer product on a pair of vectors is a matrix
* @param yi: sparse vector
* @param ym: mean vector
* @param xi: dense vector
* @param xm: mean vector
* @param nonZeroIndices: the indices of nonzero elements in the sparse vector
* @param resArray: resulting two-dimensional array
*/
public static void outerProductWithIndices(org.apache.spark.mllib.linalg.Vector yi, Vector ym, double[] xi,
Vector xm, double[][] resArray, int[] nonZeroIndices) {
// 1. Sum(Yi' x (Xi-Xm))
int xSize = xi.length;
double yScale=0;
int i, yRow;
for(i=0; i < nonZeroIndices.length; i++)
{
yRow=nonZeroIndices[i];
yScale=yi.apply(yRow);
for (int xCol = 0; xCol < xSize; xCol++) {
double centeredValue = xi[xCol] - xm.getQuick(xCol);
resArray[yRow][xCol] += centeredValue * yScale;
}
}
}
示例6: updateXtXAndYtx
import org.apache.mahout.math.Vector; //导入方法依赖的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;
}
示例7: vectorTimesMatrixTranspose
import org.apache.mahout.math.Vector; //导入方法依赖的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;
}
示例8: denseVectorPlusAbsDenseDiff
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
static void denseVectorPlusAbsDenseDiff(
DenseVector denseVector, Vector sparseVector, DenseVector meanVector) {
for (int i = 0; i < denseVector.size(); i++) {
double denseV = denseVector.getQuick(i);
double v = sparseVector.getQuick(i);
double mean = meanVector.getQuick(i);
denseVector.setQuick(i, denseV + Math.abs(v-mean));
}
}
示例9: denseVectorSubtractSparseSubtractDense
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
static void denseVectorSubtractSparseSubtractDense(DenseVector mainVector,
Vector subtractor1, DenseVector subtractor2) {
int nCols = mainVector.size();
for (int c = 0; c < nCols; c++) {
double v = mainVector.getQuick(c);
v -= subtractor1.getQuick(c);
v -= subtractor2.getQuick(c);
mainVector.setQuick(c, v);
}
}
示例10: subtractVectorArray
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* Subtract a vector from an array
* @param res: The minuend and the variable where the difference is stored
* @param subtractor: the subtrahend
* @return difference array
*/
public static double[] subtractVectorArray(double[] res, Vector subtractor) {
for (int i = 0; i < res.length; i++) {
res[i] -= subtractor.getQuick(i);
}
return res;
}
示例11: dotVectorArray
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* dot Product of vector and array
* @param vector
* @param arr2
* @return
*/
public static double dotVectorArray(Vector vector, double[] arr2) {
double dotRes = 0;
for (int i = 0; i < arr2.length; i++) {
dotRes += vector.getQuick(i) * arr2[i];
}
return dotRes;
}
示例12: denseVectorTimesMatrix
import org.apache.mahout.math.Vector; //导入方法依赖的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;
}
示例13: vectorTimesMatrixTranspose
import org.apache.mahout.math.Vector; //导入方法依赖的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;
}
示例14: sparseVectorMinusVector
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* Subtract a vector from a sparse vector
* @param sparseVector
* @param vector
* @param nonZeroIndices: the indices of nonzero elements in the sparse vector
* @param resArray: result array
* @return
*/
static double[] sparseVectorMinusVector(org.apache.spark.mllib.linalg.Vector sparseVector, Vector vector,
double[] resArray, int[] nonZeroIndices) {
int index = 0;
double value = 0;
for(int i=0; i<nonZeroIndices.length; i++)
{
index=nonZeroIndices[i];
value=sparseVector.apply(index);
resArray[index] = value - vector.getQuick(index); //because the array is already negated
}
return resArray;
}
示例15: denseVectorMinusVector
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* Subtract two dense vectors
* @param vector1
* @param vector2
* @param resArray: result array
* @return
*/
static double[] denseVectorMinusVector(org.apache.spark.mllib.linalg.Vector vector1, Vector vector2,
double[] resArray) {
for(int i=0; i< vector2.size(); i++)
{
resArray[i] = vector1.apply(i) - vector2.getQuick(i);
}
return resArray;
}