sequince.posterior
==================

.. py:module:: sequince.posterior


Attributes
----------

.. autoapisummary::

   sequince.posterior.LogProposalLike
   sequince.posterior.JointLogDensityFn


Classes
-------

.. autoapisummary::

   sequince.posterior.TemperedPosterior


Functions
---------

.. autoapisummary::

   sequince.posterior.draw_additional_samples


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

.. py:data:: LogProposalLike

.. py:data:: JointLogDensityFn

.. py:class:: TemperedPosterior

   Bases: :py:obj:`sequince.target.TemperedTarget`


   Wrapper exposing posterior building blocks for SMC workflows.

   :param log_prior: Callable returning ``log p(x)`` for each particle.
   :param log_likelihood: Callable returning ``log l(x)`` for each particle. May be omitted when
                          ``log_likelihood_and_proposal`` is supplied.
   :param log_proposal: Optional callable or proposal object returning ``log q(x)``. When
                        supplied the intermediate targets follow the bridge
                        ``q(x)^{1-β} [p(x)L(x)]^{β}``.
   :param log_proposal_override_key: Context metadata key containing a runtime proposal override.
   :param log_likelihood_and_proposal: Alternative to separate likelihood and proposal inputs: a callable
                                       returning ``(log l(x), log q(x))`` from shared computation. Accepts
                                       particles and optionally context. Requesting either component evaluates
                                       and caches both. A runtime proposal override takes precedence over the
                                       returned proposal; refreshing only that override skips the joint call.
   :param log_density_ratio: Optional direct terminal-to-initial log-density ratio for weighting.
                             Accepts particles and optionally context. When supplied, weighting skips
                             full density preparation; MCMC still evaluates the posterior normally.
                             The callback must account for any runtime proposal override itself.


   .. py:attribute:: log_prior
      :type:  sequince.target.TargetComponentFn


   .. py:attribute:: log_likelihood
      :type:  sequince.target.TargetComponentFn | None
      :value: None



   .. py:attribute:: log_proposal
      :type:  LogProposalLike | None
      :value: None



   .. py:attribute:: log_proposal_override_key
      :type:  str
      :value: 'log_proposal_override'



   .. py:attribute:: log_likelihood_and_proposal
      :type:  JointLogDensityFn | None
      :value: None



   .. py:attribute:: log_density_ratio
      :type:  sequince.target.TargetComponentFn | None
      :value: None



   .. py:method:: evaluation_components(context)

      Components needed for a full density evaluation, when known.

      These are the components used to compute ``log_prob``, such as during
      MCMC. They need not include every component the target supports:
      ``log_increment`` is included only when the density itself requires it.
      Other components can still be requested explicitly through
      ``prepare_evaluation(components=...)``.

      When ``components=None``, preparation uses this declaration to complete
      a partial cache and retain only these components. Returning None
      preserves the default full-evaluation contract for custom targets.



   .. py:method:: log_increment(particles, context, *, evaluation=None)

      Return the terminal-to-initial log-density ratio.



   .. py:method:: log_prob(particles, context, *, evaluation=None)

      Return the interpolated log density at the current beta.



   .. py:method:: resolve_log_proposal(log_proposal_override = None)

      Return the effective proposal callable for the current evaluation.



   .. py:method:: log_initial(particles, context, *, evaluation = None)

      Return the proposal or prior endpoint log density.

      When ``evaluation`` is omitted, all posterior components are evaluated
      from ``particles``. Supplying a matching evaluation avoids recomputing
      those components.



   .. py:method:: log_terminal(particles, context, *, evaluation = None)

      Return the posterior endpoint log density.

      When ``evaluation`` is omitted, all posterior components are evaluated
      from ``particles``. Supplying a matching evaluation avoids recomputing
      those components.



   .. py:method:: evaluate(particles, context, *, components = None, evaluation = None)

      Evaluate or refresh posterior components for a particle population.



   .. py:method:: freeze_log_prob(context, *, log_proposal_override = None)


.. py:function:: draw_additional_samples(*, log_prior = None, log_likelihood = None, log_proposal = None, posterior = None, result, rng, n_particles, mutation = 'minipcn', mutation_n_steps = 10, mutation_kwargs = None, particle_transform = 'affine', particle_transform_kwargs = None)

   Draw additional samples from the current particles to fill up to n_particles.

   :param log_prior: Callable evaluating the log prior density ``log p(x)``. If `posterior` is
                     not provided, both `log_prior` and `log_likelihood` must be given.
   :param log_likelihood: Callable evaluating the log likelihood ``log l(x)``. If `posterior` is
                          not provided, both `log_prior` and `log_likelihood` must be given.
   :param log_proposal: Optional callable or proposal object for ``log q(x)`` when importance
                        sampling proposals are used.
   :param posterior: TemperedPosterior object defining the target distribution.
   :param state: Current ParticleState containing particles and weights.
   :param context: StepContext providing shared information such as beta.
   :param rng: Random number generator.
   :param n_particles: Desired total number of particles after drawing additional samples.
   :param mutation: Mutation strategy to apply to the new particles.
   :param mutation_n_steps: Number of mutation steps to apply if mutation is used.
   :param mutation_kwargs: Additional keyword arguments to pass to the mutation step.
   :param particle_transform: ParticleTransform instance or string identifier for the transform to use
                              during mutation. If `None`, no transform is applied.


