gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-23 17:37:05 25 4
gpt4 key购买 nike

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

WeightedThing.getWeight介绍

暂无

代码示例

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

public Multinomial(Iterable<WeightedThing<T>> things) {
 this();
 for (WeightedThing<T> thing : things) {
  add(thing.getValue(), thing.getWeight());
 }
}

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

@Override
 protected boolean lessThan(WeightedThing<Vector> a, WeightedThing<Vector> b) {
  return a.getWeight() > b.getWeight();
 }
};

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

@Override
 protected boolean lessThan(WeightedThing<Vector> a, WeightedThing<Vector> b) {
  return a.getWeight() > b.getWeight();
 }
};

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

@Override
 protected boolean lessThan(WeightedThing<Vector> a, WeightedThing<Vector> b) {
  return a.getWeight() > b.getWeight();
 }
};

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

/**
 * Adds up the distances from each point to its closest cluster and returns the sum.
 * @param datapoints iterable of datapoints.
 * @param centroids searcher of Centroids.
 * @return the total cost described above.
 */
public static double totalClusterCost(Iterable<? extends Vector> datapoints, Searcher centroids) {
 double totalCost = 0;
 for (Vector vector : datapoints) {
  totalCost += centroids.searchFirst(vector, false).getWeight();
 }
 return totalCost;
}

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

/**
 * Adds up the distances from each point to its closest cluster and returns the sum.
 * @param datapoints iterable of datapoints.
 * @param centroids searcher of Centroids.
 * @return the total cost described above.
 */
public static double totalClusterCost(Iterable<? extends Vector> datapoints, Searcher centroids) {
 double totalCost = 0;
 for (Vector vector : datapoints) {
  totalCost += centroids.searchFirst(vector, false).getWeight();
 }
 return totalCost;
}

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

/**
 * Adds up the distances from each point to its closest cluster and returns the sum.
 * @param datapoints iterable of datapoints.
 * @param centroids searcher of Centroids.
 * @return the total cost described above.
 */
public static double totalClusterCost(Iterable<? extends Vector> datapoints, Searcher centroids) {
 double totalCost = 0;
 for (Vector vector : datapoints) {
  totalCost += centroids.searchFirst(vector, false).getWeight();
 }
 return totalCost;
}

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

public Multinomial(Iterable<WeightedThing<T>> things) {
 this();
 for (WeightedThing<T> thing : things) {
  add(thing.getValue(), thing.getWeight());
 }
}

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

@Override
public List<WeightedThing<Vector>> search(Vector query, int limit) {
 PriorityQueue<WeightedThing<Vector>> top = searchInternal(query);
 List<WeightedThing<Vector>> results = Lists.newArrayListWithExpectedSize(top.size());
 while (top.size() != 0) {
  WeightedThing<Vector> wv = top.pop();
  results.add(new WeightedThing<Vector>(((HashedVector) wv.getValue()).getVector(), wv.getWeight()));
 }
 Collections.reverse(results);
 if (limit < results.size()) {
  results = results.subList(0, limit);
 }
 return results;
}

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

@Override
public List<WeightedThing<Vector>> search(Vector query, int limit) {
 PriorityQueue<WeightedThing<Vector>> top = searchInternal(query);
 List<WeightedThing<Vector>> results = Lists.newArrayListWithExpectedSize(top.size());
 while (top.size() != 0) {
  WeightedThing<Vector> wv = top.pop();
  results.add(new WeightedThing<Vector>(((HashedVector) wv.getValue()).getVector(), wv.getWeight()));
 }
 Collections.reverse(results);
 if (limit < results.size()) {
  results = results.subList(0, limit);
 }
 return results;
}

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

@Override
public List<WeightedThing<Vector>> search(Vector query, int limit) {
 PriorityQueue<WeightedThing<Vector>> top = searchInternal(query);
 List<WeightedThing<Vector>> results = Lists.newArrayListWithExpectedSize(top.size());
 while (top.size() != 0) {
  WeightedThing<Vector> wv = top.pop();
  results.add(new WeightedThing<>(((HashedVector) wv.getValue()).getVector(), wv.getWeight()));
 }
 Collections.reverse(results);
 if (limit < results.size()) {
  results = results.subList(0, limit);
 }
 return results;
}

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

protected static WeightedThing<Vector> removeHash(WeightedThing<Vector> input) {
 return new WeightedThing<Vector>(((HashedVector) input.getValue()).getVector(), input.getWeight());
}

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

