当前位置: 首页>>代码示例>>Java>>正文


Java Vector.toArray方法代码示例

本文整理汇总了Java中org.apache.spark.mllib.linalg.Vector.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.toArray方法的具体用法?Java Vector.toArray怎么用?Java Vector.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.spark.mllib.linalg.Vector的用法示例。


在下文中一共展示了Vector.toArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hellingerDistance

import org.apache.spark.mllib.linalg.Vector; //导入方法依赖的package包/类
/**
 * Calculate similarity (Hellinger Distance) between vectors
 *
 * @param vecA initial vector from which to calculate a similarity
 * @param vecB second vector involved in similarity calculation
 * @return similarity between two vectors
 */
public static double hellingerDistance(Vector vecA, Vector vecB) {
  double[] arrA = vecA.toArray();
  double[] arrB = vecB.toArray();

  double sim = 0.0;

  int arrsize = arrA.length;
  for (int i = 0; i < arrsize; i++) {
    double a = arrA[i];
    double b = arrB[i];
    double sqrtDiff = Math.sqrt(a) - Math.sqrt(b);
    sim += sqrtDiff * sqrtDiff;
  }

  sim = sim / Math.sqrt(2);

  return sim;
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:26,代码来源:SimilarityUtil.java

示例2: pearsonDistance

import org.apache.spark.mllib.linalg.Vector; //导入方法依赖的package包/类
/**
 * Calculate similarity (Pearson Distance) between vectors
 *
 * @param vecA initial vector from which to calculate a similarity
 * @param vecB second vector involved in similarity calculation
 * @return similarity between two vectors
 */
public static double pearsonDistance(Vector vecA, Vector vecB) {
  double[] arrA = vecA.toArray();
  double[] arrB = vecB.toArray();

  int viewA = 0;
  int viewB = 0;
  int viewAB = 0;

  int arrsize = arrA.length;
  for (int i = 0; i < arrsize; i++) {
    if (arrA[i] > 0) {
      viewA++;
    }

    if (arrB[i] > 0) {
      viewB++;
    }

    if (arrB[i] > 0 && arrA[i] > 0) {
      viewAB++;
    }
  }
  return viewAB / (Math.sqrt(viewA) * Math.sqrt(viewB));
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:32,代码来源:SimilarityUtil.java

示例3: getPredictedValue

import org.apache.spark.mllib.linalg.Vector; //导入方法依赖的package包/类
/**
 * This method is to predict the label of a given data point
 */
private String getPredictedValue(Vector dataPointVector, int clusterIndex, double clusterBoundary) {

    String prediction;
    EuclideanDistance euclideanDistance = new EuclideanDistance();
    Vector[] clusterCenters = kMeansModel.clusterCenters();

    double[] dataPoint = dataPointVector.toArray();
    double[] clusterCenter = clusterCenters[clusterIndex].toArray();
    double distance = euclideanDistance.compute(clusterCenter, dataPoint);

    if (distance > clusterBoundary) {
        prediction = anomalyLabel;
    } else {
        prediction = normalLabel;
    }

    return prediction;
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:22,代码来源:AnomalyDetectionModel.java


注:本文中的org.apache.spark.mllib.linalg.Vector.toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。