Exemple #1
0
def _wmvnpdf(x, pi, mu, va, d=1, logged=False, use_gpu=True, **kwargs):
    if len(x.shape) == 1:
        x = x.reshape((1, x.shape))
    if len(mu.shape) == 1:
        mu = mu.reshape((1, mu.shape))
    if len(va.shape) == 2:
        va = va.reshape(1, va.shape[0], va.shape[1])

    if len(va.shape) == 1:
        va = va.reshape(va.shape[0], 1, 1)

    if isinstance(pi, float) or isinstance(pi, int):
        pi = array([pi])
    elif isinstance(pi, ndarray):
        if len(pi.shape) == 0:
            pi = pi.reshape((1))

    if has_gpu and use_gpu:
        if 'device' in kwargs:
            dev = kwargs['device']
        else:
            dev = 0
        select_gpu(dev)
        return mvnpdf_multi(x, mu, va, weights=pi, logged=logged, order='C').astype('float64')
    else:
        if logged:
            return mvn_weighted_logged(x, mu, va, pi)
        else:
            return exp(mvn_weighted_logged(x, mu, va, pi))
Exemple #2
0
def _mvnpdf(x, mu, va, n=1, logged=False, use_gpu=True, **kwargs):
    if len(x.shape) == 1:
        x = x.reshape((1, x.shape[0]))
    if len(mu.shape) == 1:
        mu = mu.reshape((1, mu.shape[0]))
    if len(va.shape) == 2:
        va = va.reshape(1, va.shape[0], va.shape[1])

    if has_gpu and use_gpu:
        if 'device' in kwargs:
            dev = kwargs['device']
        else:
            dev = 0
        select_gpu(dev)
        return mvnpdf_multi(
            x,
            mu,
            va,
            weights=ones(
                mu.shape[0]),
            logged=logged,
            order='C').astype('float64')
    else:
        if logged:
            return mvn_weighted_logged(x, mu, va, ones(mu.shape[0]))
        else:
            return exp(mvn_weighted_logged(x, mu, va, ones(mu.shape[0])))
Exemple #3
0
def _mvnpdf(x, mu, va, n=1, logged=False, use_gpu=True, **kwargs):
    if len(x.shape) == 1:
        x = x.reshape((1, x.shape[0]))
    if len(mu.shape) == 1:
        mu = mu.reshape((1, mu.shape[0]))
    if len(va.shape) == 2:
        va = va.reshape(1, va.shape[0], va.shape[1])

    if has_gpu and use_gpu:
        if 'device' in kwargs:
            dev = kwargs['device']
        else:
            dev = 0
        select_gpu(dev)
        return mvnpdf_multi(x,
                            mu,
                            va,
                            weights=ones(mu.shape[0]),
                            logged=logged,
                            order='C').astype('float64')
    else:
        if logged:
            return mvn_weighted_logged(x, mu, va, ones(mu.shape[0]))
        else:
            return exp(mvn_weighted_logged(x, mu, va, ones(mu.shape[0])))
def update_labels(data, mus, sigmas, pis):
    densities = mvn_weighted_logged(data, mus, sigmas, pis)
    Z = np.asarray(densities.argmax(1), dtype='i')

    return sample_discrete(densities).squeeze(), Z