protected static WeightedThing<Vector> removeHash(WeightedThing<Vector> input) {
 return new WeightedThing<>(((HashedVector) input.getValue()).getVector(), input.getWeight());
}

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

protected static WeightedThing<Vector> removeHash(WeightedThing<Vector> input) {
 return new WeightedThing<Vector>(((HashedVector) input.getValue()).getVector(), input.getWeight());
}

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

@Override
public boolean remove(Vector vector, double epsilon) {
 WeightedThing<Vector> toRemove = searchFirst(vector, false);
 if (toRemove.getWeight() < epsilon) {
  Iterator<? extends Vector> basisVectors = basisMatrix.iterator();
  for (TreeMultiset<WeightedThing<Vector>> projection : scalarProjections) {
   if (!projection.remove(new WeightedThing<Vector>(vector, vector.dot(basisVectors.next())))) {
    throw new RuntimeException("Internal inconsistency in ProjectionSearch");
   }
  }
  return true;
 } else {
  return false;
 }
}

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

@Override
public boolean remove(Vector vector, double epsilon) {
 WeightedThing<Vector> toRemove = searchFirst(vector, false);
 if (toRemove.getWeight() < epsilon) {
  Iterator<? extends Vector> basisVectors = basisMatrix.iterator();
  for (TreeMultiset<WeightedThing<Vector>> projection : scalarProjections) {
   if (!projection.remove(new WeightedThing<Vector>(vector, vector.dot(basisVectors.next())))) {
    throw new RuntimeException("Internal inconsistency in ProjectionSearch");
   }
  }
  return true;
 } else {
  return false;
 }
}

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

@Override
public boolean remove(Vector vector, double epsilon) {
 WeightedThing<Vector> toRemove = searchFirst(vector, false);
 if (toRemove.getWeight() < epsilon) {
  Iterator<? extends Vector> basisVectors = basisMatrix.iterator();
  for (TreeMultiset<WeightedThing<Vector>> projection : scalarProjections) {
   if (!projection.remove(new WeightedThing<>(vector, vector.dot(basisVectors.next())))) {
    throw new RuntimeException("Internal inconsistency in ProjectionSearch");
   }
  }
  return true;
 } else {
  return false;
 }
}

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

@Test
public void testNearMatch() {
 searcher.clear();
 List<MatrixSlice> queries = Lists.newArrayList(Iterables.limit(dataPoints, 100));
 searcher.addAllMatrixSlicesAsWeightedVectors(dataPoints);
 MultiNormal noise = new MultiNormal(0.01, new DenseVector(20));
 for (MatrixSlice slice : queries) {
  Vector query = slice.vector();
  final Vector epsilon = noise.sample();
  List<WeightedThing<Vector>> r = searcher.search(query, 2);
  query = query.plus(epsilon);
  assertEquals("Distance has to be small", epsilon.norm(2), r.get(0).getWeight(), 1.0e-1);
  assertEquals("Answer must be substantially the same as query", epsilon.norm(2),
    r.get(0).getValue().minus(query).norm(2), 1.0e-1);
  assertTrue("Wrong answer must be further away", r.get(1).getWeight() > r.get(0).getWeight());
 }
}

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

@Test
public void testSearchFirst() {
 searcher.clear();
 searcher.addAll(dataPoints);
 for (Vector datapoint : dataPoints) {
  WeightedThing<Vector> first = searcher.searchFirst(datapoint, false);
  WeightedThing<Vector> second = searcher.searchFirst(datapoint, true);
  List<WeightedThing<Vector>> firstTwo = searcher.search(datapoint, 2);
  assertEquals("First isn't self", 0, first.getWeight(), 0);
  assertEquals("First isn't self", datapoint, first.getValue());
  assertEquals("First doesn't match", first, firstTwo.get(0));
  assertEquals("Second doesn't match", second, firstTwo.get(1));
 }
}

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

@Test
public void testOrdering() {
 searcher.clear();
 Matrix queries = new DenseMatrix(100, 20);
 MultiNormal gen = new MultiNormal(20);
 for (int i = 0; i < 100; i++) {
  queries.viewRow(i).assign(gen.sample());
 }
 searcher.addAllMatrixSlices(dataPoints);
 for (MatrixSlice query : queries) {
  List<WeightedThing<Vector>> r = searcher.search(query.vector(), 200);
  double x = 0;
  for (WeightedThing<Vector> thing : r) {
   assertTrue("Scores must be monotonic increasing", thing.getWeight() >= x);
   x = thing.getWeight();
  }
 }
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com