本文整理汇总了Java中org.apache.mahout.math.Vector.zSum方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.zSum方法的具体用法?Java Vector.zSum怎么用?Java Vector.zSum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.math.Vector
的用法示例。
在下文中一共展示了Vector.zSum方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rMultinom
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/** Returns one sample from a multinomial. */
public static int rMultinom(Vector probabilities) {
// our probability argument are not normalized.
double total = probabilities.zSum();
double nextDouble = RANDOM.nextDouble();
double p = nextDouble * total;
for (int i = 0; i < probabilities.size(); i++) {
double pi = probabilities.get(i);
if (p < pi) {
return i;
} else {
p -= pi;
}
}
// can't happen except for round-off error so we don't care what we return here
return 0;
}
示例2: getAverageStd
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
@Override
public double getAverageStd() {
if (sumWeight == 0.0) {
return 0.0;
} else {
Vector std = getStd();
return std.zSum() / std.size();
}
}
示例3: rDirichlet
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* Sample from a Dirichlet distribution, returning a vector of probabilities using a stick-breaking
* algorithm
*
* @param totalCounts
* an unnormalized count Vector
* @param alpha0
* a double
* @return a Vector of probabilities
*/
public static Vector rDirichlet(Vector totalCounts, double alpha0) {
Vector pi = totalCounts.like();
double total = totalCounts.zSum();
double remainder = 1.0;
for (int k = 0; k < pi.size(); k++) {
double countK = totalCounts.get(k);
total -= countK;
double betaK = rBeta(1.0 + countK, Math.max(0.0, alpha0 + total));
double piK = betaK * remainder;
pi.set(k, piK);
remainder -= piK;
}
return pi;
}
示例4: median
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* A quick and dirty hack to compute the median of a vector...
* @param v
* @return
*/
private static double median(Vector v) {
OnlineSummarizer med = new OnlineSummarizer();
if (v.size() < 100) {
return v.zSum() / v.size();
}
for (Vector.Element e : v) {
med.add(e.get());
}
return med.getMedian();
}
示例5: trace
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* @param m matrix
* @return m.viewDiagonal().zSum()
*/
static double trace(Matrix m) {
Vector d = m.viewDiagonal();
return d.zSum();
}
示例6: trace
import org.apache.mahout.math.Vector; //导入方法依赖的package包/类
/**
* @param m matrix
* @return trace of matrix m
*/
static double trace(Matrix m) {
Vector d = m.viewDiagonal();
return d.zSum();
}