-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from mooscaliaproject/fix/crowding_distance_w_…
…dups CHORE: test for edge case
- Loading branch information
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import numpy as np | ||
|
||
try: | ||
from pymoode.cython.pruning_cd import calc_pcd | ||
|
||
do_test = True | ||
except ModuleNotFoundError: | ||
print('Module not found for Cython pruning_cd') | ||
do_test = False | ||
calc_pcd = None | ||
|
||
|
||
def test_edgecase_pcd(): | ||
X = np.array([ | ||
[0.44107087, -0.39376368, -0.35701034], | ||
[0.43660261, -0.38772938, -0.35929946], | ||
[0.44107087, -0.39376368, -0.35701034], | ||
[0.43791779, -0.3895055, -0.35862569], | ||
[0.44053895, -0.39304534, -0.35728285], | ||
[0.43786142, -0.38942938, -0.35865456], | ||
[0.43964992, -0.39184472, -0.3577383], | ||
[0.43999904, -0.3923162, -0.35755945], | ||
[0.43447003, -0.38484936, -0.36039199], | ||
[0.43631468, -0.38734053, -0.35944697], | ||
[0.43207851, -0.38161963, -0.36161718], | ||
[0.43174801, -0.3811733, -0.3617865], | ||
[0.4373249, -0.38870481, -0.35892943], | ||
[0.43829797, -0.39001893, -0.35843091], | ||
[0.43336635, -0.38335885, -0.36095741], | ||
[0.43480479, -0.38530144, -0.36022049], | ||
[0.43306025, -0.38294546, -0.36111423], | ||
[0.4366501, -0.3877935, -0.35927513], | ||
[0.43741487, -0.38882631, -0.35888333], | ||
[0.43853913, -0.39034461, -0.35830737], | ||
[0.43672522, -0.38789495, -0.35923664], | ||
[0.43588172, -0.38675582, -0.35966877], | ||
[0.43909541, -0.39109586, -0.35802238], | ||
[0.4396585, -0.39185631, -0.35773391], | ||
[0.43584245, -0.38670279, -0.35968889], | ||
[0.43348672, -0.3835214, -0.36089575], | ||
[0.43123517, -0.38048072, -0.36204923], | ||
[0.43516766, -0.38579149, -0.36003459], | ||
[0.43546305, -0.38619041, -0.35988326], | ||
[0.43867936, -0.39053399, -0.35823553], | ||
[0.4409444, -0.3935929, -0.35707513], | ||
[0.435545, -0.38630108, -0.35984128], | ||
[0.43851132, -0.39030706, -0.35832161], | ||
[0.43436811, -0.38471171, -0.36044421], | ||
[0.43914191, -0.39115866, -0.35799856], | ||
[0.43708624, -0.38838251, -0.35905169], | ||
[0.4384717, -0.39025355, -0.35834191], | ||
[0.43205424, -0.38158686, -0.36162962], | ||
[0.44088654, -0.39351476, -0.35710477], | ||
[0.43243631, -0.38210284, -0.36143388], | ||
[0.43979464, -0.39204016, -0.35766416], | ||
[0.43381116, -0.38395956, -0.36072954], | ||
[0.43370379, -0.38381456, -0.36078454], | ||
[0.43269153, -0.38244751, -0.36130313], | ||
[0.43924092, -0.39129237, -0.35794784], | ||
[0.43872278, -0.39059263, -0.35821328], | ||
[0.43903785, -0.39101812, -0.35805187], | ||
[0.43411261, -0.38436667, -0.3605751], | ||
[0.43423356, -0.38453, -0.36051314], | ||
[0.44024805, -0.39265249, -0.35743188], | ||
[0.44087024, -0.39349274, -0.35711313], | ||
[0.43305819, -0.38294268, -0.36111529], | ||
]) | ||
res = np.array([ | ||
np.inf, | ||
0.03410153, | ||
np.inf, | ||
0.0443843, | ||
0.06325797, | ||
0.05113217, | ||
0.04245589, | ||
0.04609897, | ||
0.04439749, | ||
0.07329366, | ||
0.03884496, | ||
0.08327485, | ||
0.03341132, | ||
0.05631684, | ||
0.04335893, | ||
0.07092818, | ||
0.03133131, | ||
0.01246547, | ||
0.05454877, | ||
0.01708464, | ||
0.04434333, | ||
0.0480121, | ||
0.01057988, | ||
0.01471335, | ||
0.03423474, | ||
0.03430807, | ||
np.inf, | ||
0.0669258, | ||
0.03836405, | ||
0.01867222, | ||
0.01874031, | ||
0.03857378, | ||
0.00685487, | ||
0.0240425, | ||
0.01479437, | ||
0.06096955, | ||
0.02169136, | ||
0.03360176, | ||
0.00754014, | ||
0.06232631, | ||
0.03462236, | ||
0.04156483, | ||
0.03298651, | ||
0.06322694, | ||
0.05164993, | ||
0.03644734, | ||
0.03788544, | ||
0.04294547, | ||
0.0259765, | ||
0.05489302, | ||
0.03533971, | ||
0.03748806, | ||
]) | ||
|
||
d = calc_pcd(X) | ||
assert np.all(np.isclose(res, d, atol=1e-4)), ( | ||
'Wrong results for crowding distances on edge case' | ||
) |