def score_samples(X,model_weights,model_covars,use_scipy_misc=False):
    inv_covars = 1.0/model_covars
    n_features = X.shape[1]
    lpr= - 0.5 * ( n_features * numpy.log(2*numpy.pi) +
                    numpy.sum(numpy.log(model_covars),1)
                    + numpy.dot(numpy.abs(X)**2, inv_covars.T))
    if numpy.any(numpy.isnan(lpr)):
        import pdb; pdb.set_trace()
    lpr += numpy.log(model_weights)
    logprob = logsumexp(lpr)
    responsibilities = numpy.exp(lpr - logprob[:,numpy.newaxis])
    return logprob, responsibilities
def score_samples(X,model_weights,model_covars,use_scipy_misc=False):
    n_samples, n_dim = X.shape
    nmix = len(model_covars)
    lpr = numpy.empty((n_samples, nmix))
    for c, cv in enumerate(model_covars):
        cv_chol = linalg.cholesky(cv, lower=True)
        cv_log_det = 2 * numpy.sum(numpy.log(numpy.diagonal(cv_chol)))
        cv_sol = linalg.solve_triangular(cv_chol, X.T, lower=True).T
        lpr[:, c] = - .5 * (numpy.sum(cv_sol ** 2, axis=1) +
                                 n_dim * numpy.log(2 * numpy.pi) + cv_log_det)
    if numpy.any(numpy.isnan(lpr)):
        import pdb; pdb.set_trace()
    lpr += numpy.log(model_weights)
    logprob = logsumexp(lpr)
    responsibilities = numpy.exp(lpr - logprob[:,numpy.newaxis])
    return logprob, responsibilities