Utility Classes¶
class WithArgs¶
-
class
WithArgs¶ This class wraps around a user-provided function and provides an attribute
argsso that simuPOP knows which parameters to send to the function. This is only needed if the function can not be defined with allowed parameters.-
WithArgs(func, args)¶ Return a callable object that wraps around function
func. Parameterargsshould be a list of parameter names.
-
class WithMode¶
-
class
WithMode¶ This class wraps around a user-provided output string, function or file handle (acceptable by parameter
outputof operators) so that simuPOP knows which mode the output should be written to. For example, if the output of the operator is a binary compressed stream,WithMode(output, 'b')could be used to tell the operators to output bytes instead of string. This is most needed for Python 3 because files in Python 2 accepts string even if they are opened in binary mode.-
WithMode(output, mode='')¶ Return an object that wraps around
outputand tells simuPOP to output string inmode. This class currently only supportmode=''for text mode andmode='b'for binary output.
-
class RNG¶
-
class
RNG¶ This random number generator class wraps around a number of random number generators from GNU Scientific Library. You can obtain and change the RNG used by the current simuPOP module through the
getRNG()function, or create a separate random number generator and use it in your script.-
RNG(name=None, seed=0)¶ Create a RNG object using specified name and seed. If rng is not given, environmental variable
GSL_RNG_TYPEwill be used if it is available. Otherwise, generatormt19937will be used. If seed is not given,/dev/urandom,/dev/random, or other system random number source will be used to guarantee that random seeds are used even if more than one simuPOP sessions are started simultaneously. Names of supported random number generators are available frommoduleInfo()['availableRNGs'].
-
name()¶ Return the name of the current random number generator.
-
randBinomial(n, p)¶ Generate a random number following a binomial distribution with parameters n and p.
-
randChisq(nu)¶ Generate a random number following a Chi-squared distribution with nu degrees of freedom.
-
randExponential(mu)¶ Generate a random number following a exponential distribution with parameter mu.
-
randGamma(a, b)¶ Generate a random number following a gamma distribution with a shape parameters a and scale parameter b.
-
randGeometric(p)¶ Generate a random number following a geometric distribution with parameter p.
-
randInt(n)¶ return a random number in the range of
[0, 1, 2, ... n-1]
-
randMultinomial(N, p)¶ Generate a random number following a multinomial distribution with parameters N and p (a list of probabilities).
-
randNormal(mu, sigma)¶ Generate a random number following a normal distribution with mean mu and standard deviation sigma.
-
randPoisson(mu)¶ Generate a random number following a Poisson distribution with parameter mu.
-
randTruncatedBinomial(n, p)¶ Generate a positive random number following a zero-truncated binomial distribution with parameters n and p.
-
randTruncatedPoisson(mu)¶ Generate a positive random number following a zero-truncated Poisson distribution with parameter mu.
-
randUniform()¶ Generate a random number following a rng_uniform [0, 1) distribution.
-
seed()¶ Return the seed used to initialize the RNG. This can be used to repeat a previous session.
-
set(name=None, seed=0)¶ Replace the existing random number generator using RNG*name* with seed seed. If seed is 0, a random seed will be used. If name is empty, use the existing RNG but reset the seed.
-
class WeightedSampler¶
-
class
WeightedSampler¶ A random number generator that returns
0,1, …,k-1with probabilites that are proportional to their weights. For example, a weighted sampler with weights4,3,2and1will return numbers0,1,2and3with probabilities0.4,0.3,0.2and0.1, respectively. If an additional parameterNis specified, the weighted sampler will return exact proportions of numbers ifNnumbers are returned. The version without additional parameter is similar to thesample(prob, replace=FALSE)function of the R statistical package.-
WeightedSampler(weights=[], N=0)¶ Creates a weighted sampler that returns
0,1, …k-1when a list ofkweights are specified (weights). weights do not have to add up to 1. If a non-zero N is specified, exact proportions of numbers will be returned in N returned numbers.
-
draw()¶ Returns a random number between
0andk-1with probabilities that are proportional to specified weights.
-
drawSamples(n=1)¶ Returns a list of n random numbers
-