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

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

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

WeightedThing.<init>介绍

暂无

代码示例

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

double sample(double u) {
  if (u < limit) {
   List<WeightedThing<Integer>> steps = Lists.newArrayList();
   limit = 1;
   int i = 0;
   while (u / 20 < limit) {
    double pdf = pd.probability(i);
    limit -= pdf;
    steps.add(new WeightedThing<>(i, pdf));
    i++;
   }
   steps.add(new WeightedThing<>(steps.size(), limit));
   partial = new Multinomial<>(steps);
  }
  return partial.sample(u);
 }
}

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

/**
 * Returns the closest vector to the query.
 * When only one the nearest vector is needed, use this method, NOT search(query, limit) because
 * it's faster (less overhead).
 *
 * @param query the vector to search for
 * @param differentThanQuery if true, returns the closest vector different than the query (this
 *                           only matters if the query is among the searched vectors), otherwise,
 *                           returns the closest vector to the query (even the same vector).
 * @return the weighted vector closest to the query
 */
@Override
public WeightedThing<Vector> searchFirst(Vector query, boolean differentThanQuery) {
 double bestDistance = Double.POSITIVE_INFINITY;
 Vector bestVector = null;
 for (Vector row : referenceVectors) {
  double distance = distanceMeasure.distance(query, row);
  if (distance < bestDistance && (!differentThanQuery || !row.equals(query))) {
   bestDistance = distance;
   bestVector = row;
  }
 }
 return new WeightedThing<Vector>(bestVector, bestDistance);
}

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

double sample(double u) {
  if (u < limit) {
   List<WeightedThing<Integer>> steps = Lists.newArrayList();
   limit = 1;
   int i = 0;
   while (u / 20 < limit) {
    double pdf = pd.probability(i);
    limit -= pdf;
    steps.add(new WeightedThing<>(i, pdf));
    i++;
   }
   steps.add(new WeightedThing<>(steps.size(), limit));
   partial = new Multinomial<>(steps);
  }
  return partial.sample(u);
 }
}

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

/**
 * Returns the closest vector to the query.
 * When only one the nearest vector is needed, use this method, NOT search(query, limit) because
 * it's faster (less overhead).
 *
 * @param query the vector to search for
 * @param differentThanQuery if true, returns the closest vector different than the query (this
 *                           only matters if the query is among the searched vectors), otherwise,
 *                           returns the closest vector to the query (even the same vector).
 * @return the weighted vector closest to the query
 */
@Override
public WeightedThing<Vector> searchFirst(Vector query, boolean differentThanQuery) {
 double bestDistance = Double.POSITIVE_INFINITY;
 Vector bestVector = null;
 for (Vector row : referenceVectors) {
  double distance = distanceMeasure.distance(query, row);
  if (distance < bestDistance && (!differentThanQuery || !row.equals(query))) {
   bestDistance = distance;
   bestVector = row;
  }
 }
 return new WeightedThing<Vector>(bestVector, bestDistance);
}

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

/**
 * Returns the closest vector to the query.
 * When only one the nearest vector is needed, use this method, NOT search(query, limit) because
 * it's faster (less overhead).
 *
 * @param query the vector to search for
 * @param differentThanQuery if true, returns the closest vector different than the query (this
 *                           only matters if the query is among the searched vectors), otherwise,
 *                           returns the closest vector to the query (even the same vector).
 * @return the weighted vector closest to the query
 */
@Override
public WeightedThing<Vector> searchFirst(Vector query, boolean differentThanQuery) {
 double bestDistance = Double.POSITIVE_INFINITY;
 Vector bestVector = null;
 for (Vector row : referenceVectors) {
  double distance = distanceMeasure.distance(query, row);
  if (distance < bestDistance && (!differentThanQuery || !row.equals(query))) {
   bestDistance = distance;
   bestVector = row;
  }
 }
 return new WeightedThing<>(bestVector, bestDistance);
}

代码示例来源: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-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

@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-mr

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

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

