Skip to content

Base

sgptools.methods.get_method(method)

Retrieves an optimization method class by its string name.

Parameters:

Name Type Description Default
method str

The name of the optimization method (e.g., 'ContinuousSGP', 'CMA').

required

Returns:

Type Description
Type[Method]

Type[Method]: The class of the requested optimization method.

Raises:

Type Description
KeyError

If the method name is not found.

Usage
# To get the ContinuousSGP class
ContinuousSGPClass = get_method('ContinuousSGP')
# You can then instantiate it:
# CSGP_instance = ContinuousSGPClass(...)
Source code in sgptools/methods.py
def get_method(method: str) -> Type[Method]:
    """
    Retrieves an optimization method class by its string name.

    Args:
        method (str): The name of the optimization method (e.g., 'ContinuousSGP', 'CMA').

    Returns:
        Type[Method]: The class of the requested optimization method.

    Raises:
        KeyError: If the method name is not found.

    Usage:
        ```python
        # To get the ContinuousSGP class
        ContinuousSGPClass = get_method('ContinuousSGP')
        # You can then instantiate it:
        # CSGP_instance = ContinuousSGPClass(...)
        ```
    """
    return METHODS[method]

sgptools.methods.Method

Method class for optimization methods.

Attributes:

Name Type Description
num_sensing int

Number of sensing locations to optimize.

num_dim int

Dimensionality of the data points.

num_robots int

Number of robots/agents.

X_objective ndarray

(n, d); Data points used to define the objective function.

kernel Kernel

GPflow kernel function.

noise_variance float

Data noise variance.

transform Optional[Transform]

Transform object to apply to inducing points.

X_candidates Optional[ndarray]

(c, d); Discrete set of candidate locations for sensor placement.

num_dim int

Dimensionality of the sensing locations.

Source code in sgptools/methods.py
class Method:
    """
    Method class for optimization methods.

    Attributes:
        num_sensing (int): Number of sensing locations to optimize.
        num_dim (int): Dimensionality of the data points.
        num_robots (int): Number of robots/agents.
        X_objective (np.ndarray): (n, d); Data points used to define the objective function.
        kernel (gpflow.kernels.Kernel): GPflow kernel function.
        noise_variance (float): Data noise variance.
        transform (Optional[Transform]): Transform object to apply to inducing points.
        X_candidates (Optional[np.ndarray]): (c, d); Discrete set of candidate locations for sensor placement.
        num_dim (int): Dimensionality of the sensing locations.
    """

    def __init__(self,
                 num_sensing: int,
                 X_objective: np.ndarray,
                 kernel: gpflow.kernels.Kernel,
                 noise_variance: float,
                 transform: Optional[Transform] = None,
                 num_robots: int = 1,
                 X_candidates: Optional[np.ndarray] = None,
                 num_dim: Optional[int] = None,
                 **kwargs: Any):
        """
        Initializes the Method class.

        Args:
            num_sensing (int): Number of sensing locations to optimize.
            X_objective (np.ndarray): (n, d); Data points used to define the objective function.
            kernel (gpflow.kernels.Kernel): GPflow kernel function.
            noise_variance (float): Data noise variance.
            transform (Optional[Transform]): Transform object to apply to inducing points. Defaults to None.
            num_robots (int): Number of robots/agents. Defaults to 1.
            X_candidates (Optional[np.ndarray]): (c, d); Discrete set of candidate locations for sensor placement.
                                                 Defaults to None.
            num_dim (Optional[int]): Dimensionality of the sensing locations. Defaults to dimensonality of X_objective.
            **kwargs: Additional keyword arguments.
        """
        self.num_sensing = num_sensing
        self.num_robots = num_robots
        self.X_candidates = X_candidates
        if num_dim is None:
            self.num_dim = X_objective.shape[-1]
        else:
            self.num_dim = num_dim

    def optimize(self) -> np.ndarray:
        """
        Optimizes the sensor placements/path(s).

        Raises:
            NotImplementedError: This method must be implemented by subclasses.

        Returns:
            np.ndarray: (num_robots, num_sensing, num_dim); Optimized sensing locations.
        """
        raise NotImplementedError

    def update(self, kernel: gpflow.kernels.Kernel,
               noise_variance: float) -> None:
        """
        Updates the kernel and noise variance parameters of the underlying model/objective.

        Args:
            kernel (gpflow.kernels.Kernel): Updated GPflow kernel function.
            noise_variance (float): Updated data noise variance.

        Raises:
            NotImplementedError: This method must be implemented by subclasses.
        """
        raise NotImplementedError

    def get_hyperparameters(self) -> Tuple[gpflow.kernels.Kernel, float]:
        """
        Retrieves the current kernel and noise variance hyperparameters.

        Raises:
            NotImplementedError: This method must be implemented by subclasses.

        Returns:
            Tuple[gpflow.kernels.Kernel, float]: A tuple containing the kernel and noise variance.
        """
        raise NotImplementedError

