petitRADTRANS.sbi.flow_matching_posterior
=========================================

.. py:module:: petitRADTRANS.sbi.flow_matching_posterior

.. autoapi-nested-parse::

   Flow-matching posterior estimator (experimental).



Classes
-------

.. autoapisummary::

   petitRADTRANS.sbi.flow_matching_posterior.FlowMatchingPosterior


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

.. py:class:: FlowMatchingPosterior(parameter_dim: int, embedding_dim: int = 128, hidden_dim: int = 128, num_velocity_layers: int = 3, learning_rate: float = 0.001, batch_size: int = 32, num_epochs: int = 5, parameter_space: str = 'unconstrained', integration_steps: int = 32, early_stopping_patience: int | None = None, early_stopping_min_delta: float = 0.0, checkpoint_directory: str | None = None, checkpoint_backend: str = 'auto', resume_from_checkpoint: bool = False, seed: int = 0, task_metadata: Mapping[str, Any] | None = None)

   Bases: :py:obj:`petitRADTRANS.sbi.posterior_base.PersistentPosteriorEstimator`


   Conditional flow-matching posterior skeleton.

   .. warning::

       This estimator is **experimental**. It does not expose ``log_prob``
       and the ODE integration scheme is a simple midpoint rule.  Expect
       the API and numerical behaviour to change in future releases.

   This estimator family trains a conditional vector field on straight-line
   interpolation paths between Gaussian noise and target parameters, then
   generates posterior samples by integrating the learned field from noise to
   the terminal parameter state.


   .. py:attribute:: estimator_family
      :value: 'flow_matching'



   .. py:attribute:: embedding_dim
      :value: 128



   .. py:attribute:: hidden_dim
      :value: 128



   .. py:attribute:: num_velocity_layers
      :value: 3



   .. py:attribute:: learning_rate


   .. py:attribute:: batch_size
      :value: 32



   .. py:attribute:: num_epochs
      :value: 5



   .. py:attribute:: integration_steps
      :value: 32



   .. py:attribute:: early_stopping_patience
      :value: None



   .. py:attribute:: early_stopping_min_delta


   .. py:attribute:: checkpoint_directory
      :value: None



   .. py:attribute:: checkpoint_backend
      :value: 'auto'



   .. py:attribute:: resume_from_checkpoint
      :value: False



   .. py:attribute:: model


   .. py:method:: _batch_embeddings(model: _FlowMatchingModel, observations: Any) -> jax.numpy.ndarray
      :staticmethod:



   .. py:method:: _loss(model: _FlowMatchingModel, batch: petitRADTRANS.sbi.posterior_base.PosteriorBatch) -> jax.numpy.ndarray
      :staticmethod:



   .. py:method:: fit(dataset: Any) -> petitRADTRANS.sbi.posterior_base.TrainingArtifacts

      Train the posterior estimator on a simulation dataset.



   .. py:method:: _build_estimator_config() -> dict[str, Any]

      Return backend-specific configuration for metadata persistence.



   .. py:method:: _resolve_estimator_config(metadata: Mapping[str, Any]) -> dict[str, Any]
      :staticmethod:



   .. py:method:: _build_serialized_metadata(artifact_metadata) -> dict[str, Any]


   .. py:method:: from_serialized_metadata(metadata: Mapping[str, Any]) -> FlowMatchingPosterior
      :classmethod:


      Rebuild an estimator instance from persisted metadata only.



   .. py:method:: save_backend_state(output_path: pathlib.Path) -> None

      Persist backend-specific model state into the output directory.



   .. py:method:: load_backend_state(input_path: pathlib.Path) -> None

      Restore backend-specific model state from the input directory.



   .. py:method:: encode_observation(blocks: list[petitRADTRANS.sbi.observation.ObservationBlock]) -> petitRADTRANS.sbi.observation.EncodedObservation

      Encode a structured observation into the estimator input space.



   .. py:method:: batch_encode_observation(blocks_list: list[list[petitRADTRANS.sbi.observation.ObservationBlock]]) -> list[petitRADTRANS.sbi.observation.EncodedObservation]

      Encode a batch of observations using a single vmapped forward pass.



   .. py:method:: sample_posterior(observation: petitRADTRANS.sbi.observation.EncodedObservation, n_samples: int, seed: int | None = None) -> petitRADTRANS.sbi.posterior_base.PosteriorSamples

      Sample the amortized posterior for one encoded observation.



   .. py:method:: log_prob(observation: petitRADTRANS.sbi.observation.EncodedObservation, parameters: Any) -> Any

      Evaluate posterior log-density when supported by the backend.



