コード例 #1
0
ファイル: pdfs.py プロジェクト: xiangze/gpustats
def mvnpdf(data, means, covs):
    '''
    Compute multivariate normal log pdf

    Parameters
    ----------

    Returns
    -------

    '''
    logdets = [np.log(np.linalg.det(c)) for c in covs]
    ichol_sigmas = [inv(chol(c)) for c in covs]

    packed_params = util.pack_params(means, ichol_sigmas, logdets)
    packed_data = util.pad_data(data)
    return testmod.mvn_call(packed_data, packed_params, data.shape[1])
コード例 #2
0
ファイル: pdfs.py プロジェクト: drdangersimon/gpustats
def mvnpdf(data, means, covs):
    '''
    Compute multivariate normal log pdf

    Parameters
    ----------

    Returns
    -------

    '''
    logdets = [np.log(np.linalg.det(c)) for c in covs]
    ichol_sigmas = [inv(chol(c)) for c in covs]

    packed_params = util.pack_params(means, ichol_sigmas, logdets)
    packed_data = util.pad_data(data)
    return testmod.mvn_call(packed_data, packed_params,
                            data.shape[1])
コード例 #3
0
    n = 1e3
    k = 16

    data = randn(n, k).astype(np.float32)
    mean = randn(k)
    cov = np.array(util.random_cov(k), dtype=np.float32)

    j = 32

    padded_data = util.pad_data(data)

    chol_sigma = chol(cov)
    ichol_sigma = L.inv(chol_sigma)
    logdet = np.log(np.linalg.det(cov))

    means = (mean, ) * j
    covs = (ichol_sigma, ) * j
    logdets = (logdet, ) * j

    packed_params = util.pack_params(means, covs, logdets)

    cpu_func = lambda: testmod.cpu_mvnpdf(padded_data, packed_params, k
                                          ).squeeze()
    gpu_func = lambda: testmod._mvnpdf(padded_data, packed_params, k).squeeze()

    print cpu_func()
    print gpu_func()

    # bench(cpu_func, gpu_func, gruns=50)
コード例 #4
0
ファイル: scratch.py プロジェクト: drdangersimon/gpustats
    testmod.set_device(0)

    n = 1e3
    k = 16

    data = randn(n, k).astype(np.float32)
    mean = randn(k)
    cov = np.array(util.random_cov(k), dtype=np.float32)

    j = 32

    padded_data = util.pad_data(data)

    chol_sigma = chol(cov)
    ichol_sigma = L.inv(chol_sigma)
    logdet = np.log(np.linalg.det(cov))

    means = (mean,) * j
    covs = (ichol_sigma,) * j
    logdets = (logdet,) * j

    packed_params = util.pack_params(means, covs, logdets)

    cpu_func = lambda: testmod.cpu_mvnpdf(padded_data, packed_params, k).squeeze()
    gpu_func = lambda: testmod._mvnpdf(padded_data, packed_params, k).squeeze()

    print cpu_func()
    print gpu_func()

    # bench(cpu_func, gpu_func, gruns=50)