Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
gagolews committed Nov 19, 2024
1 parent 313bb6f commit f756559
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
37 changes: 23 additions & 14 deletions .devel/pytest/test_approx.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
try:
import rpy2
from rpy2.robjects.packages import importr
import rpy2.robjects.numpy2ri
from rpy2.robjects import numpy2ri
from rpy2.robjects import default_converter
#import rpy2.robjects.numpy2ri
#rpy2.robjects.numpy2ri.activate()
stats = importr("stats")
genie = importr("genie")

r_base = importr("base")
lib_loc = r_base.Sys_getenv("R_LIBS_USER")[0]
print(lib_loc)

genie = importr("genie", lib_loc=lib_loc)
except:
rpy2 = None
stats = None
Expand Down Expand Up @@ -93,18 +100,20 @@ def __test_genie_approx(metric='euclidean'):
#assert len(np.unique(res1[res1>=0])) == k

if stats is not None and genie is not None and M == 1 and not (metric in ['cosine', 'maximum']):
t02 = time.time()
res2 = stats.cutree(genie.hclust2(objects=X, d=metric, thresholdGini=g), k)
t12 = time.time()
print("t_r=%.3f" % (t12-t02), end="\t")
res2 = np.array(res2, np.intp)
assert len(np.unique(res2)) == k

ari = genieclust.compare_partitions.adjusted_rand_score(res1, res2)
print("ARI=%.3f" % ari, end="\t")
assert ari>1.0-1e-12

print("t_rel=%.3f" % ((t11-t01)/(t12-t02),), end="\t")
np_cv_rules = default_converter + numpy2ri.converter
with np_cv_rules.context():
t02 = time.time()
res2 = stats.cutree(genie.hclust2(objects=X, d=metric, thresholdGini=g), k)
t12 = time.time()
print("t_r=%.3f" % (t12-t02), end="\t")
res2 = np.array(res2, np.intp)
assert len(np.unique(res2)) == k

ari = genieclust.compare_partitions.adjusted_rand_score(res1, res2)
print("ARI=%.3f" % ari, end="\t")
assert ari>1.0-1e-12

print("t_rel=%.3f" % ((t11-t01)/(t12-t02),), end="\t")



Expand Down
24 changes: 13 additions & 11 deletions .devel/pytest/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
import scipy.spatial.distance
import numpy as np

try:
import rpy2
from rpy2.robjects.packages import importr
import rpy2.robjects.numpy2ri
#rpy2.robjects.numpy2ri.activate()
stats = importr("stats")
genie = importr("genie")
except:
rpy2 = None
stats = None
genie = None
# try:
# import rpy2
# from rpy2.robjects.packages import importr
# from rpy2.robjects import numpy2ri
# from rpy2.robjects import default_converter
# #import rpy2.robjects.numpy2ri
# #rpy2.robjects.numpy2ri.activate()
# stats = importr("stats")
# genie = importr("genie")
# except:
# rpy2 = None
# stats = None
# genie = None


try:
Expand Down

0 comments on commit f756559

Please sign in to comment.