From 6e342a9b82ea1d7b9ffd82534c7f8eaec6a45252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Proch=C3=A1zka?= <david@prochazka.dev> Date: Tue, 4 May 2021 21:04:10 +0200 Subject: [PATCH] FIX: renamed approximate state, node degree -> arity --- ...ApproxState.java => ApproximateState.java} | 20 +++++------ src/mhtree/MHTree.java | 34 ++++++++----------- src/mhtree/benchmarking/SearchState.java | 6 ++-- 3 files changed, 28 insertions(+), 32 deletions(-) rename src/mhtree/{ApproxState.java => ApproximateState.java} (59%) diff --git a/src/mhtree/ApproxState.java b/src/mhtree/ApproximateState.java similarity index 59% rename from src/mhtree/ApproxState.java rename to src/mhtree/ApproximateState.java index cb10095..c9e6f4d 100644 --- a/src/mhtree/ApproxState.java +++ b/src/mhtree/ApproximateState.java @@ -2,23 +2,23 @@ package mhtree; import messif.operations.Approximate; -public class ApproxState { +public class ApproximateState { public int limit; protected int objectsChecked; protected int bucketsVisited; - protected ApproxState(int limit) { + protected ApproximateState(int limit) { this.limit = limit; } - public static ApproxState create(Approximate limits, MHTree mhTree) { + public static ApproximateState create(Approximate limits, MHTree mhTree) { switch (limits.getLocalSearchType()) { case PERCENTAGE: - return new ApproxStateObjects(Math.round((float) mhTree.getObjectCount() * (float) limits.getLocalSearchParam() / 100f)); + return new ApproximateStateObjects(Math.round((float) mhTree.getObjectCount() * (float) limits.getLocalSearchParam() / 100f)); case ABS_OBJ_COUNT: - return new ApproxStateObjects(limits.getLocalSearchParam()); + return new ApproximateStateObjects(limits.getLocalSearchParam()); case DATA_PARTITIONS: - return new ApproxStateBuckets(limits.getLocalSearchParam()); + return new ApproximateStateBuckets(limits.getLocalSearchParam()); default: throw new IllegalArgumentException("Unsupported approximation type: " + limits.getLocalSearchType()); } @@ -33,8 +33,8 @@ public class ApproxState { throw new IllegalStateException("ApproxState.stop must be implemented and must not be called!"); } - private static class ApproxStateBuckets extends ApproxState { - private ApproxStateBuckets(int limit) { + private static class ApproximateStateBuckets extends ApproximateState { + private ApproximateStateBuckets(int limit) { super(limit); } @@ -44,8 +44,8 @@ public class ApproxState { } } - private static class ApproxStateObjects extends ApproxState { - private ApproxStateObjects(int limit) { + private static class ApproximateStateObjects extends ApproximateState { + private ApproximateStateObjects(int limit) { super(limit); } diff --git a/src/mhtree/MHTree.java b/src/mhtree/MHTree.java index 8ed418d..ae8d9b3 100644 --- a/src/mhtree/MHTree.java +++ b/src/mhtree/MHTree.java @@ -38,9 +38,9 @@ public class MHTree extends Algorithm implements Serializable { private final int leafCapacity; /** - * Maximal degree of an internal node. + * Arity */ - private final int nodeDegree; + private final int arity; private final Node root; private final InsertType insertType; private final ObjectToNodeDistance objectToNodeDistance; @@ -53,7 +53,7 @@ public class MHTree extends Algorithm implements Serializable { super("MH-Tree"); leafCapacity = builder.leafCapacity; - nodeDegree = builder.nodeDegree; + arity = builder.nodeDegree; bucketDispatcher = builder.bucketDispatcher; insertType = builder.insertType; @@ -70,7 +70,7 @@ public class MHTree extends Algorithm implements Serializable { SearchState searchState = (SearchState) operation.suppData; while (!searchState.queue.isEmpty()) { - if (searchState.approxState != null && searchState.approxState.stop()) { + if (searchState.approximateState != null && searchState.approximateState.stop()) { break; } @@ -83,8 +83,8 @@ public class MHTree extends Algorithm implements Serializable { } } - if (searchState.approxState != null) { - searchState.approxState.update((LeafNode) node); + if (searchState.approximateState != null) { + searchState.approximateState.update((LeafNode) node); } } else { for (Node child : ((InternalNode) node).getChildren()) { @@ -96,14 +96,14 @@ public class MHTree extends Algorithm implements Serializable { operation.endOperation(); } - public void kNNSearch(KNNQueryOperation operation, ApproxState approxState) { + public void kNNSearch(KNNQueryOperation operation, ApproximateState approximateState) { LocalAbstractObject queryObject = operation.getQueryObject(); PriorityQueue<ObjectToNodeDistanceRank> queue = new PriorityQueue<>(); queue.add(new ObjectToNodeDistanceRank(queryObject, root, operation.getK())); while (!queue.isEmpty()) { - if (approxState != null && approxState.stop()) { + if (approximateState != null && approximateState.stop()) { break; } @@ -116,8 +116,8 @@ public class MHTree extends Algorithm implements Serializable { } } - if (approxState != null) { - approxState.update((LeafNode) node); + if (approximateState != null) { + approximateState.update((LeafNode) node); } } else { for (Node child : ((InternalNode) node).getChildren()) { @@ -188,7 +188,7 @@ public class MHTree extends Algorithm implements Serializable { .summaryStatistics(); System.out.println("Leaf object capacity: " + leafCapacity); - System.out.println("Node degree: " + nodeDegree); + System.out.println("Node degree: " + arity); System.out.println("Object to node distance measurement: " + objectToNodeDistance); System.out.println("Insert type: " + insertType); @@ -214,7 +214,7 @@ public class MHTree extends Algorithm implements Serializable { public String toString() { return "MHTree{" + "leafCapacity=" + leafCapacity + - ", nodeDegree=" + nodeDegree + + ", nodeDegree=" + arity + ", insertType=" + insertType + ", objectToNodeDistance=" + objectToNodeDistance + '}'; @@ -290,7 +290,7 @@ public class MHTree extends Algorithm implements Serializable { this.insertType = InsertType.GREEDY; this.objectToNodeDistance = ObjectToNodeDistance.NEAREST; this.bucketDispatcher = new BucketDispatcher(Integer.MAX_VALUE, Long.MAX_VALUE, leafCapacity, 0, false, MemoryStorageBucket.class, null); - this.mergeType = MergeType.REPRESENTATION_BASED; + this.mergeType = MergeType.HULL_BASED; } public Builder insertType(InsertType insertType) { @@ -388,7 +388,7 @@ public class MHTree extends Algorithm implements Serializable { List<Integer> objectIndices = new ArrayList<>(leafCapacity); - // Select a base object + // Select the furthest object (the outlier) int furthestIndex = Utils.maxDistanceIndex(objectDistances.getDistances(), notProcessedObjectIndices); notProcessedObjectIndices.clear(furthestIndex); objectIndices.add(furthestIndex); @@ -531,16 +531,12 @@ public class MHTree extends Algorithm implements Serializable { }); } - private int getClosestIndex(int nodeIndex, BitSet notUsedIndexes) { - return Utils.minDistanceIndex(distances[nodeIndex], notUsedIndexes); - } - private int getFurthestIndex(BitSet validIndices) { return Utils.maxDistanceIndex(distances, validIndices); } /** - * Computes distances between nodes in {@code nodes}, storing the result in {@code distances}. + * Computes distances between nodes in {@code nodes}, stores the result in {@code distances}. */ private void computeNodeDistances() { for (int i = 0; i < nodes.length; i++) { diff --git a/src/mhtree/benchmarking/SearchState.java b/src/mhtree/benchmarking/SearchState.java index eccc121..6ff8c6f 100644 --- a/src/mhtree/benchmarking/SearchState.java +++ b/src/mhtree/benchmarking/SearchState.java @@ -2,7 +2,7 @@ package mhtree.benchmarking; import messif.objects.LocalAbstractObject; import messif.operations.query.ApproxKNNQueryOperation; -import mhtree.ApproxState; +import mhtree.ApproximateState; import mhtree.MHTree; import mhtree.ObjectToNodeDistanceRank; @@ -11,14 +11,14 @@ import java.util.PriorityQueue; public class SearchState { public PriorityQueue<ObjectToNodeDistanceRank> queue; public LocalAbstractObject queryObject; - public ApproxState approxState; + public ApproximateState approximateState; public double recall; public SearchState(MHTree tree, ApproxKNNQueryOperation operation) { this.queue = new PriorityQueue<>(); this.queue.add(new ObjectToNodeDistanceRank(operation.getQueryObject(), tree.getRoot(), operation.getK())); this.queryObject = operation.getQueryObject(); - this.approxState = ApproxState.create(operation, tree); + this.approximateState = ApproximateState.create(operation, tree); this.recall = 0d; } } -- GitLab