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
d0e726c7
There was an error fetching the commit references. Please try again later.
Verified
Commit
d0e726c7
authored
4 years ago
by
David Procházka
Browse files
Options
Downloads
Patches
Plain Diff
ADD: more explicit tree building steps
parent
00b7b116
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mhtree/BuildTree.java
+44
-46
44 additions, 46 deletions
src/mhtree/BuildTree.java
with
44 additions
and
46 deletions
src/mhtree/BuildTree.java
+
44
−
46
View file @
d0e726c7
...
...
@@ -30,6 +30,9 @@ class BuildTree {
BuildTree
(
List
<
LocalAbstractObject
>
objects
,
int
leafCapacity
,
int
arity
,
InsertType
insertType
,
DistanceMeasure
distanceMeasure
,
BucketDispatcher
bucketDispatcher
)
throws
BucketStorageException
{
this
.
arity
=
arity
;
this
.
leafCapacity
=
leafCapacity
;
this
.
insertType
=
insertType
;
this
.
distanceMeasure
=
distanceMeasure
;
this
.
bucketDispatcher
=
bucketDispatcher
;
nodes
=
new
Node
[
objects
.
size
()
/
leafCapacity
];
...
...
@@ -39,9 +42,15 @@ class BuildTree {
objectDistances
=
new
PrecomputedDistances
(
objects
);
nodeDistances
=
new
float
[
nodes
.
length
][
nodes
.
length
];
this
.
insertType
=
insertType
;
this
.
distanceMeasure
=
distanceMeasure
;
this
.
bucketDispatcher
=
bucketDispatcher
;
// Every object is stored in the root
if
(
objectDistances
.
getObjectCount
()
<
leafCapacity
)
{
root
=
new
LeafNode
(
objectDistances
,
bucketDispatcher
.
createBucket
(),
insertType
,
distanceMeasure
);
return
;
}
createLeafNodes
();
precomputeNodeDistances
();
buildTree
();
}
...
...
@@ -50,50 +59,41 @@ class BuildTree {
return
root
;
}
private
void
buildTree
()
throws
BucketStorageException
{
if
(!
initHullPoints
())
return
;
precomputeHullDistances
();
private
void
buildTree
()
{
while
(
validNodeIndices
.
cardinality
()
!=
1
)
{
BitSet
notProcessedIndices
=
(
BitSet
)
validNodeIndices
.
clone
();
BitSet
notProcessed
Node
Indices
=
(
BitSet
)
validNodeIndices
.
clone
();
while
(!
notProcessedIndices
.
isEmpty
())
{
if
(
notProcessedIndices
.
cardinality
()
<
arity
)
{
List
<
Integer
>
restOfTh
eIndices
=
new
ArrayList
<>();
while
(!
notProcessed
Node
Indices
.
isEmpty
())
{
if
(
notProcessed
Node
Indices
.
cardinality
()
<
arity
)
{
List
<
Integer
>
nod
eIndices
=
new
ArrayList
<>();
notProcessedIndices
.
stream
().
forEach
(
restOfTh
eIndices:
:
add
);
notProcessed
Node
Indices
.
stream
().
forEach
(
nod
eIndices:
:
add
);
int
mainIndex
=
restOfTh
eIndices
.
remove
(
0
);
merge
Hull
s
(
mainIndex
,
restOfTh
eIndices
);
int
main
Node
Index
=
nod
eIndices
.
remove
(
0
);
merge
Node
s
(
main
Node
Index
,
nod
eIndices
);
break
;
}
int
furthestNodeIndex
=
getFurthestIndex
(
nodeDistances
,
notProcessedIndices
);
notProcessedIndices
.
clear
(
furthestNodeIndex
);
int
furthestNodeIndex
=
getFurthestIndex
(
nodeDistances
,
notProcessed
Node
Indices
);
notProcessed
Node
Indices
.
clear
(
furthestNodeIndex
);
List
<
Integer
>
nnIndices
=
new
ArrayList
<>();
List
<
Integer
>
nn
Node
Indices
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
arity
-
1
;
i
++)
{
int
index
=
objectDistances
.
minDistInArrayExceptIdx
(
nodeDistances
[
furthestNodeIndex
],
notProcessedIndices
,
furthestNodeIndex
);
notProcessedIndices
.
clear
(
index
);
nnIndices
.
add
(
index
);
int
index
=
objectDistances
.
minDistInArrayExceptIdx
(
nodeDistances
[
furthestNodeIndex
],
notProcessed
Node
Indices
,
furthestNodeIndex
);
notProcessed
Node
Indices
.
clear
(
index
);
nn
Node
Indices
.
add
(
index
);
}
merge
Hull
s
(
furthestNodeIndex
,
nnIndices
);
merge
Node
s
(
furthestNodeIndex
,
nn
Node
Indices
);
}
}
root
=
nodes
[
validNodeIndices
.
nextSetBit
(
0
)];
}
private
boolean
initHullPoints
()
throws
BucketStorageException
{
if
(
objectDistances
.
getObjectCount
()
<
leafCapacity
)
{
root
=
new
LeafNode
(
objectDistances
,
bucketDispatcher
.
createBucket
(),
insertType
,
distanceMeasure
);
return
false
;
}
private
void
createLeafNodes
()
throws
BucketStorageException
{
BitSet
notProcessedObjectIndices
=
new
BitSet
(
objectDistances
.
getObjectCount
());
notProcessedObjectIndices
.
set
(
0
,
objectDistances
.
getObjectCount
());
...
...
@@ -101,7 +101,7 @@ class BuildTree {
if
(
notProcessedObjectIndices
.
cardinality
()
<
leafCapacity
)
{
for
(
int
i
=
notProcessedObjectIndices
.
nextSetBit
(
0
);
i
>=
0
;
i
=
notProcessedObjectIndices
.
nextSetBit
(
i
+
1
))
addObjectToClosestNode
(
i
);
return
true
;
return
;
}
List
<
LocalAbstractObject
>
objects
=
new
ArrayList
<>();
...
...
@@ -116,15 +116,13 @@ class BuildTree {
nodes
[
nodeIndex
]
=
new
LeafNode
(
objectDistances
.
getSubset
(
objects
),
bucketDispatcher
.
createBucket
(),
insertType
,
distanceMeasure
);
}
return
true
;
}
private
void
addObjectToClosestNode
(
int
objectIndex
)
throws
BucketStorageException
{
LocalAbstractObject
object
=
objectDistances
.
getObject
(
objectIndex
);
Function
<
Node
,
Float
>
getMinHullObjectDistance
=
node
->
node
.
getHullObjects
().
stream
()
.
map
(
obj
->
obj
.
getDistance
(
object
)
)
.
map
(
obj
ect:
:
getDistance
)
.
reduce
(
Float
.
MAX_VALUE
,
Math:
:
min
);
Map
<
Node
,
Float
>
nodeToObjectDistance
=
Arrays
.
stream
(
nodes
)
...
...
@@ -177,7 +175,7 @@ class BuildTree {
}).
collect
(
Collectors
.
toList
());
}
private
void
precompute
Hull
Distances
()
{
private
void
precompute
Node
Distances
()
{
for
(
int
i
=
0
;
i
<
nodes
.
length
;
i
++)
{
for
(
int
j
=
i
+
1
;
j
<
nodes
.
length
;
j
++)
{
float
minDistance
=
Float
.
MAX_VALUE
;
...
...
@@ -195,11 +193,11 @@ class BuildTree {
}
}
private
void
merge
Hull
s
(
int
main
Hull
Index
,
List
<
Integer
>
otherHull
Indices
)
{
if
(
otherHull
Indices
.
size
()
==
0
)
return
;
private
void
merge
Node
s
(
int
main
Node
Index
,
List
<
Integer
>
node
Indices
)
{
if
(
node
Indices
.
size
()
==
0
)
return
;
List
<
Integer
>
indices
=
new
ArrayList
<>(
otherHull
Indices
);
indices
.
add
(
main
Hull
Index
);
List
<
Integer
>
indices
=
new
ArrayList
<>(
node
Indices
);
indices
.
add
(
main
Node
Index
);
List
<
Node
>
nodes
=
indices
.
stream
().
map
(
i
->
this
.
nodes
[
i
]).
collect
(
Collectors
.
toList
());
...
...
@@ -207,27 +205,27 @@ class BuildTree {
nodes
.
forEach
(
node
->
node
.
setParent
(
parent
));
parent
.
addChildren
(
nodes
);
this
.
nodes
[
main
Hull
Index
]
=
parent
;
this
.
nodes
[
main
Node
Index
]
=
parent
;
for
(
int
i
:
otherHull
Indices
)
{
for
(
int
i
:
node
Indices
)
{
validNodeIndices
.
clear
(
i
);
this
.
nodes
[
i
]
=
null
;
}
update
Hull
Distances
(
main
Hull
Index
,
otherHull
Indices
);
update
Node
Distances
(
main
Node
Index
,
node
Indices
);
}
private
void
update
Hull
Distances
(
int
base
Hull
Index
,
List
<
Integer
>
otherHull
Indices
)
{
if
(
otherHull
Indices
.
size
()
==
0
)
return
;
private
void
update
Node
Distances
(
int
base
Node
Index
,
List
<
Integer
>
node
Indices
)
{
if
(
node
Indices
.
size
()
==
0
)
return
;
validNodeIndices
.
stream
().
forEach
(
i
->
{
float
minDistance
=
nodeDistances
[
base
Hull
Index
][
i
];
float
minDistance
=
nodeDistances
[
base
Node
Index
][
i
];
for
(
int
index
:
otherHull
Indices
)
for
(
int
index
:
node
Indices
)
minDistance
=
Math
.
min
(
minDistance
,
nodeDistances
[
index
][
i
]);
nodeDistances
[
base
Hull
Index
][
i
]
=
minDistance
;
nodeDistances
[
i
][
base
Hull
Index
]
=
minDistance
;
nodeDistances
[
base
Node
Index
][
i
]
=
minDistance
;
nodeDistances
[
i
][
base
Node
Index
]
=
minDistance
;
});
}
}
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