> For the complete documentation index, see [llms.txt](https://infinitode-docs.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitode-docs.gitbook.io/documentation/package-documentation/duplipy-package-documentation/duplipy-reference/similarity-functions.md).

# Similarity Functions

Available functions:

* [`edit_distance_score`](#edit-distance-score)`(text1, text2)`: Calculate the edit distance score between two texts.
* [`bleu_score`](#bleu-score)`(reference, candidate)`: Calculate the BLEU score between a reference sentence and a candidate sentence.
* [`jaccard_similarity_score`](#jaccard-similarity-score)`(text1, text2)`: Calculate Jaccard similarity between two texts.
* [`sorensen_dice_coefficient`](#sorensen-dice-coefficient)`(text1, text2)`: Calculate the Sorensen-Dice coefficient between two texts.
* [`cosine_similarity_score`](#cosine-similarity-score)`(text1, text2)`: Calculate the cosine similarity between two texts.
* [`mean_squared_error`](#mean-squared-error)`(image1, image2)`: Calculate the mean squared error (MSE) between two images.
* [`psnr`](#psnr)`(image1, image2)`: Calculate the peak signal-to-noise ratio (PSNR) between two images.

***

### Edit distance score

Calculate the edit distance score between two texts.

```
Parameters:
- `text1` (str): The first text.
- `text2` (str): The second text.

Returns:
- `int`: The edit distance score.
```

### BLEU Score

Calculate the BLEU score between a reference sentence and a candidate sentence.

```
Parameters:
- `reference` (str): The reference sentence.
- `candidate` (str): The candidate sentence.

Returns:
- `float`: The BLEU score.
```

### Jaccard Similarity Score

Jaccard similarity is a measure of similarity between two sets. In the context of text comparison, it calculates the similarity between the sets of words in two texts.

```
Parameters:
- `text1` (str): The first text for comparison.
- `text2` (str): The second text for comparison.

Returns:
- `float`: Jaccard similarity score between the two texts. The score ranges
from 0 (no similarity) to 1 (complete similarity).
```

### Sorensen-Dice Coefficient

The Sorensen-Dice coefficient is a statistic used for comparing the similarity of two samples.

```
Parameters:
- `text1` (str): The first text for comparison.
- `text2` (str): The second text for comparison.

Returns:
- `float`: The Sorensen-Dice coefficient between the two texts.
```

### Cosine Similarity Score

Cosine similarity is a measure of similarity between two non-zero vectors of an inner product space that measures the cosine of the angle between them.

```
Parameters:
- `text1` (str): The first text for comparison.
- `text2` (str): The second text for comparison.

Returns:
- `float`: The cosine similarity score between the two texts.
```

### Mean Squared Error

MSE is a measure of the average squared difference between the estimated values and the actual value.

```
Parameters:
- `image1` (PIL.Image.Image): The first image for comparison.
- `image2` (PIL.Image.Image): The second image for comparison.

Returns:
- `float`: The mean squared error between the two images.
```

### PSNR

PSNR is the ratio between the maximum possible power of a signal and the power of corrupting noise that affects the fidelity of its representation.

```
Parameters:
- `image1` (PIL.Image.Image): The first image for comparison.
- `image2` (PIL.Image.Image): The second image for comparison.

Returns:
- `float`: The peak signal-to-noise ratio between the two images.
```
