Source code for alts.core.oracle.interpolation_strategy

#Version 1.1.1 conform as of 29.11.2024
"""
*alts.core.oracle.interpolation_strategy*
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from alts.core.data.data_sampler import DataSampler

from alts.core.configuration import Configurable, post_init, Required, is_set

from alts.core.data.constrains import QueryConstrain, QueryConstrained

if TYPE_CHECKING:
    from typing import Tuple, List, Dict
    from nptyping import NDArray, Number, Shape

[docs] class InterpolationStrategy(Configurable, QueryConstrained): """ InterpolationStrategy(data_sampler) | **Description** | An ``InterpolatingStrategy`` is an **ambivalent** source of data depending on the :doc:`DataSampler </core/data/data_sampler>` it interpolates within. | This is a base class not intended for direct use. :param data_sampler: A sample of the data which contains the to be interpolated data points :type data_sampler: :doc:`DataSampler </core/data/data_sampler>` """ data_sampler: DataSampler = post_init()
[docs] def interpolate(self, data_points: Tuple[NDArray[Shape["query_nr, sample_nr, ... query_dim"], Number], NDArray[Shape["query_nr, sample_nr, ... result_dim"], Number]]) -> Tuple[NDArray[Shape["query_nr, ... query_dim"], Number], NDArray[Shape["query_nr, ... result_dim"], Number]]: # type: ignore """ interpolate(self, data_points) -> data_points | **Description** | Interpolates a tuple of two data points and returns the interpolated tuple of length 2. | This implementation of ``interpolate`` returns the twople as is. If this is the result you wish to achieve, please use :class:`NoInterpolation` instead. :param data_points: A tuple of two data_points to be interpolated :type data_points: Tuple(`NDArray <https://numpy.org/doc/stable/reference/arrays.ndarray.html>`_, `NDArray <https://numpy.org/doc/stable/reference/arrays.ndarray.html>`_) :return: The interpolated tuple of length 2 :rtype: Tuple(`NDArray <https://numpy.org/doc/stable/reference/arrays.ndarray.html>`_, `NDArray <https://numpy.org/doc/stable/reference/arrays.ndarray.html>`_) """ return data_points
[docs] def query_constrain(self) -> QueryConstrain: """ query_constrain(self) -> QueryConstrain | **Description** | See :func:`DataSource.query()` :param queries: Requested Query :type queries: `NDArray <https://numpy.org/doc/stable/reference/arrays.ndarray.html>`_ :return: Processed Query, Result :rtype: A tuple of two `NDArray <https://numpy.org/doc/stable/reference/arrays.ndarray.html>`_ """ return self.data_sampler.query_constrain()
def __call__(self, data_sampler: Required[DataSampler] = None, **kwargs) -> Self: # type: ignore """ __call__(self, data_sampler, **kwargs) -> Self | **Description** | Returns an ``InterpolatingDataSource`` constrained to the given :doc:`DataSampler </core/data/data_sampler>`. :param data_sampler: A sample of the data which contains the to-be interpolated data points :type data_sampler: :doc:`DataSampler </core/data/data_sampler>` :return: Instance of ``InterpolatingDataSource`` constrained to ``data_sampler`` :rtype: ``InterpolatingDataSource`` """ obj = super().__call__(**kwargs) obj.data_sampler = is_set(data_sampler) return obj
[docs] class NoInterpolation(InterpolationStrategy): """ NoInterpolation() | **Description** | ``NoInterpolation`` is an interpolator that does nothing to the given data. :param data_sampler: A sample of the data which contains the to-be interpolated data points :type data_sampler: :doc:`DataSampler </core/data/data_sampler>` """ ...