Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MH-Tree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
disa
public
Hulls
MH-Tree
Commits
390d7d5a
There was an error fetching the commit references. Please try again later.
Verified
Commit
390d7d5a
authored
4 years ago
by
David Procházka
Browse files
Options
Downloads
Patches
Plain Diff
ADD: node to node distance
parent
d2e933bd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mhtree/BuildTree.java
+20
-14
20 additions, 14 deletions
src/mhtree/BuildTree.java
src/mhtree/MHTree.java
+5
-2
5 additions, 2 deletions
src/mhtree/MHTree.java
src/mhtree/NodeToNodeDistance.java
+6
-0
6 additions, 0 deletions
src/mhtree/NodeToNodeDistance.java
with
31 additions
and
16 deletions
src/mhtree/BuildTree.java
+
20
−
14
View file @
390d7d5a
...
...
@@ -6,6 +6,7 @@ import messif.buckets.BucketStorageException;
import
messif.objects.LocalAbstractObject
;
import
java.util.*
;
import
java.util.function.BiFunction
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
...
...
@@ -24,16 +25,21 @@ class BuildTree {
private
final
InsertType
insertType
;
private
final
ObjectToNodeDistance
objectToNodeDistance
;
private
final
BucketDispatcher
bucketDispatcher
;
private
final
BiFunction
<
Float
,
Float
,
Float
>
distanceSelector
;
private
Node
root
;
BuildTree
(
List
<
LocalAbstractObject
>
objects
,
int
leafCapacity
,
int
arity
,
InsertType
insertType
,
ObjectToNodeDistance
objectToNodeDistance
,
BucketDispatcher
bucketDispatcher
)
throws
BucketStorageException
{
BuildTree
(
List
<
LocalAbstractObject
>
objects
,
int
leafCapacity
,
int
arity
,
InsertType
insertType
,
ObjectToNodeDistance
objectToNodeDistance
,
NodeToNodeDistance
nodeToNodeDistance
,
BucketDispatcher
bucketDispatcher
)
throws
BucketStorageException
{
this
.
arity
=
arity
;
this
.
leafCapacity
=
leafCapacity
;
this
.
insertType
=
insertType
;
this
.
objectToNodeDistance
=
objectToNodeDistance
;
this
.
bucketDispatcher
=
bucketDispatcher
;
// Set distance selector function for two hull objects
boolean
selectNearest
=
nodeToNodeDistance
==
NodeToNodeDistance
.
NEAREST_HULL_OBJECTS
;
distanceSelector
=
selectNearest
?
Math:
:
min
:
Math:
:
max
;
nodes
=
new
Node
[
objects
.
size
()
/
leafCapacity
];
validNodeIndices
=
new
BitSet
(
nodes
.
length
);
...
...
@@ -50,7 +56,7 @@ class BuildTree {
createLeafNodes
();
precomputeNodeDistances
();
precompute
Leaf
NodeDistances
();
buildTree
();
}
...
...
@@ -175,20 +181,20 @@ class BuildTree {
}).
collect
(
Collectors
.
toSet
());
}
private
void
precomputeNodeDistances
()
{
private
void
precompute
Leaf
NodeDistances
()
{
for
(
int
i
=
0
;
i
<
nodes
.
length
;
i
++)
{
for
(
int
j
=
i
+
1
;
j
<
nodes
.
length
;
j
++)
{
float
minD
istance
=
Float
.
MAX_VALUE
;
float
d
istance
=
Float
.
MAX_VALUE
;
for
(
LocalAbstractObject
first
Poin
t
:
nodes
[
i
].
getObjects
())
for
(
LocalAbstractObject
second
Poin
t
:
nodes
[
j
].
getObjects
())
minD
istance
=
Math
.
min
(
minD
istance
,
objectDistances
.
getDistance
(
first
Point
,
secondPoin
t
));
for
(
LocalAbstractObject
first
HullObjec
t
:
nodes
[
i
].
get
Hull
Objects
())
for
(
LocalAbstractObject
second
HullObjec
t
:
nodes
[
j
].
get
Hull
Objects
())
d
istance
=
distanceSelector
.
apply
(
d
istance
,
objectDistances
.
getDistance
(
first
HullObject
,
secondHullObjec
t
));
if
(
minD
istance
==
0
f
)
if
(
d
istance
==
0
f
)
throw
new
RuntimeException
(
"Zero distance between "
+
nodes
[
i
].
toString
()
+
" and "
+
nodes
[
j
].
toString
());
nodeDistances
[
i
][
j
]
=
minD
istance
;
nodeDistances
[
j
][
i
]
=
minD
istance
;
nodeDistances
[
i
][
j
]
=
d
istance
;
nodeDistances
[
j
][
i
]
=
d
istance
;
}
}
}
...
...
@@ -219,13 +225,13 @@ class BuildTree {
if
(
nodeIndices
.
size
()
==
0
)
return
;
validNodeIndices
.
stream
().
forEach
(
i
->
{
float
minD
istance
=
nodeDistances
[
baseNodeIndex
][
i
];
float
d
istance
=
nodeDistances
[
baseNodeIndex
][
i
];
for
(
int
index
:
nodeIndices
)
minD
istance
=
Math
.
min
(
minD
istance
,
nodeDistances
[
index
][
i
]);
d
istance
=
distanceSelector
.
apply
(
d
istance
,
nodeDistances
[
index
][
i
]);
nodeDistances
[
baseNodeIndex
][
i
]
=
minD
istance
;
nodeDistances
[
i
][
baseNodeIndex
]
=
minD
istance
;
nodeDistances
[
baseNodeIndex
][
i
]
=
d
istance
;
nodeDistances
[
i
][
baseNodeIndex
]
=
d
istance
;
});
}
}
This diff is collapsed.
Click to expand it.
src/mhtree/MHTree.java
+
5
−
2
View file @
390d7d5a
...
...
@@ -29,6 +29,7 @@ public class MHTree extends Algorithm implements Serializable {
private
final
BucketDispatcher
bucketDispatcher
;
private
final
InsertType
insertType
;
private
final
ObjectToNodeDistance
objectToNodeDistance
;
private
final
NodeToNodeDistance
nodeToNodeDistance
;
private
final
StatisticCounter
statVisitedLeaves
=
StatisticCounter
.
getStatistics
(
"Node.Leaf.Visited"
);
...
...
@@ -42,17 +43,18 @@ public class MHTree extends Algorithm implements Serializable {
"storage class for buckets"
,
"storage class parameters"
})
public
MHTree
(
List
<
LocalAbstractObject
>
objects
,
int
leafCapacity
,
int
arity
,
InsertType
insertType
,
ObjectToNodeDistance
objectToNodeDistance
,
Class
<?
extends
LocalBucket
>
defaultBucketClass
,
Map
<
String
,
Object
>
bucketClassParams
)
throws
BucketStorageException
{
public
MHTree
(
List
<
LocalAbstractObject
>
objects
,
int
leafCapacity
,
int
arity
,
InsertType
insertType
,
ObjectToNodeDistance
objectToNodeDistance
,
NodeToNodeDistance
nodeToNodeDistance
,
Class
<?
extends
LocalBucket
>
defaultBucketClass
,
Map
<
String
,
Object
>
bucketClassParams
)
throws
BucketStorageException
{
super
(
"MH-Tree"
);
this
.
leafCapacity
=
leafCapacity
;
this
.
arity
=
arity
;
this
.
insertType
=
insertType
;
this
.
objectToNodeDistance
=
objectToNodeDistance
;
this
.
nodeToNodeDistance
=
nodeToNodeDistance
;
bucketDispatcher
=
new
BucketDispatcher
(
Integer
.
MAX_VALUE
,
Long
.
MAX_VALUE
,
leafCapacity
,
0
,
false
,
defaultBucketClass
,
bucketClassParams
);
root
=
new
BuildTree
(
objects
,
leafCapacity
,
arity
,
insertType
,
objectToNodeDistance
,
bucketDispatcher
).
getRoot
();
root
=
new
BuildTree
(
objects
,
leafCapacity
,
arity
,
insertType
,
objectToNodeDistance
,
nodeToNodeDistance
,
bucketDispatcher
).
getRoot
();
}
public
void
approxKNN
(
ApproxKNNQueryOperation
operation
,
double
coefficient
)
{
...
...
@@ -175,6 +177,7 @@ public class MHTree extends Algorithm implements Serializable {
", root="
+
root
+
", insertType"
+
insertType
+
", objectToNodeDistance"
+
objectToNodeDistance
+
", nodeToNodeDistance"
+
nodeToNodeDistance
+
'}'
;
}
}
This diff is collapsed.
Click to expand it.
src/mhtree/NodeToNodeDistance.java
0 → 100644
+
6
−
0
View file @
390d7d5a
package
mhtree
;
public
enum
NodeToNodeDistance
{
NEAREST_HULL_OBJECTS
,
FURTHEST_HULL_OBJECTS
,
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment