def slice_sampler(px, N = <NUM_LIT:1>, x = None):
values = np.zeros(N, dtype=np.int)<EOL>samples = np.arange(len(px))<EOL>px = np.array(px) / (<NUM_LIT:1.>*sum(px))<EOL>u = uniform(<NUM_LIT:0>, max(px))<EOL>for n in range(N):<EOL><INDENT>included = px>=u<EOL>choice = random.sample(list(range(np.sum(included))), <NUM_LIT:1>)[<NUM_LIT:0>]<EOL>values[n] = samples[included][choice]<EOL>u = uniform(<NUM_LIT:0>, px[included][choice])<EOL><DEDENT>if x:<EOL><INDENT>if len(x) == len(px):<EOL><INDENT>x=np.array(x)<EOL>values = x[values]<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT><DEDENT>return values<EOL>
Provides samples from a user-defined distribution.

slice_sampler(px, N = 1, x = None)

Inputs:
px = A discrete probability distribution.
N  = Number of samples to return, default is 1
x  = Optional list/array of observation values to return, where prob(x) = px.

Outputs:
If x=None (default) or if len(x) != len(px), it will return an array of integers
between 0 and len(px)-1. If x is supplied, it will return the
samples from x according to the distribution px.