# matchms.similarity.FingerprintSimilarity module¶

class matchms.similarity.FingerprintSimilarity.FingerprintSimilarity(similarity_measure: str = 'jaccard', set_empty_scores: Union[float, int, str] = 'nan')[source]

Calculate similarity between molecules based on their fingerprints.

For this similarity measure to work, fingerprints are expected to be derived by running `add_fingerprint()`.

Code example:

```import numpy as np
from matchms import calculate_scores
from matchms import Spectrum
from matchms.similarity import FingerprintSimilarity

spectrum_1 = Spectrum(mz=np.array([], dtype="float"),
intensities=np.array([], dtype="float"),

spectrum_2 = Spectrum(mz=np.array([], dtype="float"),
intensities=np.array([], dtype="float"),

spectrum_3 = Spectrum(mz=np.array([], dtype="float"),
intensities=np.array([], dtype="float"),

spectrums = [spectrum_1, spectrum_2, spectrum_3]
spectrums = [add_fingerprint(x, nbits=256) for x in spectrums]

# Specify type and calculate similarities
similarity_measure = FingerprintSimilarity("jaccard")
scores = calculate_scores(spectrums, spectrums, similarity_measure)
print(np.round(scores.scores, 3))
```

Should output

```[[1.    0.878 0.415]
[0.878 1.    0.444]
[0.415 0.444 1.   ]]
```
__init__(similarity_measure: str = 'jaccard', set_empty_scores: Union[float, int, str] = 'nan')[source]
Parameters
• similarity_measure – Chose similarity measure form “cosine”, “dice”, “jaccard”. The default is “jaccard”.

• set_empty_scores – Define what should be given instead of a similarity score in cases where fingprints are missing. The default is “nan”, which will return numpy.nan’s in such cases.

matrix(references: , queries: , is_symmetric: bool = False) numpy.array[source]

Calculate matrix of fingerprint based similarity scores.

Parameters
• references – List of reference spectrums.

• queries – List of query spectrums.

pair(reference: Spectrum, query: Spectrum) [source]

Calculate fingerprint based similarity score between two spectra.

Parameters
• reference – Single reference spectrum.

• query – Single query spectrum.

score_datatype

alias of `numpy.float64`

sort(scores: numpy.ndarray)

Return array of indexes for sorted list of scores. This method can be adapted for different styles of scores.

Parameters

scores – 1D Array of scores.

Returns

Indexes of sorted scores.

Return type

idx_sorted