<gh_stars>1-10
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/5.2_utils.distances.ipynb (unless otherwise specified).

__all__ = ['CustomDistance', 'EuclideanDistance', 'JaccardDistance']

# Cell

import numpy as np
from abc import ABC, abstractmethod

# Cell


class CustomDistance(ABC):

    @abstractmethod
    def compute_distance(x: np.ndarray, y: np.ndarray) -> float:
        """
        Computes the distance (dissimilarity) metric among 2 real vectors
        """
        pass

# Cell

class EuclideanDistance(CustomDistance):

    def compute_distance(x: np.ndarray, y: np.ndarray) -> float:
        return np.linalg.norm(x - y)

# Cell

class JaccardDistance(CustomDistance):
    def compute_distance(x: np.ndarray, y: np.ndarray) -> float:
        x_set = set(x)
        y_set = set(y)

        jacc_idx= len(x_set & y_set) / len(x_set | y_set)

        return jacc_idx
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/5.2_utils.distances.ipynb (unless otherwise specified).

__all__ = ['CustomDistance', 'EuclideanDistance', 'JaccardDistance']

# Cell

import numpy as np
from abc import ABC, abstractmethod

# Cell


class CustomDistance(ABC):

    @abstractmethod
    def compute_distance(x: np.ndarray, y: np.ndarray) -> float:
        """
        Computes the distance (dissimilarity) metric among 2 real vectors
        """
        pass

# Cell

class EuclideanDistance(CustomDistance):

    def compute_distance(x: np.ndarray, y: np.ndarray) -> float:
        return np.linalg.norm(x - y)

# Cell

class JaccardDistance(CustomDistance):
    def compute_distance(x: np.ndarray, y: np.ndarray) -> float:
        x_set = set(x)
        y_set = set(y)

        jacc_idx= len(x_set & y_set) / len(x_set | y_set)

        return jacc_idx
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/5.2_utils.distances.ipynb (unless otherwise specified). # Cell # Cell Computes the distance (dissimilarity) metric among 2 real vectors # Cell # Cell