# Path: facerec_py/facerec/normalization.py
# def minmax(X, low, high, minX=None, maxX=None, dtype=np.float):
# def zscore(X, mean=None, std=None):
# def gaussian(X, mu, sig):
# def inverse_dissim(X):
# def vector_normalize(x):
# def gaussian_kernel(X, mu=None, sig=None):
#     X = np.asarray(X)
#     X = X * (high - low)
#     X = X + low
#     X = np.asarray(X)
#     X = (X - mean) / std
#     X = np.asarray(X)
#     X = zscore(X)
#     X = minmax(X, 0, 10)
#     X = np.asarray(X)


import numpy as np
from facerec_py.facerec import normalization

class HistogramIntersection(AbstractDistance):
    """
    Histogram Intersection is a similarity measure
    Need to convert similarity to distance

    """
    def __init__(self):
        AbstractDistance.__init__(self, "HistogramIntersection")

    def __call__(self, p, q):
        p = np.asarray(p).flatten()
        q = np.asarray(q).flatten()
        sim = np.sum(np.minimum(p, q))
        return 1/(sim+1)


class HistogramNormalizationIntersection(AbstractDistance):
    def __init__(self):
        """
        Normalized Version of Histogram Intersection

        If the historam is already normalized on construction, then HistogramIntersection should be be used
        """
        super(self.__class__, self).__init__("HistogramNormalizationIntersection")
        self.hist_int = HistogramIntersection()

    def __call__(self, p, q):
        p = np.asarray(p).flatten()
        q = np.asarray(q).flatten()

# Path: facerec_py/facerec/normalization.py
# def minmax(X, low, high, minX=None, maxX=None, dtype=np.float):
# def zscore(X, mean=None, std=None):
# def gaussian(X, mu, sig):
# def inverse_dissim(X):
# def vector_normalize(x):
# def gaussian_kernel(X, mu=None, sig=None):
#     X = np.asarray(X)
#     X = X * (high - low)
#     X = X + low
#     X = np.asarray(X)
#     X = (X - mean) / std
#     X = np.asarray(X)
#     X = zscore(X)
#     X = minmax(X, 0, 10)
#     X = np.asarray(X)


# Path: facerec_py/facerec/distance.py
import numpy as np
from facerec_py.facerec import normalization


class HistogramIntersection(AbstractDistance):
    """
    Histogram Intersection is a similarity measure
    Need to convert similarity to distance

    """
    def __init__(self):
        AbstractDistance.__init__(self, "HistogramIntersection")

    def __call__(self, p, q):
        p = np.asarray(p).flatten()
        q = np.asarray(q).flatten()
        sim = np.sum(np.minimum(p, q))
        return 1/(sim+1)


class HistogramNormalizationIntersection(AbstractDistance):
    def __init__(self):
        """
        Normalized Version of Histogram Intersection

        If the historam is already normalized on construction, then HistogramIntersection should be be used
        """
        super(self.__class__, self).__init__("HistogramNormalizationIntersection")
        self.hist_int = HistogramIntersection()

    def __call__(self, p, q):
        p = np.asarray(p).flatten()
        q = np.asarray(q).flatten()

        p = normalization.vector_normalize(p)