Skip to content
Snippets Groups Projects
Verified Commit ff598df0 authored by David Procházka's avatar David Procházka
Browse files

ADD: support for distance measure, number of threads is now set externally

parent a3e2ab44
No related branches found
No related tags found
No related merge requests found
......@@ -17,8 +17,8 @@ public class InternalNode extends Node implements Serializable {
private final List<Node> children;
InternalNode(PrecomputedDistances distances, InsertType insertType) {
super(distances, insertType);
InternalNode(PrecomputedDistances distances, InsertType insertType, DistanceMeasure distanceMeasure) {
super(distances, insertType, distanceMeasure);
children = new ArrayList<>();
}
......@@ -31,7 +31,7 @@ public class InternalNode extends Node implements Serializable {
}
public Node getNearestChild(LocalAbstractObject object) {
Map<Node, Float> nodeToObjectDistance = children.stream()
Map<Node, Double> nodeToObjectDistance = children.stream()
.collect(Collectors.toMap(Function.identity(), node -> node.getDistance(object)));
return Collections.min(nodeToObjectDistance.entrySet(), Map.Entry.comparingByValue()).getKey();
......
......@@ -19,8 +19,8 @@ public class LeafNode extends Node implements Serializable {
private static final long serialVersionUID = 1L;
private LocalBucket bucket;
LeafNode(PrecomputedDistances distances, LocalBucket bucket, InsertType insertType) throws BucketStorageException {
super(distances, insertType);
LeafNode(PrecomputedDistances distances, LocalBucket bucket, InsertType insertType, DistanceMeasure distanceMeasure) throws BucketStorageException {
super(distances, insertType, distanceMeasure);
this.bucket = bucket;
this.bucket.addObjects(distances.getObjects());
......
package mhtree;
import cz.muni.fi.disa.similarityoperators.cover.AbstractRepresentation.PrecomputedDistances;
import messif.algorithms.Algorithm;
import messif.buckets.BucketDispatcher;
import messif.buckets.BucketErrorCode;
......@@ -36,20 +35,20 @@ public class MHTree extends Algorithm implements Serializable {
"arity",
"number of threads used in precomputing distances",
"insert type",
"distance measure",
"storage class for buckets",
"storage class parameters"
})
public MHTree(List<LocalAbstractObject> objects, int leafCapacity, int arity, int numberOfThreads, InsertType insertType, Class<? extends LocalBucket> defaultBucketClass, Map<String, Object> bucketClassParams) throws BucketStorageException {
public MHTree(List<LocalAbstractObject> objects, int leafCapacity, int arity, InsertType insertType, DistanceMeasure distanceMeasure, Class<? extends LocalBucket> defaultBucketClass, Map<String, Object> bucketClassParams) throws BucketStorageException {
super("MH-Tree");
this.leafCapacity = leafCapacity;
this.arity = arity;
this.insertType = insertType;
bucketDispatcher = new BucketDispatcher(Integer.MAX_VALUE, Long.MAX_VALUE, leafCapacity, 0, false, defaultBucketClass, bucketClassParams);
PrecomputedDistances.COMPUTATION_THREADS = numberOfThreads;
bucketDispatcher = new BucketDispatcher(Integer.MAX_VALUE, Long.MAX_VALUE, leafCapacity, 0, false, defaultBucketClass, bucketClassParams);
root = new BuildTree(objects, leafCapacity, arity, insertType, bucketDispatcher).getRoot();
root = new BuildTree(objects, leafCapacity, arity, insertType, distanceMeasure, bucketDispatcher).getRoot();
}
public void approxKNN(ApproxKNNQueryOperation operation) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment