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); } }
protected static WeightedThing<Vector> removeHash(WeightedThing<Vector> input) { return new WeightedThing<Vector>(((HashedVector) input.getValue()).getVector(), input.getWeight()); }
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)));
@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; } }
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);
protected static WeightedThing<Vector> removeHash(WeightedThing<Vector> input) { return new WeightedThing<>(((HashedVector) input.getValue()).getVector(), input.getWeight()); }
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)));
@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; } }
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);
protected static WeightedThing<Vector> removeHash(WeightedThing<Vector> input) { return new WeightedThing<Vector>(((HashedVector) input.getValue()).getVector(), input.getWeight()); }
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)));
@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; } }
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);