Skip to content

Commit 05bcc10

Browse files
committed
line length tweaks
1 parent e3fe655 commit 05bcc10

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/aspire/operators/wemd.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
Wavelet-based approximate Earthmover's distance (EMD) for n-dimensional signals.
33
44
This code is based on the following paper:
5-
Sameer Shirdhonkar and David W. Jacobs. "Approximate earth mover’s distance in linear time." 2008 IEEE Conference on Computer Vision and Pattern Recognition (CVPR).
5+
Sameer Shirdhonkar and David W. Jacobs.
6+
"Approximate earth mover’s distance in linear time."
7+
2008 IEEE Conference on Computer Vision and Pattern Recognition (CVPR).
68
7-
More details are available in their technical report: CAR-TR-1025 CS-TR-4908 UMIACS-TR-2008-06.
9+
More details are available in their technical report:
10+
CAR-TR-1025 CS-TR-4908 UMIACS-TR-2008-06.
811
"""
912

1013
import numpy as np
@@ -14,8 +17,9 @@
1417
def wemd_embed(arr, wavelet, level):
1518
"""
1619
This function computes an embedding of Numpy arrays such that
17-
for non-negative arrays that sum to one, the L1 distance between the resulting embeddings
18-
is strongly equivalent to the Earthmover distance of the arrays.
20+
for non-negative arrays that sum to one, the L1 distance between the
21+
resulting embeddings is strongly equivalent to the Earthmover distance
22+
of the arrays.
1923
2024
:param arr: Numpy array
2125
:param level: Decomposition level of the wavelets
@@ -43,7 +47,8 @@ def wemd_embed(arr, wavelet, level):
4347

4448
def wemd_norm(arr, wavelet, level):
4549
"""
46-
Wavelet-based norm used to approximate the Earthmover's distance between mass distributions specified as Numpy arrays (typically images or volumes).
50+
Wavelet-based norm used to approximate the Earthmover's distance between
51+
mass distributions specified as Numpy arrays (typically images or volumes).
4752
4853
:param arr: Numpy array of the difference between the two mass distributions.
4954
:param level: Decomposition level of the wavelets
@@ -53,5 +58,6 @@ def wemd_norm(arr, wavelet, level):
5358
See https://pywavelets.readthedocs.io/en/latest/ref/wavelets.html#built-in-wavelets-wavelist
5459
:return: Approximated Earthmover's Distance
5560
"""
61+
5662
coefs = wemd_embed(arr, wavelet, level)
5763
return np.linalg.norm(coefs, ord=1)

tests/test_wemd.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,26 @@ def _is_monotone(seq):
2323

2424

2525
class WEMDTestCase(TestCase):
26-
"""Test that the WEMD distance between smoothed disks of various radii, angles and distances is monotone in the Euclidean distance of their centers.
27-
Note that this monotonicity isn't strictly required by the theory, but holds empirically."""
26+
"""
27+
Test that the WEMD distance between smoothed disks of various radii,
28+
angles and distances is monotone in the Euclidean distance of their centers.
29+
Note that this monotonicity isn't strictly required by the theory,
30+
but holds empirically.
31+
"""
2832

2933
def test_wemd_norm(self):
3034
WIDTH = 64
3135
HEIGHT = 64
3236
CENTER_X = WIDTH // 2
3337
CENTER_Y = HEIGHT // 2
34-
LEVEL = (
35-
int(ceil(log2(max(WIDTH, HEIGHT)))) + 1
36-
) # A rule of thumb for the wavelet level is to take the log2 of the side length.
38+
# A rule of thumb for the wavelet level is to take
39+
# the log2 of the side length.
40+
LEVEL = int(ceil(log2(max(WIDTH, HEIGHT)))) + 1
3741
WAVELET = "coif3"
3842
warnings.filterwarnings(
3943
"ignore",
40-
message="Level value of .* is too high: all coefficients will experience boundary effects.",
44+
message="Level value of .* is too high:"
45+
" all coefficients will experience boundary effects.",
4146
)
4247
for radius in [1, 2, 3, 4, 5, 6, 7]: # Just some random radii
4348
for angle in [

0 commit comments

Comments
 (0)