org.apache.mahout.math.random.WeightedThing类的使用及代码示例

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

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

WeightedThing介绍

[英]Handy for creating multinomial distributions of things.
[中]便于创建事物的多项式分布。

代码示例

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

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

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

List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
 int middle = Collections.binarySearch(currProjections,
   new WeightedThing<Vector>(projection.get(i)));
 if (middle < 0) {
  middle = -(middle + 1);
  if (currProjections.get(j).getValue() == null) {
   continue;
  candidates.add(currProjections.get(j).getValue());
  Lists.newArrayListWithCapacity(candidates.size() + pendingAdditions.size());
for (Vector candidate : Iterables.concat(candidates, pendingAdditions)) {
 top.add(new WeightedThing<>(candidate, distanceMeasure.distance(candidate, query)));

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

@Override
 protected Vector computeNext() {
  do {
   if (!data.hasNext()) {
    return endOfData();
   }
   WeightedThing<Vector> next = data.next();
   if (next.getValue() != null) {
    return next.getValue();
   }
  } while (true);
 }
};

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

Vector projection = basisMatrix.times(pending);
for (int i = 0; i < numProjections; ++i) {
 scalarProjections.get(i).add(new WeightedThing<Vector>(pending, projection.get(i)));
List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
for (WeightedThing<Vector> v : currProjections) {
 if (v.getValue() == null) {
  v.setWeight(Double.POSITIVE_INFINITY);

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

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

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

List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
 int middle = Collections.binarySearch(currProjections,
   new WeightedThing<Vector>(projection.get(i)));
 if (middle < 0) {
  middle = -(middle + 1);
  if (currProjections.get(j).getValue() == null) {
   continue;
  candidates.add(currProjections.get(j).getValue());
  Lists.newArrayListWithCapacity(candidates.size() + pendingAdditions.size());
for (Vector candidate : Iterables.concat(candidates, pendingAdditions)) {
 top.add(new WeightedThing<Vector>(candidate, distanceMeasure.distance(candidate, query)));

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

@Override
 protected Vector computeNext() {
  do {
   if (!data.hasNext()) {
    return endOfData();
   }
   WeightedThing<Vector> next = data.next();
   if (next.getValue() != null) {
    return next.getValue();
   }
  } while (true);
 }
};

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

Vector projection = basisMatrix.times(pending);
for (int i = 0; i < numProjections; ++i) {
 scalarProjections.get(i).add(new WeightedThing<Vector>(pending, projection.get(i)));
List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
for (WeightedThing<Vector> v : currProjections) {
 if (v.getValue() == null) {
  v.setWeight(Double.POSITIVE_INFINITY);

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

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

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

List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
 int middle = Collections.binarySearch(currProjections,
   new WeightedThing<Vector>(projection.get(i)));
 if (middle < 0) {
  middle = -(middle + 1);
  if (currProjections.get(j).getValue() == null) {
   continue;
  candidates.add(currProjections.get(j).getValue());
  Lists.newArrayListWithCapacity(candidates.size() + pendingAdditions.size());
for (Vector candidate : Iterables.concat(candidates, pendingAdditions)) {
 top.add(new WeightedThing<Vector>(candidate, distanceMeasure.distance(candidate, query)));

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

@Override
 protected Vector computeNext() {
  do {
   if (!data.hasNext()) {
    return endOfData();
   }
   WeightedThing<Vector> next = data.next();
   if (next.getValue() != null) {
    return next.getValue();
   }
  } while (true);
 }
};

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

Vector projection = basisMatrix.times(pending);
for (int i = 0; i < numProjections; ++i) {
 scalarProjections.get(i).add(new WeightedThing<>(pending, projection.get(i)));
List<WeightedThing<Vector>> currProjections = scalarProjections.get(i);
for (WeightedThing<Vector> v : currProjections) {
 if (v.getValue() == null) {
  v.setWeight(Double.POSITIVE_INFINITY);

相关文章

微信公众号

最新文章

更多