tensap.tools package

Submodules

tensap.tools.chebyshev_points module

Module chebyshev_points.

tensap.tools.chebyshev_points.chebyshev_points(n, s=None)

Return the first n Chebyshev points in [s[0], s[1]].

Parameters
nint

The number of Chebyshev points.

slist or numpy.ndarray, optional

The interval on which the points are computed. The default is [-1, 1].

Returns
xnumpy.ndarray

The first n Chebyshev points in [s[0], s[1]].

tensap.tools.grids module

Module grids.

class tensap.tools.grids.FullTensorGrid(grids, dim=None)

Bases: tensap.tools.grids.TensorGrid

Class FullTensorGrid: tensor product grid.

Attributes
size

Return the number of grid points.

Methods

array([ind])

Return an array of shape (n, d) where n is the number of grid points and d is the dimension.

multi_indices()

Return a set of multi-indices for indexing the grid.

ndim()

Return the dimension of the underlying space.

plot(y, *args)

Plot the grid.

plot_grid(*args, **kwargs)

Plot the grid.

random(X, n)

Generate a random FullTensorGrid from a RandomVector.

shape([d])

Return the shape of the grid, along the dimension d if provided.

eval_at_indices

array(ind=None)

Return an array of shape (n, d) where n is the number of grid points and d is the dimension.

Returns
numpy.ndarray

The TensorGrid as an array.

eval_at_indices(ind)
multi_indices()

Return a set of multi-indices for indexing the grid.

Returns
tensap.MultiIndices

Aset of multi-indices for indexing the grid.

plot(y, *args)

Plot the grid.

Parameters
ylist or numpy.ndarray

The values of the function on the grid.

*argstuple

Parameters of the plot, see matplotlib.pyplot.plot for more information.

Returns
None.
static random(X, n)

Generate a random FullTensorGrid from a RandomVector.

Parameters
Xtensap.RandomVector

The RandomVector used to generate the FullTensorGrid.

nlist or numpy.ndarray

Array of size d (or an integer for isotropic grid) containing the sizes of the grids in each dimension.

Returns
tensap.FullTensorGrid

The random FullTensorGrid.

property size

Return the number of grid points.

Returns
int

The number of grid points.

class tensap.tools.grids.SparseTensorGrid(grids, indices, dim=None)

Bases: tensap.tools.grids.TensorGrid

Class SparseTensorGrid: sparse tensor product grid.

Attributes
size

Return the number of grid points.

Methods

array()

Return an array of shape (n, d) where n is the number of grid points and d is the dimension.

ndim()

Return the dimension of the underlying space.

plot_grid(*args, **kwargs)

Plot the grid.

shape([d])

Return the shape of the grid, along the dimension d if provided.

array()

Return an array of shape (n, d) where n is the number of grid points and d is the dimension.

Returns
numpy.ndarray

The TensorGrid as an array.

property size

Return the number of grid points.

Returns
int

The number of grid points.

class tensap.tools.grids.TensorGrid

Bases: abc.ABC

Class TensorGrid: grids in product sets.

Attributes
dimint

The dimension.

grids: list

List containing the grids.

shape: numpy.ndarray

The shapes of the grids.

Methods

array()

Return an array of shape (n, d) where n is the number of grid points and d is the dimension.

ndim()

Return the dimension of the underlying space.

plot_grid(*args, **kwargs)

Plot the grid.

shape([d])

Return the shape of the grid, along the dimension d if provided.

abstract array()

Return an array of shape (n, d) where n is the number of grid points and d is the dimension.

Returns
numpy.ndarray

The TensorGrid as an array.

ndim()

Return the dimension of the underlying space.

Returns
int

The dimension of the underlying space.

plot_grid(*args, **kwargs)

Plot the grid.

Parameters
*argstuple

Parameters of the plot, see matplotlib.pyplot.plot for more information.

Returns
None.
Raises
ValueError

If the dimension is greater than 3.

shape(d=None)

Return the shape of the grid, along the dimension d if provided.

Equivalent to self.shape[d] if d is provided, self.shape otherwise.

Parameters
dint, optional

The dimension for which the shape is asked. The default is None.

Returns
numpy.ndarray

The shape of the grid.