__init__(num_sensing, X_objective, kernel, noise_variance, transform=None, num_robots=1, X_candidates=None, num_dim=None, **kwargs)

Initializes the Method class.

Parameters:

Name Type Description Default
num_sensing int

Number of sensing locations to optimize.

required
X_objective ndarray

(n, d); Data points used to define the objective function.

required
kernel Kernel

GPflow kernel function.

required
noise_variance float

Data noise variance.

required
transform Optional[Transform]

Transform object to apply to inducing points. Defaults to None.

None
num_robots int

Number of robots/agents. Defaults to 1.

1
X_candidates Optional[ndarray]

(c, d); Discrete set of candidate locations for sensor placement. Defaults to None.

None
num_dim Optional[int]

Dimensionality of the sensing locations. Defaults to dimensonality of X_objective.

None
**kwargs Any

Additional keyword arguments.

{}
Source code in sgptools/methods.py
def __init__(self,
             num_sensing: int,
             X_objective: np.ndarray,
             kernel: gpflow.kernels.Kernel,
             noise_variance: float,
             transform: Optional[Transform] = None,
             num_robots: int = 1,
             X_candidates: Optional[np.ndarray] = None,
             num_dim: Optional[int] = None,
             **kwargs: Any):
    """
    Initializes the Method class.

    Args:
        num_sensing (int): Number of sensing locations to optimize.
        X_objective (np.ndarray): (n, d); Data points used to define the objective function.
        kernel (gpflow.kernels.Kernel): GPflow kernel function.
        noise_variance (float): Data noise variance.
        transform (Optional[Transform]): Transform object to apply to inducing points. Defaults to None.
        num_robots (int): Number of robots/agents. Defaults to 1.
        X_candidates (Optional[np.ndarray]): (c, d); Discrete set of candidate locations for sensor placement.
                                             Defaults to None.
        num_dim (Optional[int]): Dimensionality of the sensing locations. Defaults to dimensonality of X_objective.
        **kwargs: Additional keyword arguments.
    """
    self.num_sensing = num_sensing
    self.num_robots = num_robots
    self.X_candidates = X_candidates
    if num_dim is None:
        self.num_dim = X_objective.shape[-1]
    else:
        self.num_dim = num_dim

get_hyperparameters()

Retrieves the current kernel and noise variance hyperparameters.

Raises:

Type Description
NotImplementedError

This method must be implemented by subclasses.

Returns:

Type Description
Tuple[Kernel, float]

Tuple[gpflow.kernels.Kernel, float]: A tuple containing the kernel and noise variance.

Source code in sgptools/methods.py
def get_hyperparameters(self) -> Tuple[gpflow.kernels.Kernel, float]:
    """
    Retrieves the current kernel and noise variance hyperparameters.

    Raises:
        NotImplementedError: This method must be implemented by subclasses.

    Returns:
        Tuple[gpflow.kernels.Kernel, float]: A tuple containing the kernel and noise variance.
    """
    raise NotImplementedError

optimize()

Optimizes the sensor placements/path(s).

Raises:

Type Description
NotImplementedError

This method must be implemented by subclasses.

Returns:

Type Description
ndarray

np.ndarray: (num_robots, num_sensing, num_dim); Optimized sensing locations.

Source code in sgptools/methods.py
def optimize(self) -> np.ndarray:
    """
    Optimizes the sensor placements/path(s).

    Raises:
        NotImplementedError: This method must be implemented by subclasses.

    Returns:
        np.ndarray: (num_robots, num_sensing, num_dim); Optimized sensing locations.
    """
    raise NotImplementedError

update(kernel, noise_variance)

Updates the kernel and noise variance parameters of the underlying model/objective.

Parameters:

Name Type Description Default
kernel Kernel

Updated GPflow kernel function.

required
noise_variance float

Updated data noise variance.

required

Raises:

Type Description
NotImplementedError

This method must be implemented by subclasses.

Source code in sgptools/methods.py
def update(self, kernel: gpflow.kernels.Kernel,
           noise_variance: float) -> None:
    """
    Updates the kernel and noise variance parameters of the underlying model/objective.

    Args:
        kernel (gpflow.kernels.Kernel): Updated GPflow kernel function.
        noise_variance (float): Updated data noise variance.

    Raises:
        NotImplementedError: This method must be implemented by subclasses.
    """
    raise NotImplementedError