calculate_minimum_bandwidth¶
- sofia_redux.toolkit.splines.spline_utils.calculate_minimum_bandwidth(degrees, n_knots, permutations)[source]¶
Calculate the minimum possible bandwidth given knots and spline degree.
The bandwidth of a given observation matrix is given as:
k0(d1*d2*d3*…*dn) + k1(d2*d3*…*dn) + k2(d3*…*dn) + … + kn
for the n-dimensional case where a number (1,2,3, etc) signifies the dimension number, k represents the degree, and dn is given as n_knots - k - 1. This function loops through all available dimensional permutations in order to find the permutation that results in the smallest bandwidth.
Finding the bandwidth is only relevant in more than one dimension. The bandwidth of the observation matrix may be minimized by switching the order of dimensions (coordinates, degrees, knot lines, etc.). This can speed up evaluation of spline coefficients and knot locations.
To save speed, permutations should be pre-calculated and supplied to this function, containing each possible ordering of the dimensions. For example, for two dimensions, permutations would be [[0, 1], [1, 0]]. For three dimensions permutations would be:
- [[0 1 2]
[0 2 1] [1 0 2] [1 2 0] [2 0 1] [2 1 0]]
Note that for 1-dimension the minimum bandwidth will be fixed.
Dimensional permutations can be calculated via:
permutations = np.array(list(itertools.permutations(range(n_dim))))
where ndim is the number of dimensions.
- Parameters:
- degreesnumpy.ndarray (int)
The degrees of the spline in each dimension (n_dimensions,).
- n_knotsnumpy.ndarray (int)
The number of knots in each dimension (n_dimensions,).
- permutationsnumpy.ndarray (int)
All possible dimensional ordering of shape (n_permutations, n_dimensions).
- Returns:
- minimum_bandwidth, permutation_index, changedint, int, bool
The minimum bandwidth, the index of the permutation for the minimum bandwidth, and whether the permutation is different to the first available permutation.