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
e068eb57
Commit
e068eb57
authored
May 19, 2021
by
lucas_miranda
Browse files
Replaced for loop with vectorised mapping on ClusterOverlap regularization layer
parent
f7772dc7
Pipeline
#101805
passed with stages
in 26 minutes and 8 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/test_model_utils.py
View file @
e068eb57
...
...
@@ -51,14 +51,41 @@ def test_compute_shannon_entropy(tensor):
tensor
=
arrays
(
shape
=
[
100
,
10
],
dtype
=
float
,
unique
=
Fals
e
,
unique
=
Tru
e
,
elements
=
st
.
floats
(
min_value
=
0.0
,
max_value
=
10.0
),
)
),
k
=
st
.
integers
(
min_value
=
5
,
max_value
=
20
),
)
def
test_k_nearest_neighbors
(
tensor
,
k
):
deepof_knn
=
deepof
.
model_utils
.
get_k_nearest_neighbors
(
tensor
,
k
,
0
)
sklearn_knn
=
NearestNeighbors
().
fit
(
tensor
)
assert
np
.
allclose
(
deepof_knn
,
sklearn_knn
.
kneighbors
())
sklearn_knn
=
NearestNeighbors
(
k
).
fit
(
tensor
)
sklearn_knn
=
sklearn_knn
.
kneighbors
(
tensor
[
0
].
reshape
(
1
,
-
1
))[
1
].
flatten
()
assert
np
.
allclose
(
deepof_knn
.
numpy
(),
sorted
(
sklearn_knn
))
@
settings
(
deadline
=
None
,
suppress_health_check
=
[
HealthCheck
.
too_slow
])
@
given
(
tensor
=
arrays
(
shape
=
[
100
,
10
],
dtype
=
float
,
unique
=
True
,
elements
=
st
.
floats
(
min_value
=
0.0
,
max_value
=
10.0
),
),
clusters
=
arrays
(
shape
=
[
100
],
dtype
=
int
,
unique
=
False
,
elements
=
st
.
integers
(
min_value
=
0
,
max_value
=
10
),
),
k
=
st
.
integers
(
min_value
=
5
,
max_value
=
20
),
)
def
test_get_neighbourhood_entropy
(
tensor
,
clusters
,
k
):
neighborhood_entropy
=
deepof
.
model_utils
.
get_neighbourhood_entropy
(
0
,
tensor
,
clusters
,
k
).
numpy
()
assert
isinstance
(
neighborhood_entropy
,
np
.
float32
)
@
settings
(
deadline
=
None
,
suppress_health_check
=
[
HealthCheck
.
too_slow
])
...
...
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