abstract property size

Return the number of grid points.

Returns
int

The number of grid points.

tensap.tools.multi_indices module

Module multi_indices.

class tensap.tools.multi_indices.MultiIndices(array=None)

Bases: object

Class MultiIndices.

Attributes
arraynumpy.ndarray

An array containing n multi-indices in N^d.

Methods

add_indices(J)

Return the union of multi-indices of self and J.

bounded_by(m[, m0])

Create the set of multi-indices bounded by m.

cardinal()

Return the cardinal of the MultiIndices object.

envelope(u)

Compute the monotone envelope (or monotone majorant) of a bounded sequence u.

get_indices(k)

Return the multi-indices k in self.

get_margin()

Return the margin of the multi-index set self defined by the set of multi-indices i not in self such that it exists k in N^* s.t.

get_maximal_indices()

Return the set of maximal multi-indices contained in the downward closed multi-index set self.

get_reduced_margin()

Return the reduced margin of the multi-index set self defined by the set of multi-indices i not in self such that for all k in N^* s.t.

ind2sub(shape, ind)

Create the set of multi-indices with array [I1, …, Id] such that (I1, …, Id) = np.unravel_index(np.ravel(ind), shape).

intersect_indices(J)

Return the intersection of the multi-indices of self and J.

is_downward_closed([m])

Check whether or not the multi-index set is downward closed (or lower or monotone).

keep_dims(dims)

Keep the dimensions dims in self.

keep_indices(k)

Keep the multi-indices k in self.

ndim()

Return the dimension of the multi-indices.

norm([p, k])

Compute the p-norm of multi-indices k in the object.

plot(*args)

Plot the multi-index set self.

product_set(L[, d])

Create the set of multi-indices obtained by a product of sets of indices.

remove_dims(dims)

Remove the dimensions in ind in the MultiIndices.

remove_indices(J)

Remove multi-indices J from self.

sort([columns, mode])

Sort multi-indices column-wise using the column order provided in columns.

sort_by_norm(p[, mode])

Sort the multi-indices by increasing or decreasing p-norm.

sort_by_weighted_norm(p, w[, mode])

Sort the multi-indices by increasing or decreasing weighted p-norm.

sub2ind(shape)

Convert the indices of the MultiIndices object into flat indices.

to_list()

Convert the MultiIndices’ array into a list of arrays.

weighted_norm(p, w[, k])

Compute the weighted p-norm of multi-indices k in the object.

with_bounded_norm(d, p, m)

Create the set of multi-indices in N^d with p-norm bounded by m, p>0.

with_bounded_weighted_norm(d, p, m, w)

Create the set of multi-indices in N^d with weighted p-norm bounded by m, p>0.

add_indices(J)

Return the union of multi-indices of self and J.

Parameters
Jtensap.MultiIndices

The second MultiIndices object.

Returns
tensap.MultiIndices

The union of multi-indices of self and J.

static bounded_by(m, m0=0)

Create the set of multi-indices bounded by m.

Parameters
mlist or numpy.ndarray

List or array of length d containing the highest indices in each dimension.

m0int, optional

The lowest index for all dimensions. The default is 0.

Returns
tensap.MultiIndices

MultiIndices object containing the product set (m0:m[0]) x … x (m0:m[d-1]).

cardinal()

Return the cardinal of the MultiIndices object.

Returns
int

The cardinal of the MultiIndices object.

envelope(u)

Compute the monotone envelope (or monotone majorant) of a bounded sequence u.

Parameters
ulist or numpy.ndarray

The bounded sequence.

Returns
envnumpy.ndarray

The monotone envelope corresponding to the sequence defined by \(env_i = max_{j >= i} |u_j|\)

get_indices(k)

Return the multi-indices k in self.

Parameters
kint or list or numpy.ndarray

The numbers of the multi-indices to select.

Returns
numpy.ndarray

The multi-indices k in self.

get_margin()

Return the margin of the multi-index set self defined by the set of multi-indices i not in self such that it exists k in N^* s.t. i_k != 0 implies i - e_k in self where e_k is the k-th Kronecker sequence.

Returns
tensap.MultiIndices

The margin of self.

get_maximal_indices()

