You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error encountered while trying to use the cosine to compute stats.compare_images.
Detailed issue description
Hello Neuromaps team,
I encountered an error while I was trying to reproduce the tutorial Comparing brain maps specifying cosine as the chosen metric (see also steps below).
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[16], line 1
----> 1 cossim = 1 - compare_images(ns_res, aba_res, metric=cosine)
File ~/Documents/master_analysis/brainmaps/lib/python3.9/site-packages/neuromaps/stats.py:61, in compare_images(src, trg, metric, ignore_zero, nulls, nan_policy)
59 else:
60 if not isinstance(metric([1, 1], [1, 1]), float):
---> 61 raise ValueError('Provided callable `metric` must accept two '
62 'inputs and return single value.')
64 srcdata, trgdata = load_data(src), load_data(trg)
66 mask = np.zeros(len(srcdata), dtype=bool)
ValueError: Provided callable `metric` must accept two inputs and return single value.
The problem seems to be with the verification of the variable method in stats.py (L60). Indeed, if I run cosine([1, 1], [1, 1]) I obtain 0 (int), which lead to not isinstance(cosine([1, 1], [1, 1]), float) equally True, thus raising the ValueError. For the moment I just bypass the problem by changing L60 for if not isinstance(metric([1, 2], [1, 1]), float):.
Don't know if this info is relevant, but I'm using scipy==1.10.1
Thank you for your help and for this really cool tool !
Sorry it took me so long to get to this 🥲
The issue is that neuromaps.stats.compare_images is double checking that the metric you use (if it isn't pearsonr or spearmanr) does accept two array inputs and returns a single float. To test this we use two dummy arrays which are [1, 1] and [1, 1]. This issue surfaces because cosine([1, 1], [1, 1]) is 0 (int) so it fails the condition. So as a fix I am changing it to double check that the output of the metric is a scalar (instead of a float). (The proposed solution above would also work.)
(scipy.spatial.distance.cosine should probably be fixed such that the output of cosine([1, 1], [1, 1]) is 0.0 instead of 0, to be consistent).
Issue summary
Error encountered while trying to use the cosine to compute
stats.compare_images
.Detailed issue description
Hello Neuromaps team,
I encountered an error while I was trying to reproduce the tutorial Comparing brain maps specifying cosine as the chosen metric (see also steps below).
The problem seems to be with the verification of the variable
method
in stats.py (L60). Indeed, if I runcosine([1, 1], [1, 1])
I obtain 0 (int), which lead tonot isinstance(cosine([1, 1], [1, 1]), float)
equally True, thus raising the ValueError. For the moment I just bypass the problem by changing L60for if not isinstance(metric([1, 2], [1, 1]), float):
.Don't know if this info is relevant, but I'm using scipy==1.10.1
Thank you for your help and for this really cool tool !
Steps to reproduce issue
Software version
0.0.3
What operating system were you using when you encountered this issue?
Code of Conduct
neuromaps
Code of ConductThe text was updated successfully, but these errors were encountered: