Skip to content

Commit 47ad523

Browse files
committed
remove test_sampling_consistency
1 parent 1d41eb7 commit 47ad523

File tree

1 file changed

+0
-87
lines changed

1 file changed

+0
-87
lines changed

tests/distributions/test_discrete.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -330,93 +330,6 @@ def test_logp_basic(self):
330330
with pytest.raises(TypeError):
331331
logp_fn(np.array([1.5])) # Value must be integer
332332

333-
def test_sampling_consistency(self):
334-
"""Test that sampling from the distribution produces reasonable results"""
335-
r = 2.0
336-
alpha = 1.0
337-
time_covariate_vector = [0.0, 1.0, 2.0]
338-
339-
try:
340-
dist = GrassiaIIGeometric.dist(
341-
r=r, alpha=alpha, time_covariate_vector=time_covariate_vector
342-
)
343-
344-
direct_samples = dist.eval()
345-
346-
if not isinstance(direct_samples, np.ndarray):
347-
direct_samples = np.array([direct_samples])
348-
349-
if direct_samples.ndim == 0:
350-
direct_samples = direct_samples.reshape(1)
351-
352-
assert (
353-
direct_samples.size > 0
354-
), f"Direct sampling produced no samples for {time_covariate_vector}"
355-
assert np.all(
356-
direct_samples > 0
357-
), f"Direct sampling produced non-positive values for {time_covariate_vector}"
358-
assert np.all(
359-
direct_samples.astype(int) == direct_samples
360-
), f"Direct sampling produced non-integer values for {time_covariate_vector}"
361-
362-
except Exception as e:
363-
import traceback
364-
365-
traceback.print_exc()
366-
raise
367-
368-
try:
369-
with pm.Model():
370-
x = GrassiaIIGeometric(
371-
"x", r=r, alpha=alpha, time_covariate_vector=time_covariate_vector
372-
)
373-
374-
trace = pm.sample(
375-
chains=1, draws=50, tune=0, random_seed=42, progressbar=False
376-
).posterior
377-
378-
# Extract samples and ensure correct shape
379-
samples = trace["x"].values
380-
381-
assert (
382-
samples is not None
383-
), f"No samples were returned from MCMC for {time_covariate_vector}"
384-
assert (
385-
samples.size > 0
386-
), f"MCMC sampling produced empty array for {time_covariate_vector}"
387-
388-
if samples.ndim > 1:
389-
samples = samples.reshape(-1) # Flatten if needed
390-
391-
# Check basic properties of samples
392-
assert samples.size > 0, f"No samples after reshaping for {time_covariate_vector}"
393-
assert np.all(
394-
samples > 0
395-
), f"Found non-positive values in samples for {time_covariate_vector}"
396-
assert np.all(
397-
samples.astype(int) == samples
398-
), f"Found non-integer values in samples for {time_covariate_vector}"
399-
400-
# Check mean and variance are reasonable
401-
mean = np.mean(samples)
402-
var = np.var(samples)
403-
assert (
404-
0 < mean < np.inf
405-
), f"Mean {mean} is not in valid range for {time_covariate_vector}"
406-
assert (
407-
0 < var < np.inf
408-
), f"Variance {var} is not in valid range for {time_covariate_vector}"
409-
410-
# Additional checks for distribution properties
411-
assert mean > 1, f"Mean {mean} is not greater than 1 for {time_covariate_vector}"
412-
assert var > 0, f"Variance {var} is not positive for {time_covariate_vector}"
413-
414-
except Exception as e:
415-
import traceback
416-
417-
traceback.print_exc()
418-
raise
419-
420333
@pytest.mark.parametrize(
421334
"r, alpha, time_covariate_vector, size, expected_shape",
422335
[

0 commit comments

Comments
 (0)