<commit_before># -*- coding: utf-8 -*-
"""Mathematical functions.
"""
import collections
import numpy as np


__all__ = [
    'moving_average',
    'block_average',
    'bootstrap',
    'correlation',
    'rmse',
    'compare_arrays',
]


def moving_average(x, y, N, mode='same'):
    """Calculate running mean for given timeseries.

    Parameters:
        x (ndarray): x data.
        y (ndarray): y data.
        N (int): Window size.
        mode (str): Convolve mode 'valid' or 'same'.

    Returns:
        ndarray, np.ndarray: Adjusted x data, Averaged y data.
    """
    if mode == 'valid':
        l, t = N//2, -N//2 + 1
        x = x[l:t]
    elif mode == 'full':
        raise Exception(
            'Mode "full" is not supported to prevent boundary effects.'
            'If you know what you are doing, use numpy.convolve to use'
            'full mode.')

    return x, np.convolve(y, np.ones((N,)) / N, mode=mode)


def block_average(x, y, N):
    """Calculate the average over windows of size N.

    Parameters:
        x (ndarray): x data.
        y (ndarray): y dat.
        N (int): Window size to average.

    Returns:
        ndarray, ndarray: Every n-th x value, Corresponding averages.
    """
    x = x[N-1::N]
    y = np.array([np.nanmean(v) for v in np.split(y, y.size / N)])

    return x, y


def bootstrap(x, size=None):
    """Generate a bootstrap of given size from x.

    Note:
        This function is a simple wrapper for np.random.choice

    Parameters:
        a (1-D array-like or int):
            If an ndarray, a random sample is generated from its elements.
            If an int, the random sample is generated as if a was np.arange(n)
        size (int or tuple of ints): Output shape.
            If the given shape is, e.g., ``(m, n, k)``, then
            ``m * n * k`` samples are drawn.  Default is None, in which case a
            single value is returned.

    Returns:
        ndarray, shape (size,): The generated random samples.
    """
    return np.random.choice(x, size=size, replace=True)<commit_msg>Fix docstring.<commit_after># -*- coding: utf-8 -*-
"""Mathematical functions.
"""
import collections
import numpy as np


__all__ = [
    'moving_average',
    'block_average',
    'bootstrap',
    'correlation',
    'rmse',
    'compare_arrays',
]


def moving_average(x, y, N, mode='same'):
    """Calculate running mean for given timeseries.

    Parameters:
        x (ndarray): x data.
        y (ndarray): y data.
        N (int): Window size.
        mode (str): Convolve mode 'valid' or 'same'.

    Returns:
        ndarray, np.ndarray: Adjusted x data, Averaged y data.
    """
    if mode == 'valid':
        l, t = N//2, -N//2 + 1
        x = x[l:t]
    elif mode == 'full':
        raise Exception(
            'Mode "full" is not supported to prevent boundary effects.'
            'If you know what you are doing, use numpy.convolve to use'
            'full mode.')

    return x, np.convolve(y, np.ones((N,)) / N, mode=mode)


def block_average(x, y, N):
    """Calculate the average over windows of size N.

    Parameters:
        x (ndarray): x data.
        y (ndarray): y dat.
        N (int): Window size to average.

    Returns:
        ndarray, ndarray: Every n-th x value, Corresponding averages.
    """
    x = x[N-1::N]
    y = np.array([np.nanmean(v) for v in np.split(y, y.size / N)])

    return x, y


def bootstrap(x, size=None):
    """Generate a bootstrap of given size from x.

    Note:
        This function is a simple wrapper for np.random.choice

    Parameters:
        x (1-D array-like or int):
            If an ndarray, a random sample is generated from its elements.
            If an int, the random sample is generated as if a was np.arange(n)
        size (int or tuple of ints): Output shape.
            If the given shape is, e.g., ``(m, n, k)``, then
            ``m * n * k`` samples are drawn.  Default is None, in which case a
            single value is returned.

    Returns:
        ndarray, shape (size,): The generated random samples.
    """
    return np.random.choice(x, size=size, replace=True)
{'fraction_non_alphanumeric': 0.12381875454325175, 'fraction_numerical': 0.002907681124303368, 'mean_word_length': 2.106094808126411, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7269507', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1275, 'n_words': 494}