org.apache.mahout.math.WeightedVector.getWeight()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中org.apache.mahout.math.WeightedVector.getWeight()方法的一些代码示例,展示了WeightedVector.getWeight()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WeightedVector.getWeight()方法的具体详情如下:
包路径:org.apache.mahout.math.WeightedVector
类名称:WeightedVector
方法名:getWeight

WeightedVector.getWeight介绍

暂无

代码示例

代码示例来源:origin: apache/mahout

@Override
public int compare(WeightedVector a, WeightedVector b) {
 if (a == b) {
  return 0;
 }
 double aWeight = a.getWeight();
 double bWeight = b.getWeight();
 int r = Double.compare(aWeight, bWeight);
 if (r != 0 && Math.abs(aWeight - bWeight) >= DOUBLE_EQUALITY_ERROR) {
  return r;
 }
 double diff = a.minus(b).norm(1);
 if (diff < 1.0e-12) {
  return 0;
 }
 for (Vector.Element element : a.all()) {
  r = Double.compare(element.get(), b.get(element.index()));
  if (r != 0) {
   return r;
  }
 }
 return 0;
}

代码示例来源:origin: apache/mahout

public Centroid(WeightedVector original) {
 super(original.getVector().like().assign(original), original.getWeight(), original.getIndex());
}

代码示例来源:origin: apache/mahout

public static Centroid create(int key, Vector initialValue) {
 if (initialValue instanceof WeightedVector) {
  return new Centroid(key, new DenseVector(initialValue), ((WeightedVector) initialValue).getWeight());
 } else {
  return new Centroid(key, new DenseVector(initialValue), 1);
 }
}

代码示例来源:origin: apache/mahout

@Test
public void testProjection() {
 Vector v1 = new DenseVector(10).assign(Functions.random());
 WeightedVector v2 = new WeightedVector(v1, v1, 31);
 assertEquals(v1.dot(v1), v2.getWeight(), 1.0e-13);
 assertEquals(31, v2.getIndex());
 Matrix y = new DenseMatrix(10, 4).assign(Functions.random());
 Matrix q = new QRDecomposition(y.viewPart(0, 10, 0, 3)).getQ();
 Vector nullSpace = y.viewColumn(3).minus(q.times(q.transpose().times(y.viewColumn(3))));
 WeightedVector v3 = new WeightedVector(q.viewColumn(0).plus(q.viewColumn(1)), nullSpace, 1);
 assertEquals(0, v3.getWeight(), 1.0e-13);
 Vector qx = q.viewColumn(0).plus(q.viewColumn(1)).normalize();
 WeightedVector v4 = new WeightedVector(qx, q.viewColumn(0), 2);
 assertEquals(Math.sqrt(0.5), v4.getWeight(), 1.0e-13);
 WeightedVector v5 = WeightedVector.project(q.viewColumn(0), qx);
 assertEquals(Math.sqrt(0.5), v5.getWeight(), 1.0e-13);
}

代码示例来源:origin: org.apache.mahout/mahout-mr

/**
  * Computes the total weight of the points in the given Vector iterable.
  * @param data iterable of points
  * @return total weight
  */
 public static double totalWeight(Iterable<? extends Vector> data) {
  double sum = 0;
  for (Vector row : data) {
   Preconditions.checkNotNull(row);
   if (row instanceof WeightedVector) {
    sum += ((WeightedVector)row).getWeight();
   } else {
    sum++;
   }
  }
  return sum;
 }
}

代码示例来源:origin: org.apache.mahout/mahout-core

/**
  * Computes the total weight of the points in the given Vector iterable.
  * @param data iterable of points
  * @return total weight
  */
 public static double totalWeight(Iterable<? extends Vector> data) {
  double sum = 0;
  for (Vector row : data) {
   Preconditions.checkNotNull(row);
   if (row instanceof WeightedVector) {
    sum += ((WeightedVector)row).getWeight();
   } else {
    sum++;
   }
  }
  return sum;
 }
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

/**
  * Computes the total weight of the points in the given Vector iterable.
  * @param data iterable of points
  * @return total weight
  */
 public static double totalWeight(Iterable<? extends Vector> data) {
  double sum = 0;
  for (Vector row : data) {
   Preconditions.checkNotNull(row);
   if (row instanceof WeightedVector) {
    sum += ((WeightedVector)row).getWeight();
   } else {
    sum++;
   }
  }
  return sum;
 }
}

代码示例来源:origin: org.apache.mahout/mahout-math

@Override
public int compare(WeightedVector a, WeightedVector b) {
 if (a == b) {
  return 0;
 }
 double aWeight = a.getWeight();
 double bWeight = b.getWeight();
 int r = Double.compare(aWeight, bWeight);
 if (r != 0 && Math.abs(aWeight - bWeight) >= DOUBLE_EQUALITY_ERROR) {
  return r;
 }
 double diff = a.minus(b).norm(1);
 if (diff < 1.0e-12) {
  return 0;
 }
 for (Vector.Element element : a.all()) {
  r = Double.compare(element.get(), b.get(element.index()));
  if (r != 0) {
   return r;
  }
 }
 return 0;
}

代码示例来源:origin: org.apache.mahout/mahout-core

public HashedVector(WeightedVector weightedVector, Matrix projection, long mask) {
 super(weightedVector.getVector(), weightedVector.getWeight(), weightedVector.getIndex());
 this.hash = mask & computeHash64(weightedVector, projection);
}

