<commit_before>from __future__ import division

from sklearn.utils.extmath import logsumexp
from sklearn.utils import check_random_state
from sklearn.base import BaseEstimator
import numpy as np
import random, collections
import scipy.sparse


# Author: <NAME>
#         <NAME> <<EMAIL>>
#



EPS = np.finfo(float).eps

def log_product_of_bernoullis_mixture_likelihood(X, log_odds, log_inv_mean_sums):
    """Log likelihood function for the product of Bernoullis
    mixture distribution
    """
    return np.dot(X,log_odds.T) + log_inv_mean_sums


def sample_bernoulli(mean, n_samples=1,
                    random_state=None,
                    data_type=np.uint8):
    """Generate random samples from a Bernoulli distribution.

    Parameters
    ----------
    mean : array_like, shape (n_features,)
        Mean of the distribution.

    n_samples : int, optional
        Number of samples to generate. Defaults to 1.

    Returns
    -------
    X : array, shape (n_features, n_samples)
        Randomly generated sample
    """
    rng = check_random_state(random_state)
    n_dim = len(mean)
    rand = rng.rand(n_dim, n_samples)
    if n_samples == 1:
        rand.shape = (n_dim,)

    return (rand.T > mean).T.astype(data_type)




class BernoulliMM(BaseEstimator):
    """
    Bernoulli Mixture model with an EM solver.

    Parameters
    ----------
    n_components : int, optional
        Number of mixture components. Defaults to 1.

    random_state : RandomState or an int seed (0 by default)
        A random number generator instance

    min_prob : float, optional
        Floor for the minimum probability<commit_msg>Fixed bug when sampling from BernoulliMM.<commit_after>from __future__ import division

from sklearn.utils.extmath import logsumexp
from sklearn.utils import check_random_state
from sklearn.base import BaseEstimator
import numpy as np
import random, collections
import scipy.sparse


# Author: <NAME>
#         <NAME> <<EMAIL>>
#



EPS = np.finfo(float).eps

def log_product_of_bernoullis_mixture_likelihood(X, log_odds, log_inv_mean_sums):
    """Log likelihood function for the product of Bernoullis
    mixture distribution
    """
    return np.dot(X,log_odds.T) + log_inv_mean_sums


def sample_bernoulli(mean, n_samples=1,
                    random_state=None,
                    data_type=np.uint8):
    """Generate random samples from a Bernoulli distribution.

    Parameters
    ----------
    mean : array_like, shape (n_features,)
        Mean of the distribution.

    n_samples : int, optional
        Number of samples to generate. Defaults to 1.

    Returns
    -------
    X : array, shape (n_features, n_samples)
        Randomly generated sample
    """
    rng = check_random_state(random_state)
    n_dim = len(mean)
    rand = rng.rand(n_dim, n_samples)
    if n_samples == 1:
        rand.shape = (n_dim,)

    return (rand.T < mean).T.astype(data_type)




class BernoulliMM(BaseEstimator):
    """
    Bernoulli Mixture model with an EM solver.

    Parameters
    ----------
    n_components : int, optional
        Number of mixture components. Defaults to 1.

    random_state : RandomState or an int seed (0 by default)
        A random number generator instance

    min_prob : float, optional
        Floor for the minimum probability
{'fraction_non_alphanumeric': 0.08791540785498489, 'fraction_numerical': 0.0036253776435045317, 'mean_word_length': 2.7244094488188977, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '4850505', 'n_tokens_mistral': 1037, 'n_tokens_neox': 988, 'n_words': 296}