Closed michael-petersen closed 1 month ago
It would also be nice to implement the flexibility option for the pdf input, such that the pdf function doesn't need to be vectorised.
The new support for non-vectorised pdfs (which is now the default) means that a minimal example to draw from a 3d prism looks like:
import numpy as np
from lintsampler import LintSampler
x = np.linspace(10,20,2)
y = np.linspace(100,200,2)
z = np.linspace(1000,2000,2)
# default: a pdf that takes the same number of arguments as dimensions
def rndmpdf_nonvec(x,y,z):
return np.random.uniform()
LintSampler(rndmpdf_nonvec,cells=(x,y,z)).sample()
But the call also works to use a vectorised pdf, for performance, if the vectorizedpdf
flag is set:
def rndmpdf(X):
return np.random.uniform(size=X.shape[0])
LintSampler(rndmpdf,cells=(x,y,z),vectorizedpdf=True).sample()
This version of
lintsampler
has a streamlined interface that more closely matches Pythonic patterns. At the simplest, we can now do something like draw 6 samples from a box:which entails constructing a probability density function (here built as a vectorised input to
numpy.random.uniform
), and defining the cell, before calling for a number of samples (here, 6).The wrapper class makes both the special case of a grid and the more flexible case of a set of cells fall under one call structure.