<commit_before>from numpy import sqrt
from scipy.interpolate import interp1d
import scipy.stats as stats

def gaussian(var):
    """Returns a Gaussian PDF with variance var."""
    stddev = sqrt(var)
    return stats.norm(0, stddev)


class Custom(stats.rv_continuous):
    def __init__(self, x, fx):
        a = x[0]
        b = x[-1]
        stats.rv_continuous.__init__(self, a=a, b=b)

        self.x = x
        self.fx = x
        self._pdf = interp1d(x, fx,
                kind='linear', bounds_error=False, fill_value=0)<commit_msg>Added numerical mean and standard deviation (horribly slow by default?)<commit_after>from utilities import memoized

import numpy as np
from scipy.integrate import quad
from scipy.interpolate import interp1d
import scipy.stats as stats

def gaussian(var):
    """Returns a Gaussian PDF with variance var."""
    stddev = np.sqrt(var)
    return stats.norm(0, stddev)


class Custom(stats.rv_continuous):
    def __init__(self, x, fx):
        a = x[0]
        b = x[-1]
        stats.rv_continuous.__init__(self, a=a, b=b)

        self.x = x
        self.fx = x
        self._pdf = interp1d(x, fx,
                kind='linear', bounds_error=False, fill_value=0)

    @memoized
    def mean(self):
        return quad(lambda x: x * self.pdf(x), self.a, self.b)[0]

    @memoized
    def std(self):
        mean = self.mean()
        return quad(lambda x: (x - mean)**2 * self.pdf(x), self.a, self.b)[0]
{'fraction_non_alphanumeric': 0.12049861495844875, 'fraction_numerical': 0.01038781163434903, 'mean_word_length': 2.648989898989899, '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': '5732878', 'n_tokens_mistral': 505, 'n_tokens_neox': 487, 'n_words': 137}