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
{{ message }}
Repository navigation
[Similarity module] Add more similarity measurements #124
As explained on Wikipedia there is a Tanimoto similarity and a Tanimoto distance. So both exist.
The easiest test is to compare an object to itself. Its similarity is greater than zero (often one) and the distance is zero.
I feel like it is better to add AIMSim as a dependence. Implementing 30+ methods is a lot of work.
We may wish to have a few basic methods implemented; the most common distance metrics and similarity measures are already there in scikit-learn
(distances) sklearn.metrics.DistanceMetric
(similarities and divergences) sklearn.metrics.pairwise
I'd lead with interfacing to scikit-learn (I think we already did this in large part?) and then considering interfacing to AIMSim a follow-up task.
I guess it is important to distinguish between similarities/affinities and distances/divergences. I'd suggest making sure that we have these distinguished, plus the "converter" between them.
Update: We decided not to include any wrappers to support the functionality in other packages (reason: additional overhead and unnecessary dependency), instead, we showcase how our package works with other libraries in notebooks/tutorials.
Of all the similarity indices we've tested, these are the "best ones". I'm including a sample implementation for the case in which they are calculated from binary fingerprints.
Thanks for sharing. I am copying @ramirandaq 's code for readibility.
importnumpyasnp# Pairwise similarity indices calculated over binary fingerprintsdefindicators(x, y):
"""Calculating base descriptors a : number of common on bits d : number of common off bits dis = b + c : 1-0 mismatches p : len of fingerprint Check Table S1 in the SI of https://link.springer.com/article/10.1186/s13321-021-00505-3#Sec21 """p=len(x)
a=np.dot(x, y)
d=np.dot(1-x, 1-y)
dis=p-a-dreturna, d, dis, p# Indices# BUB: Baroni-Urbani-Buser, Fai: Faith, Ja: Jaccard# JT: Jaccard-Tanimoto, RT: Rogers-Tanimoto, RR: Russel-Rao# SM: Sokal-Michener, SSn: Sokal-Sneath nx=np.array([1, 0, 1, 0, 1])
y=np.array([1, 1, 1, 0, 0])
a, d, dis, p=indicators(x, y)
bub= (a*d)**0.5+a)/((a*d)**0.5+a+dis)
fai= (a+0.5*d)/pja= (3*a)/(3*a+dis)
jt=a/(a+dis)
rt= (a+d)/(p+dis)
rr=a/psm=(a+d)/pss1=a/(a+2*dis)
ss2= (2* (a+d))/(p+ (a+d))
Just to clarify, all of these are "bitwise". We have:
a = logical "and" between bitstrings; intersection between sets if for each element, "1" or "on" means an element/feature is present.
d = logical "not and" between bitstrings; {universe} - {union} between sets if "1" or "on" means an element is present. So these are "features that are not present in either set"
dis = logical "exclusive or" between bitstrings. {union} - {intersection} if "1" or "on" means an element is present. So these are "features that are present in one item, but not present in the other".
As Ramon notes, most of these are just one-line formulas. For things that aren't "logical" obviously there are more complicated forms of similarity, though most will be (some sort of) mahalanobis distance-related function.
Activity
PaulWAyers commentedon May 30, 2023
As explained on Wikipedia there is a Tanimoto similarity and a Tanimoto distance. So both exist.
The easiest test is to compare an object to itself. Its similarity is greater than zero (often one) and the distance is zero.
I feel like it is better to add AIMSim as a dependence. Implementing 30+ methods is a lot of work.
We may wish to have a few basic methods implemented; the most common distance metrics and similarity measures are already there in scikit-learn
(distances) sklearn.metrics.DistanceMetric
(similarities and divergences)
sklearn.metrics.pairwiseI'd lead with interfacing to scikit-learn (I think we already did this in large part?) and then considering interfacing to AIMSim a follow-up task.
I guess it is important to distinguish between similarities/affinities and distances/divergences. I'd suggest making sure that we have these distinguished, plus the "converter" between them.
FanwangM commentedon Jun 2, 2023
Yes, we should make them differentiable and be obvious as much as we can to avoid any ambiguity.
FarnazH commentedon Jun 20, 2023
Update: We decided not to include any wrappers to support the functionality in other packages (reason: additional overhead and unnecessary dependency), instead, we showcase how our package works with other libraries in notebooks/tutorials.
PaulWAyers commentedon Jul 6, 2023
@ramirandaq will list the "key similarity measures" from https://vlachosgroup.github.io/AIMSim/implemented_metrics.html and we'll reimplement them.
ramirandaq commentedon Jul 6, 2023
Of all the similarity indices we've tested, these are the "best ones". I'm including a sample implementation for the case in which they are calculated from binary fingerprints.
sim_indices.txt
FanwangM commentedon Jul 6, 2023
Thanks for sharing. I am copying @ramirandaq 's code for readibility.
PaulWAyers commentedon Jul 9, 2023
Just to clarify, all of these are "bitwise". We have:
a = logical "and" between bitstrings; intersection between sets if for each element, "1" or "on" means an element/feature is present.
d = logical "not and" between bitstrings; {universe} - {union} between sets if "1" or "on" means an element is present. So these are "features that are not present in either set"
dis = logical "exclusive or" between bitstrings. {union} - {intersection} if "1" or "on" means an element is present. So these are "features that are present in one item, but not present in the other".
As Ramon notes, most of these are just one-line formulas. For things that aren't "logical" obviously there are more complicated forms of similarity, though most will be (some sort of) mahalanobis distance-related function.
FarnazH commentedon Aug 20, 2024
@marco-2023, please:
measures/similarity.pydiversity.pyandconvertor.pyto themeasuresmodule.