Skip to content

Latest commit

 

History

History
40 lines (22 loc) · 3.03 KB

new_model.rst

File metadata and controls

40 lines (22 loc) · 3.03 KB

Specifying a new statistical model

pySELFI makes it possible to include new statistical models, including in particular new (Gaussian) priors and new methods for the core architecture (such as prior optimization, described in Leclercq et al. 2019_).

The code for new statistical models can go into new python modules, placed for example in a subdirectory of src/pyselfi/ such as src/pyselfi/power_spectrum/, which is provided within the code.

Adding a new prior can be done by defining a new class prior. This class shall have a method compute (not taking any argument except self). The only requirement is that after compute has been called by the pySELFI core infrastructure, three attributes have been defined (by the constructor, by methods called by compute, or by compute itself):

  • self.mean: an array of size S giving the prior mean (recall that in the SELFI algorithm, the prior mean shall also be the expansion point θ0, so consistency is required here),
  • self.covariance: an array of size S × S giving the prior covariance matrix S,
  • self.inv_covariance: an array of size S × S giving the prior inverse covariance matrix S − 1,

pyselfi.selfi

The prior class shall also have a method save (with arguments self, fname) and a class method load (with arguments cls, fname) to save to and load prior data from the pySELFI hdf5 output file (in particular the three mandatory attributes, see above). Instances of the new prior class can then be used to define and manipulate selfi objects, as described in this page. Working examples of prior classes can be found in src/pyselfi/power_spectrum/prior.py and src/pyselfi/lotkavolterra/prior.py.

Adding new features to pySELFI can simply be done by defining a child of the selfi class and using it instead of the parent class. Working examples of child selfi classes can be found in src/pyselfi/power_spectrum/selfi.py and src/pyselfi/lotkavolterra/selfi.py.

pyselfi

Prior class template

A template for a new prior class is provided below and downloadable here: new_blackbox.py <https://github.com/florent-leclercq/pyselfi/tree/master/src/pyselfi_examples/templates/new_prior.py>.

Selfi class template

A template for a new child_selfi class is provided below and downloadable here: new_selfi.py <https://github.com/florent-leclercq/pyselfi/tree/master/src/pyselfi_examples/templates/new_selfi.py>.