<commit_before>"""Module for random variables.

This module contains classes for random variables.

Classes:
Discrete -- Discrete random variable
Gaussian -- Gaussian random variable

"""

import numpy as np


class ParameterException(Exception):

    """Exception for invalid parameters."""

    pass


class Discrete(object):

    """Discrete random variable.

    Discrete random variables are internally implemented using
    multidimensional arrays for storing the probability mass function.

    """

    def __init__(self, raw_pmf, *args):
        """Discrete random variable.

        Create a discrete random variable with corresponding
        probability mass function.

        Positional arguments:
        pmf -- probability mass function
        dim -- dimensions

        """
        pmf = np.asarray(raw_pmf, dtype=np.float64)

        # Set probability mass function
        if not np.allclose(np.sum(pmf), 1):
            raise ParameterException('Invalid probability mass function.')
        else:
            self.pmf = pmf

        # Set variable nodes for dimensions
        if np.size(pmf) != len(args):
            raise ParameterException('Dimension mismatch.')
        else:
            self.dim = args

    def __str__(self):
        """Return string representation."""
        return str(self.pmf)

    def __add__(self, other):
        """Add other to self and return the result."""
        pmf = np.convolve(self.pmf, other.pmf, 'same')
        return Discrete(pmf, self.dim)

    def __sub__(self, other):
        """Subtract other from self and return the result."""
        pmf = np.convolve(self.pmf[::-1], other.pmf, 'same')
        return Discrete(pmf, self.dim)

    def __mul__(self, other):
        """Multiply other with self and return the result."""
        if len(self.dim) < len(other.dim):<commit_msg>bugfix<commit_after>"""Module for random variables.

This module contains classes for random variables.

Classes:
Discrete -- Discrete random variable
Gaussian -- Gaussian random variable

"""

import numpy as np


class ParameterException(Exception):

    """Exception for invalid parameters."""

    pass


class Discrete(object):

    """Discrete random variable.

    Discrete random variables are internally implemented using
    multidimensional arrays for storing the probability mass function.

    """

    def __init__(self, raw_pmf, *args):
        """Discrete random variable.

        Create a discrete random variable with corresponding
        probability mass function.

        Positional arguments:
        pmf -- probability mass function
        dim -- dimensions

        """
        pmf = np.asarray(raw_pmf, dtype=np.float64)

        # Set probability mass function
        if not np.allclose(np.sum(pmf), 1):
            raise ParameterException('Invalid probability mass function.')
        else:
            self.pmf = pmf

        # Set variable nodes for dimensions
        if np.ndim(pmf) != len(args):
            raise ParameterException('Dimension mismatch.')
        else:
            self.dim = args

    def __str__(self):
        """Return string representation."""
        return str(self.pmf)

    def __add__(self, other):
        """Add other to self and return the result."""
        pmf = np.convolve(self.pmf, other.pmf, 'same')
        return Discrete(pmf, self.dim)

    def __sub__(self, other):
        """Subtract other from self and return the result."""
        pmf = np.convolve(self.pmf[::-1], other.pmf, 'same')
        return Discrete(pmf, self.dim)

    def __mul__(self, other):
        """Multiply other with self and return the result."""
        if len(self.dim) < len(other.dim):
{'fraction_non_alphanumeric': 0.09981014374830485, 'fraction_numerical': 0.0021697857336588013, 'mean_word_length': 2.489120151371807, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4170169', 'n_tokens_mistral': 1005, 'n_tokens_neox': 952, 'n_words': 331}