hyrax.verbs.reduction_algorithms.algorithm_registry
===================================================

.. py:module:: hyrax.verbs.reduction_algorithms.algorithm_registry


Attributes
----------

.. autoapisummary::

   hyrax.verbs.reduction_algorithms.algorithm_registry.logger
   hyrax.verbs.reduction_algorithms.algorithm_registry.ALGORITHM_REGISTRY


Classes
-------

.. autoapisummary::

   hyrax.verbs.reduction_algorithms.algorithm_registry.ReductionAlgorithm


Functions
---------

.. autoapisummary::

   hyrax.verbs.reduction_algorithms.algorithm_registry.is_reducer_class
   hyrax.verbs.reduction_algorithms.algorithm_registry.fetch_reducer_class


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

.. py:data:: logger

.. py:data:: ALGORITHM_REGISTRY
   :type:  dict[str, type[ReductionAlgorithm]]

.. py:class:: ReductionAlgorithm(config: dict, reduction_results: ResultDatasetWriter | None = None)

   Abstract base class for all reduction algorithms.


   .. py:attribute:: _config


   .. py:attribute:: _reduction_results
      :value: None



   .. py:attribute:: reducer
      :value: None



   .. py:property:: config

      Return the configuration dictionary for this reduction algorithm.


   .. py:property:: reduction_results

      Return the result dataset writer for this reduction algorithm.


   .. py:method:: __init_subclass__()
      :classmethod:



   .. py:method:: fit(data_sample: numpy.ndarray)

      Fit the reduction algorithm to the data.
      Set the internal state of the reducer based on the provided data sample.

      :param data_sample: The data sample used to fit the model.
      :type data_sample: numpy.ndarray



   .. py:method:: transform(args: dict, num_batches: int)
      :abstractmethod:


      Transform the data with a fitted reducer.

      :param args: A dictionary containing the data to be transformed.
      :type args: dict
      :param num_batches: The total number of batches that the data is split into for transformation.
      :type num_batches: int



   .. py:method:: save_model(model_path: Union[pathlib.Path, str] | None = None)

      Save the reducer model to a picklefile.

      :param model_path: The path to save the model to.
      :type model_path: Path or str



   .. py:method:: load_model(expected_input_dim: int, model_path: Union[pathlib.Path, str] | None = None)

      Load the reducer model from a file.

      :param expected_input_dim: The expected number of input features for the loaded model.
      :type expected_input_dim: int
      :param model_path: The path to the file to load the model from.
      :type model_path: Path or str, optional

      :returns: The reduction algorithm instance with the loaded model.
      :rtype: ReductionAlgorithm



   .. py:method:: _load_pickle(model_path: Union[pathlib.Path, str])

      Helper function to wrap loading a pickle file from a given path for easier testing.

      :param model_path: The file path to the pickle file.
      :type model_path: str or Path

      :returns: The object loaded from the pickle file.
      :rtype: object



   .. py:method:: _transform_batch(batch_tuple: tuple)

      Private helper to transform a single batch with fitted reducer.

      :param batch_tuple: first element is the IDs of the batch as a numpy array
                          second element is the inference results to transform as a numpy array with shape (batch_len, N)
                          where N is the total number of dimensions in the inference result. Caller flattens all inference
                          result axes for us.
      :type batch_tuple: tuple()

      :returns: first element is the ids of the batch as a numpy array
                second element is the results of running the transform on the input as a numpy array.
      :rtype: tuple



   .. py:method:: _log_memory_usage(message: str = '')
      :staticmethod:


      Log the current resident set size (RSS) memory usage of the current process in gigabytes.

      :param message: A descriptive message to include in the log output for context.
      :type message: str, optional

      .. rubric:: Notes

      This method is intended for debugging and performance monitoring.



.. py:function:: is_reducer_class(cli_name: str) -> bool

   Returns true if the reducer algorithm has a class based implementation

   :param cli_name: The name of the reducer algorithm on the command line interface
   :type cli_name: str

   :returns: True if the reducer algorithm has a class-based implementation
   :rtype: bool


.. py:function:: fetch_reducer_class(cli_name: str) -> type[ReductionAlgorithm]

   Fetch the class implementing the reducer algorithm specified.
   The class must be a subclass of ReductionAlgorithm and must be registered in the ALGORITHM_REGISTRY.

   :param cli_name: The name of the reducer algorithm on the command line interface
   :type cli_name: str

   :returns: The class implementing the reducer algorithm.
   :rtype: type[ReductionAlgorithm]


