nessai.samplers.base
====================

.. py:module:: nessai.samplers.base

.. autoapi-nested-parse::

   Base nested sampler object

   ..
       !! processed by numpydoc !!


Classes
-------

.. autoapisummary::

   nessai.samplers.base.BaseNestedSampler


Module Contents
---------------

.. py:class:: BaseNestedSampler(model: nessai.model.Model, nlive: int, output: str = None, seed: int = None, rng: Optional[numpy.random.Generator] = None, checkpointing: bool = True, checkpoint_interval: int = 600, checkpoint_on_iteration: bool = False, checkpoint_callback: Optional[Callable] = None, logging_interval: int = None, log_on_iteration: bool = True, resume_file: str = None, plot: bool = True, n_pool: Optional[int] = None, pool: Optional[Any] = None)

   Bases: :py:obj:`abc.ABC`


   
   Base nested sampler class.


   :Parameters:

       **model** : :obj:`nessai.model.Model`
           User-defined model

       **output** : str, optional
           Path for the output. If not specified the current working directory
           is used.

       **seed** : int, optional
           Seed used to seed numpy and torch.

       **checkpointing** : bool, optional
           Boolean to toggle checkpointing, must be enabled to resume the sampler.
           If false the sampler is still saved at the end of sampling.

       **checkpoint_interval** : int
           The interval used for checkpointing. By default this is a time interval
           in seconds. If :code:`checkpoint_on_iteration=True` this corresponds to
           the number of iterations between checkpointing.

       **checkpoint_on_iteration** : bool
           If true the checkpointing interval is checked against the number of
           iterations

       **checkpoint_callback** : Callback
           Callback function to be used instead of the default function. The
           function will be called in the code:`checkpoint` method as:
           :code`checkpoint_callback(self)`.

       **logging_interval** : int, optional
           The interval in seconds used for periodic logging. If not specified,
           then periodic logging is disabled.

       **log_on_iteration** : bool
           If true logging will occur based on the iteration. If false logging
           will be periodic if `logging_interval` is set. In case where neither
           logging is enabled, `log_on_iteration` will be set to true with an
           interval of :code:`nlive`.

       **resume_file** : str, optional
           Name of the file the sampler will be saved to and resumed from.

       **plot** : bool, optional
           Boolean to enable or disable plotting.

       **n_pool** : int, optional
           Number of threads to when for creating the multiprocessing pool.

       **pool** : object
           User defined multiprocessing pool that will be used when evaluating
           the likelihood.














   ..
       !! processed by numpydoc !!

   .. py:property:: likelihood_evaluation_time

      
      Current log-likelihood time
















      ..
          !! processed by numpydoc !!


   .. py:property:: total_likelihood_evaluations

      
      Total number of likelihood evaluations
















      ..
          !! processed by numpydoc !!


   .. py:attribute:: likelihood_calls

      
      Alias for :code:`total_likelihood_evaluations`
















      ..
          !! processed by numpydoc !!


   .. py:property:: posterior_effective_sample_size
      :abstractmethod:


      
      The effective sample size of the posterior distribution
















      ..
          !! processed by numpydoc !!


   .. py:method:: configure_output(output: Union[str, None], resume_file: Union[str, None] = None)

      
      Configure the output folder


      :Parameters:

          **output** : str
              Directory where the results will be stored

          **resume_file** : str, optional
              Specific file to use for checkpointing. If not specified the
              default is used (nested_sampler_resume.pkl)














      ..
          !! processed by numpydoc !!


   .. py:method:: update_output(output: str) -> None

      
      Update the output directory and resume file.


      :Parameters:

          **output: str**
              Path to the output directory














      ..
          !! processed by numpydoc !!


   .. py:method:: configure_rng(seed: Optional[int] = None, rng: Optional[numpy.random.Generator] = None)

      
      Configure the random number generation.

      If a seed is not specified, a random seed is generated using the
      specified random number generator, or the default numpy random number
      if not specified. In the latter case, the seed is then used to seed
      the new numpy random number generator.

      ..versionadded:: 0.14.0

      :Parameters:

          **seed** : Optional[int]
              The random seed. If not specified, a random seed is generated.

          **rng: Optional[np.random.Generator]**
              Random number generator. If not specified, the default numpy
              random number generator is used with the specified seed.














      ..
          !! processed by numpydoc !!


   .. py:method:: configure_random_seed(seed: Optional[int] = None) -> None

      
      Initialise the random seed

      ..deprecated:: 0.14.0
          Deprecated in favour of
          :py:meth:`~nessai.samplers.base.BaseNestedSampler.configure_rng`.

      :Parameters:

          **seed** : Optional[int]
              The random seed. If not specified, a random seed is generated.














      ..
          !! processed by numpydoc !!


   .. py:method:: configure_periodic_logging(logging_interval, log_on_iteration)

      
      Configure the periodic logging.


      :Parameters:

          **logging_interval** : int, optional
              The interval in seconds used for periodic logging. If not
              specified, then periodic logging is disabled.

          **log_on_iteration** : bool
              If true logging will occur based on the iteration. If false logging
              will be periodic if `logging_interval` is set. In case where
              neither logging is enabled, `log_on_iteration` will be set to true
              with an interval of :code:`nlive`.














      ..
          !! processed by numpydoc !!


   .. py:method:: periodically_log_state()

      
      Log the state of the sampler.

      Calls :code:`log_state` if the elapsed interval in time (or iterations)
      is more than the specified interval.















      ..
          !! processed by numpydoc !!


   .. py:method:: initialise_history() -> None

      
      Initialise the dictionary to store history
















      ..
          !! processed by numpydoc !!


   .. py:method:: update_history() -> None

      
      Update the history dictionary
















      ..
          !! processed by numpydoc !!


   .. py:method:: checkpoint(periodic: bool = False, force: bool = False, save_existing: bool = True)

      
      Checkpoint the classes internal state.


      :Parameters:

          **periodic** : bool
              Indicates if the checkpoint is regular periodic checkpointing
              or forced by a signal. If forced by a signal, it will show up on
              the state plot.

          **force** : bool
              Force the sampler to checkpoint.

          **save_existing** : bool
              If True, the previous checkpoint will be copied to `.old`.
              If False, the new checkpoint will override the previous file.














      ..
          !! processed by numpydoc !!


   .. py:method:: resume_from_pickled_sampler(sampler: Any, model: nessai.model.Model, output: Optional[str] = None, checkpoint_callback: Optional[Callable] = None)
      :classmethod:


      
      Resume from pickle data.


      :Parameters:

          **data** : Any
              Pickle data

          **model** : :obj:`nessai.model.Model`
              User-defined model

          **output** : Optional[str]
              New output directory. If not specified, the output directory will
              be the same as the previous run.

          **checkpoint_callback** : Optional[Callable]
              Checkpoint callback function. If not specified, the default method
              will be used.



      :Returns:

          Instance of BaseNestedSampler
              ..











      ..
          !! processed by numpydoc !!


   .. py:method:: resume(filename: str, model: nessai.model.Model, output: Optional[str] = None, **kwargs)
      :classmethod:


      
      Resumes the interrupted state from a checkpoint pickle file.


      :Parameters:

          **filename** : str
              Pickle file to resume from

          **model** : :obj:`nessai.model.Model`
              User-defined model

          **output** : Optional[str]
              New output directory. If not specified, the output directory will
              be the same as the previous run.



      :Returns:

          obj
              Instance of BaseNestedSampler











      ..
          !! processed by numpydoc !!


   .. py:method:: close_pool(code=None)

      
      Close the multiprocessing pool.
















      ..
          !! processed by numpydoc !!


   .. py:method:: get_result_dictionary()

      
      Return a dictionary that contains results.

      Only includes version, seed and sampling time. Child classes should
      call this method and add to the dictionary.















      ..
          !! processed by numpydoc !!


