info.debatty.spark.knngraphs.builder.LSHSuperBit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spark-knn-graphs Show documentation
Show all versions of spark-knn-graphs Show documentation
Spark algorithms for building k-nn graphs
package info.debatty.spark.knngraphs.builder;
import info.debatty.java.graphs.Node;
import java.util.ArrayList;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.function.PairFlatMapFunction;
import scala.Tuple2;
/**
*
* @author tibo
*/
abstract class LSHSuperBit extends AbstractPartitioningBuilder {
info.debatty.java.lsh.LSHSuperBit lsh;
protected int dim;
public void setDim(int dim) {
this.dim = dim;
}
@Override
protected JavaPairRDD> _binNodes(JavaRDD> nodes) throws Exception {
lsh = new info.debatty.java.lsh.LSHSuperBit(stages, buckets, this.dim);
return nodes.flatMapToPair(
new PairFlatMapFunction, Integer, Node>() {
public Iterable>> call(Node n) throws Exception {
ArrayList>> r = new ArrayList>>();
int[] hash = hash(n.value);
for (int v : hash) {
r.add(new Tuple2>(v, n));
}
return r;
}
});
}
abstract int[] hash(T node_value);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy