コード例 #1
0
ファイル: sample_dirichlet.py プロジェクト: wds2014/pydpm
def dirichlet(a, times=1):

    a = np.array(a)
    normalize_scale = [
        a.shape[-1], a.shape[-1] * times,
        int(a.size / a.shape[-1]) * times
    ]
    normal_block = int(500)
    normal_grid = int(normalize_scale[2] / normal_block + 1)
    normalize_scale = gpuarray.to_gpu(np.array(normalize_scale,
                                               dtype=np.int32))
    a, b, output, matrix_scale, randomseed, partition, single_number = para_preprocess(
        times, np.float32, np.float32, a, 1.0)

    func = Sampler.get_function('rand_Gamma')
    func(randomseed,
         output,
         matrix_scale,
         a,
         b,
         grid=(partition[0], 1, 1),
         block=(partition[1], 1, 1))

    func = Sampler.get_function('normalize')
    func(output,
         matrix_scale,
         normalize_scale,
         grid=(normal_grid, 1, 1),
         block=(normal_block, 1, 1))

    output = output.get()
    return output
コード例 #2
0
ファイル: sample_chisquare.py プロジェクト: wds2014/pydpm
def chisquare(n, times=1, device='cpu'):

    n, output, matrix_scale, randomseed, partition, single_number = para_preprocess(
        times, np.int32, np.float32, n)
    func = Sampler.get_function('rand_Chisquare')
    func(randomseed,
         output,
         matrix_scale,
         n,
         grid=(partition[0], 1, 1),
         block=(partition[1], 1, 1))
    if device == 'cpu':
        output = output.get()
    if single_number:
        return output[0]
    return output
コード例 #3
0
ファイル: sample_exponential.py プロジェクト: wds2014/pydpm
def exponential(Lambda, times=1, device='cpu'):

    Lambda, output, matrix_scale, randomseed, partition, single_number = para_preprocess(
        times, np.float32, np.float32, Lambda)
    func = Sampler.get_function('rand_Exponential')
    func(randomseed,
         output,
         matrix_scale,
         Lambda,
         grid=(partition[0], 1, 1),
         block=(partition[1], 1, 1))

    if device == 'cpu':
        output = output.get()
    if single_number:
        return output[0]
    return output
コード例 #4
0
def hypergeometric(ng, nb, ns, times=1, device='cpu'):

    ng, nb, output, matrix_scale, randomseed, partition, single_number = para_preprocess(
        times, np.float32, np.int32, ng, nb)
    ns = gpuarray.to_gpu(np.array(ns, dtype=np.int32, order='C'))
    prob = ng / (ng + nb)
    func = Sampler.get_function('rand_Hypergeometric')
    func(randomseed,
         output,
         matrix_scale,
         prob,
         ns,
         grid=(partition[0], 1, 1),
         block=(partition[1], 1, 1))

    if device == 'cpu':
        output = output.get()
    if single_number:
        return output[0]
    return output
コード例 #5
0
ファイル: sample_chisquare.py プロジェクト: wds2014/pydpm
def noncentral_chisquare(n, delta, times=1, var=1, device='cpu'):

    # n,delta,var must be same shape

    n = np.array(n, dtype=np.int32, order='C')
    delta, var, output, matrix_scale, randomseed, partition, single_number = para_preprocess(
        times, np.float32, np.float32, delta, var)
    func = Sampler.get_function('rand_Noncentral_Chisquare')
    func(randomseed,
         output,
         matrix_scale,
         n,
         delta,
         var,
         grid=(partition[0], 1, 1),
         block=(partition[1], 1, 1))

    if device == 'cpu':
        output = output.get()
    if single_number:
        return output[0]
    return output
コード例 #6
0
ファイル: sample_triangular.py プロジェクト: wds2014/pydpm
def triangular(left=0, mid=1, right=1, times=1, device='cpu'):

    left, output, matrix_scale, randomseed, partition, single_number = para_preprocess(
        times, np.float32, np.float32, left)

    mid = gpuarray.to_gpu(np.array(mid, dtype=np.float32, order='C'))
    right = gpuarray.to_gpu(np.array(right, dtype=np.float32, order='C'))

    func = Sampler.get_function('rand_Triangular')
    func(randomseed,
         output,
         matrix_scale,
         left,
         mid,
         right,
         grid=(partition[0], 1, 1),
         block=(partition[1], 1, 1))

    if device == 'cpu':
        output = output.get()
    if single_number:
        return output[0]
    return output