Data

pymc3.data.get_data(filename)

Returns a BytesIO object for a package data file.

Parameters:filename (str) – file to load
Returns:BytesIO of the data
class pymc3.data.GeneratorAdapter(generator)

Helper class that helps to infer data type of generator with looking at the first item, preserving the order of the resulting generator

class pymc3.data.DataSampler(data, batchsize=50, random_seed=42, dtype='floatX')

Convenient picklable data sampler for minibatch inference.

This generator can be used for passing to pm.generator creating picklable theano computational grapf

Parameters:
  • data (array like) –
  • batchsize (sample size over zero axis) –
  • random_seed (int for numpy random generator) –
  • dtype (str representing dtype) –
  • Usage
  • -----
  • import pickle (>>>) –
  • from functools import partial (>>>) –
  • np.random.seed(42) # reproducibility (>>>) –
  • pm.set_tt_rng(42) (>>>) –
  • data = np.random.normal(size=(1000,)) + 10 (>>>) –
  • minibatches = DataSampler(data, batchsize=50) (>>>) –
  • with pm.Model() (>>>) –
  • sd = pm.Uniform('sd', 0, 10) (..) –
  • mu = pm.Normal('mu', sd=10) (..) –
  • obs_norm = pm.Normal('obs_norm', mu=mu, sd=sd, (..) –
  • observed=minibatches, (..) –
  • total_size=data.shape[0]) (..) –
  • adam = partial(pm.adam, learning_rate=.8) # easy problem (..) –
  • approx = pm.fit(10000, method='advi', obj_optimizer=adam) (..) –
  • new = pickle.loads(pickle.dumps(approx)) (>>>) –
  • new #doctest (>>>) –
  • object at 0x...> (<pymc3.variational.approximations.MeanField) –
  • new.sample_vp(draws=1000)['mu']mean() (>>>) –
  • 10.08339999101371
  • new.sample_vp(draws=1000)['sd']mean() (>>>) –
  • 1.2178044136104513