Permalink
Browse files

new discrete sampler

  • Loading branch information...
1 parent 42e16bb commit 570fdeb4d1da204b1e56717ba29db07a08be8629 @andrewcron andrewcron committed Oct 16, 2012
Showing with 15 additions and 15 deletions.
  1. +3 −3 gpustats/kernels.py
  2. +6 −6 gpustats/sampler.py
  3. +2 −2 gpustats/tests/test_pdfs.py
  4. +4 −4 gpustats/tests/test_samplers.py
View
@@ -43,11 +43,11 @@
log_pdf_normal = DensityKernel('log_pdf_normal', _log_pdf_normal)
pdf_normal = Exp('pdf_normal', log_pdf_normal)
-sample_discrete = CUFile('sample_discrete',
+sample_discrete_old = CUFile('sample_discrete_old',
'sample_discrete.cu')
-sample_discrete_logged = CUFile('sample_discrete_logged',
+sample_discrete_logged_old = CUFile('sample_discrete_logged_old',
'sample_discrete_logged.cu')
-sample_discrete_new = CUFile('sample_discrete_new',
+sample_discrete = CUFile('sample_discrete',
'sampleFromMeasureMedium.cu')
View
@@ -13,7 +13,7 @@
cu_module = codegen.get_full_cuda_module()
-def sample_discrete_new(densities, logged=False,
+def sample_discrete(densities, logged=False,
return_gpuarray=False):
"""
@@ -46,7 +46,7 @@ def sample_discrete_new(densities, logged=False,
gpu_densities = to_gpu(densities)
# get gpu function
- cu_func = cu_module.get_function('sample_discrete_new')
+ cu_func = cu_module.get_function('sample_discrete')
# setup GPU data
gpu_random = to_gpu(np.asarray(np.random.rand(n), dtype=np.float32))
@@ -79,8 +79,8 @@ def sample_discrete_new(densities, logged=False,
return res
-
-def sample_discrete(in_densities, logged=False, pad=False,
+## depreciated
+def sample_discrete_old(in_densities, logged=False, pad=False,
return_gpuarray=False):
"""
Takes a categorical sample from the unnormalized univariate
@@ -110,9 +110,9 @@ def sample_discrete(in_densities, logged=False, pad=False,
n, k = densities.shape
if logged:
- cu_func = cu_module.get_function('sample_discrete_logged')
+ cu_func = cu_module.get_function('sample_discrete_logged_old')
else:
- cu_func = cu_module.get_function('sample_discrete')
+ cu_func = cu_module.get_function('sample_discrete_old')
if isinstance(densities, GPUArray):
if densities.flags.f_contiguous:
@@ -62,10 +62,10 @@ class TestMVN(unittest.TestCase):
(1000, 7, 64),
(1000, 8, 64),
(1000, 14, 32),
- (1000, 16, 32),
+ (1000, 16, 128),
(250, 25, 32),
(10, 15, 2),
- (500000, 5, 128)]
+ (500000, 5, 12)]
def _check_multi(self, n, k, p):
a, b = _compare_multi(n, k, p)
@@ -34,7 +34,7 @@ def _compare_discrete(n, k):
dens = densities[0,:].copy() / densities[0,:].sum()
expected_mu = np.dot(np.arange(k), dens)
- labels = gpusamp.sample_discrete_new(densities, logged=False)
+ labels = gpusamp.sample_discrete(densities, logged=False)
est_mu = labels.mean()
return est_mu, expected_mu
@@ -44,7 +44,7 @@ def _compare_logged(n, k):
dens = dens / dens.sum()
expected_mu = np.dot(np.arange(k), dens)
- labels = gpusamp.sample_discrete_new(densities, logged=True)
+ labels = gpusamp.sample_discrete(densities, logged=True)
est_mu = labels.mean()
return est_mu, expected_mu
@@ -54,7 +54,7 @@ class TestDiscreteSampler(unittest.TestCase):
(100000, 9),
(100000, 16),
(100000, 20),
- (100000, 55)]
+ (1000000, 35)]
def _check_discrete(self, n, k):
a, b = _compare_discrete(n, k)
@@ -75,7 +75,7 @@ def test_logged(self):
if __name__ == '__main__':
print 'starting sampler'
- a, b = _compare_logged(1000000, 3)
+ a, b = _compare_logged(1000000, 35)
print a
print b

0 comments on commit 570fdeb

Please sign in to comment.