Skip to content

Objective

sgptools.methods.get_objective(objective_name)

Retrieves an objective function class by its string name.

Parameters:

Name Type Description Default
objective_name str

The name of the objective function (e.g., 'MI', 'SLogMI').

required

Returns:

Type Description
Type[Objective]

Type[Objective]: The class of the requested objective function.

Raises:

Type Description
KeyError

If the objective name is not found in the registered OBJECTIVES.

Usage
# Get the Mutual Information objective class
MIObjectiveClass = get_objective('MI')
# You can then instantiate it:
# mi_instance = MIObjectiveClass(X_objective=..., kernel=..., noise_variance=...)
Source code in sgptools/objectives.py
def get_objective(objective_name: str) -> Type[Objective]:
    """
    Retrieves an objective function class by its string name.

    Args:
        objective_name (str): The name of the objective function (e.g., 'MI', 'SLogMI').

    Returns:
        Type[Objective]: The class of the requested objective function.

    Raises:
        KeyError: If the objective name is not found in the registered OBJECTIVES.

    Usage:
        ```python
        # Get the Mutual Information objective class
        MIObjectiveClass = get_objective('MI')
        # You can then instantiate it:
        # mi_instance = MIObjectiveClass(X_objective=..., kernel=..., noise_variance=...)
        ```
    """
    return OBJECTIVES[objective_name]

sgptools.objectives.Objective

Base class for objective functions used in optimization. Subclasses must implement the __call__ method to define the objective.

Source code in sgptools/objectives.py
class Objective:
    """
    Base class for objective functions used in optimization.
    Subclasses must implement the `__call__` method to define the objective.
    """

    def __init__(self, X_objective: np.ndarray, kernel: gpflow.kernels.Kernel,
                 noise_variance: float, **kwargs: Any):
        """
        Initializes the base objective. This constructor primarily serves to define
        the expected parameters for all objective subclasses.

        Args:
            X_objective (np.ndarray): The input data points that define the context or
                                      environment for which the objective is calculated.
                                      Shape: (N, D) where N is number of points, D is dimension.
            kernel (gpflow.kernels.Kernel): The GPflow kernel function used in the objective.
            noise_variance (float): The observed data noise variance.
            **kwargs: Arbitrary keyword arguments.
        """
        pass

    def __call__(self, X: tf.Tensor) -> tf.Tensor:
        """
        Computes the objective value for a given set of input points `X`.
        This method must be implemented by subclasses.

        Args:
            X (tf.Tensor): The input points for which the objective is to be computed.
                           Shape: (M, D) where M is number of points, D is dimension.

        Returns:
            tf.Tensor: The computed objective value.

        Raises:
            NotImplementedError: If the method is not implemented by a subclass.
        """
        raise NotImplementedError

    def update(self, kernel: gpflow.kernels.Kernel,
               noise_variance: float) -> None:
        """
        Updates the kernel and noise variance parameters used by the objective function.
        This method should be overridden by subclasses if they maintain internal state
        that needs updating (e.g., cached kernel matrices or jitter values).

        Args:
            kernel (gpflow.kernels.Kernel): The updated GPflow kernel function.
            noise_variance (float): The updated data noise variance.
        """
        pass

__call__(X)

Computes the objective value for a given set of input points X. This method must be implemented by subclasses.

Parameters:

Name Type Description Default
X Tensor

The input points for which the objective is to be computed. Shape: (M, D) where M is number of points, D is dimension.

required

Returns:

Type Description
Tensor

tf.Tensor: The computed objective value.

Raises:

Type Description
NotImplementedError

If the method is not implemented by a subclass.

Source code in sgptools/objectives.py
def __call__(self, X: tf.Tensor) -> tf.Tensor:
    """
    Computes the objective value for a given set of input points `X`.
    This method must be implemented by subclasses.

    Args:
        X (tf.Tensor): The input points for which the objective is to be computed.
                       Shape: (M, D) where M is number of points, D is dimension.

    Returns:
        tf.Tensor: The computed objective value.

    Raises:
        NotImplementedError: If the method is not implemented by a subclass.
    """
    raise NotImplementedError

__init__(X_objective, kernel, noise_variance, **kwargs)

Initializes the base objective. This constructor primarily serves to define the expected parameters for all objective subclasses.

Parameters:

Name Type Description Default
X_objective ndarray

The input data points that define the context or environment for which the objective is calculated. Shape: (N, D) where N is number of points, D is dimension.

required
kernel Kernel

The GPflow kernel function used in the objective.

required
noise_variance float

The observed data noise variance.

required
**kwargs Any

Arbitrary keyword arguments.

{}
Source code in sgptools/objectives.py
def __init__(self, X_objective: np.ndarray, kernel: gpflow.kernels.Kernel,
             noise_variance: float, **kwargs: Any):
    """
    Initializes the base objective. This constructor primarily serves to define
    the expected parameters for all objective subclasses.

    Args:
        X_objective (np.ndarray): The input data points that define the context or
                                  environment for which the objective is calculated.
                                  Shape: (N, D) where N is number of points, D is dimension.
        kernel (gpflow.kernels.Kernel): The GPflow kernel function used in the objective.
        noise_variance (float): The observed data noise variance.
        **kwargs: Arbitrary keyword arguments.
    """
    pass

update(kernel, noise_variance)

Updates the kernel and noise variance parameters used by the objective function. This method should be overridden by subclasses if they maintain internal state that needs updating (e.g., cached kernel matrices or jitter values).

Parameters:

Name Type Description Default
kernel Kernel

The updated GPflow kernel function.

required
noise_variance float

The updated data noise variance.

required
Source code in sgptools/objectives.py
def update(self, kernel: gpflow.kernels.Kernel,
           noise_variance: float) -> None:
    """
    Updates the kernel and noise variance parameters used by the objective function.
    This method should be overridden by subclasses if they maintain internal state
    that needs updating (e.g., cached kernel matrices or jitter values).

    Args:
        kernel (gpflow.kernels.Kernel): The updated GPflow kernel function.
        noise_variance (float): The updated data noise variance.
    """
    pass