Return the set of maximal multi-indices contained in the downward closed multi-index set self.

Returns
tensap.MultiIndices

The set of maximal multi-indices contained in the downward closed multi-index set self.

get_reduced_margin()

Return the reduced margin of the multi-index set self defined by the set of multi-indices i not in self such that for all k in N^* s.t. i_k != 0 implies i - e_k in self where e_k is the k-th Kronecker sequence.

Returns
tensap.MultiIndices

The reduced margin of self.

static ind2sub(shape, ind)

Create the set of multi-indices with array [I1, …, Id] such that (I1, …, Id) = np.unravel_index(np.ravel(ind), shape).

Parameters
shapelist or numpy.ndarray

The shape of the array.

indlist or numpy.ndarray

The indices into the flattened version of an array of dimensions shape.

Returns
tensap.MultiIndices

The MultiIndices created using the flat indices ind and shape.

intersect_indices(J)

Return the intersection of the multi-indices of self and J.

Parameters
Jtensap.MultiIndices

The second multi-indices.

Returns
tensap.MultiIndices

The intersection of the multi-indices of self and J.

ind_Inumpy.array

The indices of the multi-indices in self common to self and J.

ind_Jnumpy.array

The indices of the multi-indices in J common to self and J.

is_downward_closed(m=0)

Check whether or not the multi-index set is downward closed (or lower or monotone).

Parameters
mint, optional

The lowest index for all dimensions. The default is 0.

Returns
condboolean

Boolean indicating whether or not the multi-index set is downward closed.

keep_dims(dims)

Keep the dimensions dims in self.

Parameters
dimsint or list or numpy.ndarray

The dimension(s) to keep.

Returns
tensap.MultiIndices

The MultiIndices with retained dimensions.

keep_indices(k)

Keep the multi-indices k in self.

Parameters
kint or list or numpy.ndarray

The number(s) of the multi-indices to keep.

Returns
tensap.MultiIndices

The MultiIndices with retained indices.

ndim()

Return the dimension of the multi-indices.

Returns
int

The dimension of the multi-indices.

norm(p=2, k=None)

Compute the p-norm of multi-indices k in the object.

Parameters
pint or numpy.inf, optional

The positive real scalar p of the p-norm, or numpy.inf. The default is 2.

klist or numpy.ndarray, optional

The multi-indices of which the norm is to be computed. The default is all the multi-indices of the object.

Returns
normnumpy.ndarray

The p-norm of the selected multi-indices.

plot(*args)

Plot the multi-index set self.

See also the function plot_multi_indices.

Parameters
*argstuple

Parameters used in tensap’s function plot_multi_indices.

Returns
None.
static product_set(L, d=None)

Create the set of multi-indices obtained by a product of sets of indices.

If ndim(L) is 1 and L contains a set of indices, the method returns a MultiIndices containing the product set L x … x L (d times).

If ndim(L) is 2 and L contains arrays of integers of size m_k, 0 <= k <= d-1, the method returns a MultiIndices containing the product set L[0] x … x L[d-1].

Parameters
Llist or numpy.ndarray

The grid or grids used to create the product set.

dint, optional

The dimension of the set of multi-indices. The default is None, indicating to infer it from L.

Returns
tensap.MultiIndices

The set of multi-indices obtained by a product of sets of indices.

Raises
ValueError

If the provided arguments are wrong.

remove_dims(dims)

Remove the dimensions in ind in the MultiIndices.

Parameters
dimsint or list or numpy.ndarray

The dimension(s) to be removed.

Returns
tensap.MultiIndices

The MultiIndices object with removed dimenions in dims.

remove_indices(J)

Remove multi-indices J from self.

Parameters
Jtensap.MultiIndices or int or list or numpy.ndarray

The multi-indices to remove in a tensap.MultiIndices object, or their numbers as an int or in a list or numpy.ndarray.

Returns
tensap.MultiIndices

The MultiIndices object with removed multi-indices in J.

sort(columns=None, mode='ascend')

Sort multi-indices column-wise using the column order provided in columns.

The method first sorts according to the column columns[0], then sorts the equal coefficients of column columns[1] and so on.

Parameters
columnslist or numpy.ndarray, optional

The column order used to sort the multi-indices. The default is last to first column.

