Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucas Miranda
deepOF
Commits
5b68125c
Commit
5b68125c
authored
May 18, 2021
by
lucas_miranda
Browse files
Replaced for loop with vectorised mapping on ClusterOverlap regularization layer
parent
0958d797
Changes
1
Hide whitespace changes
Inline
Side-by-side
deepof/model_utils.py
View file @
5b68125c
...
...
@@ -39,7 +39,7 @@ def compute_shannon_entropy(tensor):
@
tf
.
function
def
get_k_nearest_neighbors
(
tensor
,
k
,
index
):
"""Retrieve indices of the k nearest neighbors in tensor to the vector with the specified index"""
query
=
tf
.
slice
(
tensor
,
index
,
1
)
query
=
tensor
[
index
]
distances
=
tf
.
norm
(
tensor
-
query
,
axis
=
1
)
max_distance
=
tf
.
sort
(
distances
)[
k
]
neighbourhood_mask
=
distances
<
max_distance
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment