### Navigation

- index
- modules |
- next |
- previous |
- SciPy v0.7 Reference Guide (DRAFT) »
- Maximum entropy models (`scipy.maxentropy`) »

# scipy.maxentropy.bigmodel.setsampleFgen

`bigmodel.``setsampleFgen`(sampler, staticsample=True)

  Initializes the Monte Carlo sampler to use the supplied generator of samples’ features and log probabilities. This is an alternative to defining a sampler in terms of a (fixed size) feature matrix sampleF and accompanying vector samplelogprobs of log probabilities.

  Calling sampler.next() should generate tuples (F, lp), where F is an (m x n) matrix of features of the n sample points x_1,...,x_n, and lp is an array of length n containing the (natural) log probability density (pdf or pmf) of each point under the auxiliary sampling distribution.

  The output of sampler.next() can optionally be a 3-tuple (F, lp, sample) instead of a 2-tuple (F, lp). In this case the value ‘sample’ is then stored as a class variable self.sample. This is useful for inspecting the output and understanding the model characteristics.

  If matrixtrials > 1 and staticsample = True, (which is useful for estimating variance between the different feature estimates), sampler.next() will be called once for each trial (0,...,matrixtrials) for each iteration. This allows using a set of feature matrices, each of which stays constant over all iterations.

  We now insist that sampleFgen.next() return the entire sample feature matrix to be used each iteration to avoid overhead in extra function calls and memory copying (and extra code).

  An alternative was to supply a list of samplers, sampler=[sampler0, sampler1, ..., sampler_{m-1}, samplerZ], one for each feature and one for estimating the normalization constant Z. But this code was unmaintained, and has now been removed (but it’s in Ed’s CVS repository :).

  Example use: >>> import spmatrix >>> model = bigmodel() >>> def sampler(): ... n = 0 ... while True: ... f = spmatrix.ll_mat(1,3) ... f[0,0] = n+1; f[0,1] = n+1; f[0,2] = n+1 ... yield f, 1.0 ... n += 1 ... >>> model.setsampleFgen(sampler()) >>> type(model.sampleFgen) <type ‘generator’> >>> [model.sampleF[0,i] for i in range(3)] [1.0, 1.0, 1.0]

  We now set matrixtrials as a class property instead, rather than passing it as an argument to this function, where it can be written over (perhaps with the default function argument by accident) when we re-call this func (e.g. to change the matrix size.)

### Navigation

- index
- modules |
- next |
- previous |
- SciPy v0.7 Reference Guide (DRAFT) »
- Maximum entropy models (`scipy.maxentropy`) »