代码示例来源:origin: org.apache.mahout/mahout-mr

public HashedVector(WeightedVector weightedVector, Matrix projection, long mask) {
 super(weightedVector.getVector(), weightedVector.getWeight(), weightedVector.getIndex());
 this.hash = mask & computeHash64(weightedVector, projection);
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

public HashedVector(WeightedVector weightedVector, Matrix projection, long mask) {
 super(weightedVector.getVector(), weightedVector.getWeight(), weightedVector.getIndex());
 this.hash = mask & computeHash64(weightedVector, projection);
}

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

/**
 * Selects some of the original points randomly with probability proportional to their weights. This is much
 * less sophisticated than the kmeans++ approach, however it is faster and coupled with
 *
 * The side effect of this method is to fill the centroids structure itself.
 *
 * @param datapoints The datapoints to select from.  These datapoints should be WeightedVectors of some kind.
 */
private void initializeSeedsRandomly(List<? extends WeightedVector> datapoints) {
 int numDatapoints = datapoints.size();
 double totalWeight = 0;
 for (WeightedVector datapoint : datapoints) {
  totalWeight += datapoint.getWeight();
 }
 Multinomial<Integer> seedSelector = new Multinomial<Integer>();
 for (int i = 0; i < numDatapoints; ++i) {
  seedSelector.add(i, datapoints.get(i).getWeight() / totalWeight);
 }
 for (int i = 0; i < numClusters; ++i) {
  int sample = seedSelector.sample();
  seedSelector.delete(sample);
  Centroid centroid = new Centroid(datapoints.get(sample));
  centroid.setIndex(i);
  centroids.add(centroid);
 }
}

代码示例来源:origin: org.apache.mahout/mahout-core

/**
 * Selects some of the original points randomly with probability proportional to their weights. This is much
 * less sophisticated than the kmeans++ approach, however it is faster and coupled with
 *
 * The side effect of this method is to fill the centroids structure itself.
 *
 * @param datapoints The datapoints to select from.  These datapoints should be WeightedVectors of some kind.
 */
private void initializeSeedsRandomly(List<? extends WeightedVector> datapoints) {
 int numDatapoints = datapoints.size();
 double totalWeight = 0;
 for (WeightedVector datapoint : datapoints) {
  totalWeight += datapoint.getWeight();
 }
 Multinomial<Integer> seedSelector = new Multinomial<Integer>();
 for (int i = 0; i < numDatapoints; ++i) {
  seedSelector.add(i, datapoints.get(i).getWeight() / totalWeight);
 }
 for (int i = 0; i < numClusters; ++i) {
  int sample = seedSelector.sample();
  seedSelector.delete(sample);
  Centroid centroid = new Centroid(datapoints.get(sample));
  centroid.setIndex(i);
  centroids.add(centroid);
 }
}

代码示例来源:origin: org.apache.mahout/mahout-mr

/**
 * Selects some of the original points randomly with probability proportional to their weights. This is much
 * less sophisticated than the kmeans++ approach, however it is faster and coupled with
 *
 * The side effect of this method is to fill the centroids structure itself.
 *
 * @param datapoints The datapoints to select from.  These datapoints should be WeightedVectors of some kind.
 */
private void initializeSeedsRandomly(List<? extends WeightedVector> datapoints) {
 int numDatapoints = datapoints.size();
 double totalWeight = 0;
 for (WeightedVector datapoint : datapoints) {
  totalWeight += datapoint.getWeight();
 }
 Multinomial<Integer> seedSelector = new Multinomial<>();
 for (int i = 0; i < numDatapoints; ++i) {
  seedSelector.add(i, datapoints.get(i).getWeight() / totalWeight);
 }
 for (int i = 0; i < numClusters; ++i) {
  int sample = seedSelector.sample();
  seedSelector.delete(sample);
  Centroid centroid = new Centroid(datapoints.get(sample));
  centroid.setIndex(i);
  centroids.add(centroid);
 }
}

代码示例来源:origin: org.apache.mahout/mahout-math

public Centroid(WeightedVector original) {
 super(original.getVector().like().assign(original), original.getWeight(), original.getIndex());
}

代码示例来源:origin: org.apache.mahout/mahout-math

public static Centroid create(int key, Vector initialValue) {
 if (initialValue instanceof WeightedVector) {
  return new Centroid(key, new DenseVector(initialValue), ((WeightedVector) initialValue).getWeight());
 } else {
  return new Centroid(key, new DenseVector(initialValue), 1);
 }
}

代码示例来源:origin: org.apache.mahout/mahout-mr

double vectorWeight;
if (vector instanceof WeightedVector) {
 vectorWeight = ((WeightedVector) vector).getWeight();
} else {
 vectorWeight = 1;

代码示例来源:origin: org.apache.mahout/mahout-core

double vectorWeight;
if (vector instanceof WeightedVector) {
 vectorWeight = ((WeightedVector) vector).getWeight();
} else {
 vectorWeight = 1;

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

double vectorWeight;
if (vector instanceof WeightedVector) {
 vectorWeight = ((WeightedVector) vector).getWeight();
} else {
 vectorWeight = 1;

代码示例来源:origin: org.apache.mahout/mahout-core

for (WeightedVector testDatapoint : trainTestSplit.getSecond()) {
 WeightedVector closest = (WeightedVector) centroids.searchFirst(testDatapoint, false).getValue();
 closest.setWeight(closest.getWeight() + testDatapoint.getWeight());

相关文章