rbf
Radial Basis Function (RBF) Interpolation Module.
This module provides a collection of functions to work with Radial Basis Function (RBF) networks, which are commonly used for interpolation, regression, and function approximation tasks. The RBFs are computed using Gaussian kernel functions (GKF) and are capable of modeling complex paths and signals.
All functions work with RBFs computed using Gaussian kernels, which are expressed as:
$GKF(x) = exp(-((x - c)^2 / (2 * sigma2)))$
Where x is the path parameter, c is the center of the kernel, and sigma2 is the standard deviation of the kernel.
The recursive regression methods applied in updateRBF use a least-squares approach to iteratively update the weights, while other functions provide tools for decoding paths, calculating derivatives, and working with quaternions or Cartesian coordinates.
- robotblockset.rbf.encodeRBF(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], y: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], N: int = 25, c: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None, sigma2: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None, bc: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...] | None = None, coff: float = 0.02, sfac: float = 3.0) Dict[str, ndarray][source]
Encode path y(x) with Radial Basis Functions (RBF) by calculating weights for Gaussian Kernel Functions (GKF).
The Gaussian Kernel Function (GKF) is defined as:
$GKF(x) = $exp(-((x - c)^2 / (2 * sigma2)))$
The Radial Basis Function (RBF) is a weighted sum of these Gaussian kernel functions: RBF(x) = $sum(w * GKF(x)) / sum(GKF(x))$
Optionally, initial and final velocity and acceleration boundary conditions can be defined, which will be included in the matrix for solving the RBF weights.
A dictionary containing the RBF parameters is defined as follows:
RBF[“N”] : Number of Gaussian kernel functions (N)
RBF[“w”] : Weights of the GKF (N, m)
RBF[“c”] : Centers of the GKF (N,)
RBF[“sigma2”] : Standard deviation of the GKF (N,)
- Parameters:
x (ArrayLike) – Path parameter (n, ). A 1D array representing the path or domain of the function.
y (ArrayLike) – Measured signals (n, m). A 2D array of shape (n, m) where each column corresponds to a signal.
N (int, optional) – The number of Gaussian kernel functions (GKF) used. Default is 25.
c (ArrayLike, optional) – equidistantly or set to x if n == N.
sigma2 (ArrayLike, optional) – (diff(c) * 0.75)**2.
bc (ArrayLike, optional) – Boundary conditions of the form [ydot(0), ydot(end), yddot(0), yddot(end)] (4, m), where m is the number of signals. If not provided, no boundary conditions are applied.
coff (float, optional) – The relative offset for auxiliary GKF centers. Default is 0.02, with typical values between 0.01 and 0.05.
sfac (float, optional) – A scaling factor for sigma2 in auxiliary GKF. Default is 3.0.
- Returns:
A dictionary containing the RBF parameters
- Return type:
Dict[str, np.ndarray]
- Raises:
ValueError – If the input parameters are incorrect, such as mismatched dimensions.
Notes
The function applies Radial Basis Function (RBF) interpolation to the input path x and corresponding measured signals y.
The boundary conditions bc are applied if provided, influencing the RBF computation.
The solution involves constructing a matrix A and solving for the weights w by using a pseudo-inverse.
- robotblockset.rbf.decodeRBF(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], RBF: Dict[str, ndarray], calc_derivative: int = 0) ndarray | Tuple[ndarray, ndarray] | Tuple[ndarray, ndarray, ndarray] | Tuple[ndarray, ndarray, ndarray, ndarray][source]
Generate path at points x encoded by Gaussian Radial Basis Functions (RBF) with Gaussian Kernel Functions (GKF).
The Gaussian Kernel Function (GKF) is defined as:
$GKF(x) = exp(-((x - c)^2 / (2 * sigma2)))$
The Radial Basis Function (RBF) is a weighted sum of these Gaussian kernel functions:
$RBF(x) = sum(w * GKF(x)) / sum(GKF(x))$
Optionally, derivatives of the path (velocity, acceleration, jerk) can be calculated by setting the calc_derivative parameter.
A dictionary containing the RBF parameters is defined as follows:
RBF[“N”] : Number of Gaussian kernel functions (N)
RBF[“w”] : Weights of the GKF (N, m)
RBF[“c”] : Centers of the GKF (N,)
RBF[“sigma2”] : Standard deviation of the GKF (N,)
- Parameters:
x (ArrayLike) – Path parameter (n,). A 1D array of the path or domain where the RBF will be evaluated.
RBF (Dict[str, np.ndarray]) – A dictionary containing the RBF parameters
calc_derivative (int, optional) – The order of the derivative to calculate from 0 to 3(default is 0, which means no derivatives). The options are:
- Returns:
y (np.ndarray) – Path values (n, m). The values of the path at the points x.
yd (np.ndarray, optional) – Path velocities (n, m), returned if calc_derivative >= 1.
ydd (np.ndarray, optional) – Path accelerations (n, m), returned if calc_derivative >= 2.
yddd (np.ndarray, optional) – Path jerks (n, m), returned if calc_derivative == 3.
- Raises:
ValueError – If input parameters are invalid or mismatched in dimensions.
Notes
The function uses the Gaussian kernel function to generate the path and its derivatives. If calc_derivative is set to a value greater than 0, it computes the respective derivatives (velocity, acceleration, or jerk) using finite differences.
- robotblockset.rbf.decodeQuaternionRBF(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], RBF: Dict[str, ndarray]) ndarray[source]
Generate quaternion path at points x encoded by Gaussian Radial Basis Functions (RBF) with Gaussian Kernel Functions (GKF).
The Gaussian Kernel Function (GKF) is defined as: GKF(x) = exp(-((x - c)^2 / (2 * sigma2)))
The Radial Basis Function (RBF) is a weighted sum of these Gaussian kernel functions: RBF(x) = sum(w * GKF(x)) / sum(GKF(x))
This function decodes the quaternion path y(x) encoded by the RBF, ensuring the resulting path is normalized to unit quaternions.
A dictionary containing the RBF parameters is defined as follows:
RBF[“N”] : Number of Gaussian kernel functions (N)
RBF[“w”] : Weights of the GKF (N, m)
RBF[“c”] : Centers of the GKF (N,)
RBF[“sigma2”] : Standard deviation of the GKF (N,)
- Parameters:
x (ArrayLike) – Path parameter (n,). A 1D array representing the path or domain where the quaternion path is evaluated.
RBF (Dict[str, np.ndarray]) – A dictionary containing the RBF parameters
- Returns:
path – The computed quaternion path values (n, 4). The path is represented as unit quaternions at the points x.
- Return type:
QuaternionsType
- Raises:
ValueError – If the input parameters are invalid or mismatched in dimensions.
Notes
The function normalizes the resulting quaternion path to ensure that each quaternion has unit magnitude.
The quaternion is represented as a 4-dimensional vector, and the function ensures that each decoded quaternion lies on the unit sphere in 4D space.
- robotblockset.rbf.decodeCartesianRBF(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], RBF: Dict[str, ndarray]) ndarray[source]
Generate Cartesian path at points x encoded by Gaussian Radial Basis Functions (RBF) with Gaussian Kernel Functions (GKF).
The Gaussian Kernel Function (GKF) is defined as: GKF(x) = exp(-((x - c)^2 / (2 * sigma2)))
The Radial Basis Function (RBF) is a weighted sum of these Gaussian kernel functions: RBF(x) = sum(w * GKF(x)) / sum(GKF(x))
This function decodes the Cartesian path y(x) encoded by the RBF. It assumes that the path includes 3D spatial data along with quaternion orientations in 7-dimensional space (x, y, z, qx, qy, qz, qw).
A dictionary containing the RBF parameters is defined as follows:
RBF[“N”] : Number of Gaussian kernel functions (N)
RBF[“w”] : Weights of the GKF (N, m)
RBF[“c”] : Centers of the GKF (N,)
RBF[“sigma2”] : Standard deviation of the GKF (N,)
- Parameters:
x (ArrayLike) – Path parameter (n,). A 1D array representing the path or domain where the Cartesian path is evaluated.
RBF (Dict[str, np.ndarray]) – A dictionary containing the RBF parameters
- Returns:
path – The computed Cartesian path values (n, m). The path includes 3D position and quaternion orientation at each point x.
- Return type:
Poses3DType
- Raises:
ValueError – If the input parameters are invalid or mismatched in dimensions (e.g., RBF weights not encoding a Cartesian path).
Notes
The function expects the RBF weights w to encode both the 3D positions and quaternion orientations, so w should have 7 columns.
The quaternion is normalized to ensure it has unit magnitude (i.e., it lies on the unit sphere in 4D space).
- robotblockset.rbf.jacobiRBF(x: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], RBF: Dict[str, ndarray], deps: float = 1e-05) Tuple[ndarray, ndarray][source]
Compute the Jacobian and its derivative for RBF encoded path at points x using numeric differentiation.
The Jacobian is calculated as the numerical derivative of the path with respect to the path parameter x, and the derivative of the Jacobian is also computed using finite differences.
A dictionary containing the RBF parameters is defined as follows:
RBF[“N”] : Number of Gaussian kernel functions (N)
RBF[“w”] : Weights of the GKF (N, m)
RBF[“c”] : Centers of the GKF (N,)
RBF[“sigma2”] : Standard deviation of the GKF (N,)
- Parameters:
x (ArrayLike) – Path parameter (n,). A 1D array representing the points at which the Jacobian is computed.
RBF (Dict[str, np.ndarray]) – A dictionary containing the RBF parameters.
deps (float, optional) – The step size used for numerical differentiation. Default is 1e-5.
- Returns:
J (n, m) and Jd (n, m) for the path and its Jacobian derivative.
- Return type:
Tuple[np.ndarray, np.ndarray]
- Raises:
ValueError – If the input parameters are invalid or mismatched in dimensions.
Notes
The function computes the Jacobian J and its derivative Jd by evaluating the RBF-encoded path at three points: - At x, at x + deps, and at x - deps.
The result is a numerical differentiation approach using the finite difference method.
- robotblockset.rbf.updateRBF(x: float, yn: ndarray | List[float] | List[int] | Tuple[float, ...] | Tuple[int, ...], RBF: Dict[str, ndarray]) Tuple[ndarray, Dict[str, ndarray]][source]
Update RBF weights using recursive regression.
This function updates the weights of the Radial Basis Function (RBF) network using a recursive regression method. The update is performed by adjusting the weights based on the difference between the measured signal
ynand the signal predicted by the RBF model at the given path parameterx. The update is done using the recursive least squares approach.A dictionary containing the RBF parameters is defined as follows:
RBF[“N”] : Number of Gaussian kernel functions (N)
RBF[“w”] : Weights of the GKF (N, m)
RBF[“c”] : Centers of the GKF (N,)
RBF[“sigma2”] : Standard deviation of the GKF (N,)
RBF[“p”] : Recursive regression matrix (N, N)
RBF[“lambda”] : Regularization parameter for recursive regression.
- Parameters:
x (float) – The path parameter at which the RBF model is evaluated. It is a scalar value.
yn (ArrayLike) – Measured signals (m,). A 1D array representing the observed data for which the RBF model is being updated.
RBF (Dict[str, np.ndarray]) – A dictionary containing the RBF parameters
- Returns:
y (np.ndarray) – The calculated signal at
xwith shape(m,). This is the predicted signal after updating the weights.RBF (Dict[str, np.ndarray]) – Updated RBF parameters, including the updated weights and the regression matrix.
- Raises:
ValueError – If the input parameters are invalid or mismatched in dimensions. For example, if x is not a scalar or if yn is not a vector.
Notes
The recursive regression method adjusts the weights based on the error between the predicted and measured values.
The
lambdaparameter serves as a regularization term to prevent overfitting during the weight update process.This method is often used in online learning scenarios where the model is updated iteratively with new data points.
Functions
|
Generate Cartesian path at points x encoded by Gaussian Radial Basis Functions (RBF) with Gaussian Kernel Functions (GKF). |
|
Generate quaternion path at points x encoded by Gaussian Radial Basis Functions (RBF) with Gaussian Kernel Functions (GKF). |
|
Generate path at points x encoded by Gaussian Radial Basis Functions (RBF) with Gaussian Kernel Functions (GKF). |
|
Encode path y(x) with Radial Basis Functions (RBF) by calculating weights for Gaussian Kernel Functions (GKF). |
|
Compute the Jacobian and its derivative for RBF encoded path at points x using numeric differentiation. |
|
Update RBF weights using recursive regression. |