本文整理汇总了Java中org.apache.spark.mllib.linalg.Vector.size方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.size方法的具体用法?Java Vector.size怎么用?Java Vector.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.spark.mllib.linalg.Vector
的用法示例。
在下文中一共展示了Vector.size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidWeights
import org.apache.spark.mllib.linalg.Vector; //导入方法依赖的package包/类
private boolean isValidWeights(Vector weights) {
for (int i = 0; i < weights.size(); i++) {
double d = weights.apply(i);
if (Double.isNaN(d) || Double.isInfinite(d)) {
return false;
}
}
return true;
}
示例2: vectorToString
import org.apache.spark.mllib.linalg.Vector; //导入方法依赖的package包/类
private String vectorToString(Vector weights) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= weights.size(); i++) {
double d = weights.apply(i - 1);
sb.append(d);
if (i != weights.size()) {
sb.append(",");
}
}
return sb.toString();
}
示例3: toClassifierPrediction
import org.apache.spark.mllib.linalg.Vector; //导入方法依赖的package包/类
/**
* This is for the edge case where
* you have a single output layer
* and need to convert the output layer to
* an index
* @param vector the vector to get the classifier prediction for
* @return the prediction for the given vector
*/
public static double toClassifierPrediction(Vector vector) {
double max = Double.NEGATIVE_INFINITY;
int maxIndex = 0;
for (int i = 0; i < vector.size(); i++) {
double curr = vector.apply(i);
if (curr > max) {
maxIndex = i;
max = curr;
}
}
return maxIndex;
}