<commit_before># Authors: <NAME>
#          <NAME> <<EMAIL>>
#
# License: BSD (3-clause)

import numpy as np


def _check_stc(stc1, stc2):
    # XXX What should we check? that the data is having the same size?
    if stc1.data.shape != stc2.data.shape:
        raise ValueError('Data in stcs must have the same size')
    if np.all(stc1.times != stc2.times):
        raise ValueError('Times of two stcs must match.')


def source_estimate_quantification(stc1, stc2, metric='rms'):
    """Helper function to calculate matrix similarities.

    Parameters
    ----------
    stc1 : SourceEstimate
        First source estimate for comparison
    stc2 : SourceEstimate
        First source estimate for comparison
    metric : str
        Metric to calculate. 'rms', 'corr',

    Returns
    -------
    score : float
        Calculated metric
    """
    # TODO Add checks for source space
    _check_stc(stc1, stc2)

    score = _calc_metric(stc1.data, stc2.data, metric)


def _calc_metric(data1, data2, metric):
    """Helper to calculate metric of choice.

    Parameters
    ----------
    data1 : ndarray, shape(n_sources, ntimes)
        Second data matrix
    data2 : ndarray, shape(n_sources, ntimes)
        Second data matrix
    metric : str
        Metric to calculate. 'rms', 'rms_normed', 'corr',

    Returns
    -------
    score : float
        Calculated metric
    """

    # Calculate root mean square difference between two matrices
    if metric == 'rms':
        return np.sqrt(np.mean((data1 - data2) ** 2))

    # Calculate root mean square difference between two normalized matrices
    if metric == 'rms_normed':
        data1 = data1 / np.max(data1)
        data2 = data2 / np.max(data2)
        return np.sqrt(np.mean((data1 - data2) ** 2))

    # Calculate correlation coefficient between matrix elements
    elif metric == 'corr':
        return np.correlate(data1.flatten(), data2.flatten())<commit_msg>Add documentation, tests, fix corr<commit_after># Authors: <NAME>
#          <NAME> <<EMAIL>>
#
# License: BSD (3-clause)

import numpy as np


def _check_stc(stc1, stc2):
    # XXX What should we check? that the data is having the same size?
    if stc1.data.shape != stc2.data.shape:
        raise ValueError('Data in stcs must have the same size')
    if np.all(stc1.times != stc2.times):
        raise ValueError('Times of two stcs must match.')


def source_estimate_quantification(stc1, stc2, metric='rms'):
    """Helper function to calculate matrix similarities.

    Parameters
    ----------
    stc1 : SourceEstimate
        First source estimate for comparison
    stc2 : SourceEstimate
        First source estimate for comparison
    metric : str
        Metric to calculate. 'rms', 'corr',

    Returns
    -------
    score : float
        Calculated metric
    """
    # TODO Add checks for source space
    _check_stc(stc1, stc2)

    score = _calc_metric(stc1.data, stc2.data, metric)


def _calc_metric(data1, data2, metric):
    """Helper to calculate metric of choice.

    Parameters
    ----------
    data1 : ndarray, shape(n_sources, ntimes)
        Second data matrix
    data2 : ndarray, shape(n_sources, ntimes)
        Second data matrix
    metric : str
        Metric to calculate. 'rms', 'corr',

    Returns
    -------
    score : float
        Calculated metric
    """

    # Calculate root mean square difference between two matrices
    if metric == 'rms':
        return np.sqrt(np.mean((data1 - data2) ** 2))

    # Calculate root mean square difference between two normalized matrices
    if metric == 'rms_normed':
        data1 = data1 / np.max(data1)
        data2 = data2 / np.max(data2)
        return np.sqrt(np.mean((data1 - data2) ** 2))

    # Calculate correlation coefficient between matrix elements
    elif metric == 'corr':
        return np.correlate(stc1.data.flatten(), stc2.data.flatten())
{'fraction_non_alphanumeric': 0.11151171774401236, 'fraction_numerical': 0.0169971671388102, 'mean_word_length': 2.4802867383512543, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6943039', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1158, 'n_words': 374}