for (int i = 0; i < basisMatrix.numRows(); ++i) {
 List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
 WeightedThing<Vector> searchedThing = new WeightedThing<Vector>(projection.get(i));
 int middle = Collections.binarySearch(currProjections, searchedThing);
 if (middle < 0) {

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

for (int i = 0; i < basisMatrix.numRows(); ++i) {
 List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
 WeightedThing<Vector> searchedThing = new WeightedThing<Vector>(projection.get(i));
 int middle = Collections.binarySearch(currProjections, searchedThing);
 if (middle < 0) {

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

for (int i = 0; i < basisMatrix.numRows(); ++i) {
 List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
 WeightedThing<Vector> searchedThing = new WeightedThing<>(projection.get(i));
 int middle = Collections.binarySearch(currProjections, searchedThing);
 if (middle < 0) {

代码示例来源: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-mrlegacy

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

代码示例来源: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-core

/**
 * Adds a WeightedVector into the set of projections for later searching.
 * @param vector  The WeightedVector to add.
 */
@Override
public void add(Vector vector) {
 initialize(vector.size());
 Vector projection = basisMatrix.times(vector);
 // Add the the new vector and the projected distance to each set separately.
 int i = 0;
 for (TreeMultiset<WeightedThing<Vector>> s : scalarProjections) {
  s.add(new WeightedThing<Vector>(vector, projection.get(i++)));
 }
 int numVectors = scalarProjections.get(0).size();
 for (TreeMultiset<WeightedThing<Vector>> s : scalarProjections) {
  Preconditions.checkArgument(s.size() == numVectors, "Number of vectors in projection sets "
    + "differ");
  double firstWeight = s.firstEntry().getElement().getWeight();
  for (WeightedThing<Vector> w : s) {
   Preconditions.checkArgument(firstWeight <= w.getWeight(), "Weights not in non-decreasing "
     + "order");
   firstWeight = w.getWeight();
  }
 }
}

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

/**
 * Adds a WeightedVector into the set of projections for later searching.
 * @param vector  The WeightedVector to add.
 */
@Override
public void add(Vector vector) {
 initialize(vector.size());
 Vector projection = basisMatrix.times(vector);
 // Add the the new vector and the projected distance to each set separately.
 int i = 0;
 for (TreeMultiset<WeightedThing<Vector>> s : scalarProjections) {
  s.add(new WeightedThing<>(vector, projection.get(i++)));
 }
 int numVectors = scalarProjections.get(0).size();
 for (TreeMultiset<WeightedThing<Vector>> s : scalarProjections) {
  Preconditions.checkArgument(s.size() == numVectors, "Number of vectors in projection sets "
    + "differ");
  double firstWeight = s.firstEntry().getElement().getWeight();
  for (WeightedThing<Vector> w : s) {
   Preconditions.checkArgument(firstWeight <= w.getWeight(), "Weights not in non-decreasing "
     + "order");
   firstWeight = w.getWeight();
  }
 }
}

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

/**
 * Adds a WeightedVector into the set of projections for later searching.
 * @param vector  The WeightedVector to add.
 */
@Override
public void add(Vector vector) {
 initialize(vector.size());
 Vector projection = basisMatrix.times(vector);
 // Add the the new vector and the projected distance to each set separately.
 int i = 0;
 for (TreeMultiset<WeightedThing<Vector>> s : scalarProjections) {
  s.add(new WeightedThing<Vector>(vector, projection.get(i++)));
 }
 int numVectors = scalarProjections.get(0).size();
 for (TreeMultiset<WeightedThing<Vector>> s : scalarProjections) {
  Preconditions.checkArgument(s.size() == numVectors, "Number of vectors in projection sets "
    + "differ");
  double firstWeight = s.firstEntry().getElement().getWeight();
  for (WeightedThing<Vector> w : s) {
   Preconditions.checkArgument(firstWeight <= w.getWeight(), "Weights not in non-decreasing "
     + "order");
   firstWeight = w.getWeight();
  }
 }
}

相关文章

微信公众号

最新文章

更多