<commit_before>
import numpy as np
from scipy.spatial.distance import mahalanobis

from ..threeD_to_twoD import _format_data
from ..mantel import mantel_test


class Mahalanobis(object):
    """docstring for Mahalanobis"""
    def __init__(self, cube):
        super(Mahalanobis, self).__init__()
        self.cube = cube

    def format_data(self, data_format='spectra', *args):
        '''
        Create a 2D representation of the data. args are passed to
        _format_data.
        '''

        self.data_matrix = _format_data(self.cube, data_format=data_format,
                                        *args)

        return self

    def compute_distmat(self):
        '''
        Compute the Mahalanobis distance matrix.
        '''

        channels = self.data_matrix.shape[0]

        self.distance_matrix = np.zeros((channels, channels))

        for i in range(channels):
            for j in range(i):
                self.distance_matrix[i, j] = \
                    mahala_fcn(self.data_matrix[i, :], self.data_matrix[j, :])

        # Add in the upper triangle
        self.distance_matrix = self.distance_matrix + self.distance_matrix.T

        return self

    def run(self, verbose=False, *args):
        '''
        Run all computations.
        '''
        self.format_data(*args)
        self.compute_distmat()

        if verbose:
            import matplotlib.pyplot as p

            p.imshow(self.distance_matrix, interpolation=None)
            p.colorbar()
            p.show()

        return self


class Mahalanobis_Distance(object):

    """docstring for Mahalanobis_Distance"""

    def __init__(self, cube1, cube2):
        super(Mahalanobis_Distance, self).__init__()

        self.mahala1 = Mahalanobis(cube1)
        self.mahala2 = Mahalanobis(cube2)

    def compute_distmats(self, data_format='spectra', *args):
        '''
        Create a 2D representation of the data. args are passed to
        _format_data.
        '''

        self.mahala1.format_data(data_format=data_format, *args)
        self.mahala2.format_data(data_format=data_format, *args)

        return self<commit_msg>Add warnings to the mahalanobis methods<commit_after>
import numpy as np
from scipy.spatial.distance import mahalanobis

from ..threeD_to_twoD import _format_data
from ..mantel import mantel_test


class Mahalanobis(object):
    """
    Calculate a distance matrix using the Mahalanobis distance.

    .. warning::
        Testing for this method has not been implemented. The output cannot be
        trusted to be correct.

    """
    def __init__(self, cube):
        super(Mahalanobis, self).__init__()
        self.cube = cube

    def format_data(self, data_format='spectra', *args):
        '''
        Create a 2D representation of the data. args are passed to
        _format_data.
        '''

        self.data_matrix = _format_data(self.cube, data_format=data_format,
                                        *args)

        return self

    def compute_distmat(self):
        '''
        Compute the Mahalanobis distance matrix.
        '''

        channels = self.data_matrix.shape[0]

        self.distance_matrix = np.zeros((channels, channels))

        for i in range(channels):
            for j in range(i):
                self.distance_matrix[i, j] = \
                    mahala_fcn(self.data_matrix[i, :], self.data_matrix[j, :])

        # Add in the upper triangle
        self.distance_matrix = self.distance_matrix + self.distance_matrix.T

        return self

    def run(self, verbose=False, *args):
        '''
        Run all computations.
        '''
        self.format_data(*args)
        self.compute_distmat()

        if verbose:
            import matplotlib.pyplot as p

            p.imshow(self.distance_matrix, interpolation=None)
            p.colorbar()
            p.show()

        return self


class Mahalanobis_Distance(object):

    """
    Compare distance matrices based on the Mahalanobis distance.

    .. warning::
        Testing for this method has not been implemented. The output cannot be
        trusted to be correct.

    """

    def __init__(self, cube1, cube2):
        super(Mahalanobis_Distance, self).__init__()

        self.mahala1 = Mahalanobis(cube1)
        self.mahala2 = Mahalanobis(cube2)

    def compute_distmats(self, data_format='spectra', *args):
        '''
        Create a 2D representation of the data. args are passed to
        _format_data.
        '''

        self.mahala1.format_data(data_format=data_format, *args)
        self.mahala2.format_data(data_format=data_format, *args)

        return self
{'fraction_non_alphanumeric': 0.09161624891961971, 'fraction_numerical': 0.004753673292999135, 'mean_word_length': 2.1618852459016393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '521719', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1340, 'n_words': 336}