modestring, optional

The sorting mode, equal to ‘ascend’ or ‘descend’. The default is ‘ascend’.

Returns
tensap.MultiIndices

The MultiIndices object with sorted multi-indices.

sort_by_norm(p, mode='ascend')

Sort the multi-indices by increasing or decreasing p-norm.

Parameters
pint

The positive real scalar p of the p-norm, or numpy.inf.

modestring, optional

The sorting mode, equal to ‘ascend’ or ‘descend’. The default is ‘ascend’.

Returns
tensap.MultiIndices

The MultiIndices object with multi-indices sorted by increasing or decreasing p-norm.

sort_by_weighted_norm(p, w, mode='ascend')

Sort the multi-indices by increasing or decreasing weighted p-norm.

Parameters
pint

The positive real scalar p of the p-norm, or numpy.inf.

wlist or numpy.ndarray

The self.cardinal() weights used in the computation of the norm.

modestring, optional

The sorting mode, equal to ‘ascend’ or ‘descend’. The default is ‘ascend’.

Returns
tensap.MultiIndices

The MultiIndices object with multi-indices sorted by increasing or decreasing weighted p-norm.

sub2ind(shape)

Convert the indices of the MultiIndices object into flat indices.

Parameters
shapelist or numpy.ndarray

The shape of the array.

Returns
numpy.ndarray

The flat indices associated with the MultiIndices object and shape.

to_list()

Convert the MultiIndices’ array into a list of arrays.

Returns
list

The MultiIndices’ array as a list of arrays.

weighted_norm(p, w, k=None)

Compute the weighted p-norm of multi-indices k in the object.

Parameters
pint or numpy.inf

The positive real scalar p of the p-norm, or numpy.inf.

wlist or numpy.ndarray

The self.cardinal() weights used in the computation of the norm.

klist or numpy.ndarray, optional

The multi-indices of which the norm is to be computed. The default is all the multi-indices of the object.

Returns
normnumpy.ndarray

The p-norm of the selected multi-indices.

static with_bounded_norm(d, p, m)

Create the set of multi-indices in N^d with p-norm bounded by m, p>0.

Parameters
dint

The dimension, a positive integer.

pint or numpy.inf

The p of the p-norm, either a positive real scalar or numpy.inf.

mint

The bound of the norm, a positive real scalar.

Returns
indtensap.MultiIndices

The set of multi-indices in N^d with p-norm bounded by m.

static with_bounded_weighted_norm(d, p, m, w)

Create the set of multi-indices in N^d with weighted p-norm bounded by m, p>0.

Parameters
dint

The dimension, a positive integer.

pint or numpy.inf

The p of the p-norm, either a positive real scalar or numpy.inf.

mint

The bound of the norm, a positive real scalar.

wlist or numpy.ndarray

The d weights defining the weighted p-norm of a multi-index i. \(|i|_{p, w} = (sum_{k=1}^d w_k^p i_k^p)^(1/p) for 0 < p < inf\) \(|i|_{Inf, w} = max_k w_k i_k\)

Returns
indtensap.MultiIndices

The set of multi-indices in N^d with weighted p-norm bounded by m.

tensap.tools.utils module

Module utils.

tensap.tools.utils.baseb2integer(I, b)

Return the integers with given representations in base b.

Parameters
Inumpy.ndarray or list

A row of I contains d integers [i_1, …, i_d] in {0, …, b-1} associated with an integer i = sum_{k=1}^d i_k b^(d-k) in [0, b^d-1].

bint

The base.

Returns
numpy.ndarray

The integers with given representations in base b.

tensap.tools.utils.fast_intersect(a, b)
tensap.tools.utils.fast_setdiff(a, b)
tensap.tools.utils.integer2baseb(i, b, d=None)

Returns the representation [i_1, …, i_d] in base b of a set of non negative integers i = sum_{k=1}^d i_k b^(d-k) in [0, b^d-1].

Parameters
ilist or numpy.ndarray

The integers to be convertes in base b.

bint

The base.

dint, optional

The dimension. The default is the minimal integer allowing the representation of max(i).

Returns
numpy.ndarray

The representation [i_1, …, i_d] in base b of the integers.

Module contents