dense1.density_estimator module

class Model(density, correlated_field, select_subset, amplitude_total_offset, normalized_amplitudes)

Bases: tuple


Alias for field number 3


Alias for field number 1


Alias for field number 0


Alias for field number 4


Alias for field number 2

build_density_estimator(shape, pixel_distances=None, pad=1.0, cf_fluctuations=None, cf_azm_uniform=None)[source]

Construct the model for a density estimator

  • shape (int or tuple of int or tuple of tuple of int) – Shape of the to-be-modeled data. Note, the level of nesting matters! While ((128, 128), ) denotes a shared kernel for both axis, (128, 128) denotes separate kernels for both axis.

  • pixel_distances (float or tuple of float, optional) – Distances between individual pixels.

  • pad (float or tuple of float, optional) – Padding factor.

  • cf_fluctuations (dict or tuple of dict, optional) – Parameters for the Matern kernel of the density field.

  • cf_azm_uniform (tuple of float, optional) – Parameters for the a-priori uniform amplitude total offset.


model – Collection of operators that represent the model. Most importantly model features an attribute .density which corresponds to the NIFTy representation of the density estimator.

Return type


draw_synthetic_sample(model, seed=60, pretty=False)[source]

Draw synthetic data (i.e. produce a prior sample in data space)

  • model (Model) – Collection of operators representing the model.

  • seed (int or np.random.SeedSequence, optional) – Random state with which to draw the synthetic truth and the noise.

  • pretty (bool or set) – Set of latent parameters which are artificially dampened as to produce untrue prior samples that look prettier. If a boolean and true then a sane set of latent parameters is chosen.


  • synth_data (np.ndarray) – Array of integers for the synthetic Poissonian counts.

  • synth_truth (np.ndarray) – Array of the true expectation value underlying the Poissonian counts.

fit(model, data, n_samples=5, n_max_iterations=20, init_position=None, init_seed=31617, kl_kw=None, sampling_kw=None, minimizer_kw=None)[source]

Fit the model to data and return approximate posterior samples

  • model (Model) – Collection of operators representing the model.

  • data (np.ndarray) – Poissonian count data to which to fit the model to.

  • init_position (ift.MultiField, optional) – Optional starting position in the form of a MultiField from NIFTy.

  • init_seed (int or np.random.SeedSequence, optional) – Random state with which to draw the synthetic truth and the noise.

  • kl_kw (dict, optional) – Parameters for the Kullback-Leibler computation.

  • sampling_kw (dict, optional) – Parameters for the sampling iteration controller.

  • minimizer_kw (dict, optional) – Parameters for the minimizer iteration controller.


  • density_samples (tuple of np.ndarray) – Samples from the approximate posterior distribution.

  • lat_samples (tuple of ift.MultiField) – Latent samples compatible with the collection of operators representation in the model. These can be used to access intermediate posteriors within the model itself.