tensap.approximation.tensor_approximation.principal_component_analysis package¶
Submodules¶
tensap.approximation.tensor_approximation.principal_component_analysis.functional_tensor_principal_component_analysis module¶
Module functional_tensor_principal_component_analysis.
-
class
tensap.approximation.tensor_approximation.principal_component_analysis.functional_tensor_principal_component_analysis.
FunctionalTensorPrincipalComponentAnalysis
¶ Bases:
object
Class FunctionalTensorPrincipalComponentAnalysis: principal component analysis of multivariate functions based on TensorPrincipalComponentAnalysis for algebraic tensors.
- Attributes
- tolint or float or list or numpy.ndarray
An array containing the prescribed relative precisions (the length depends on the format). If len(tol)==1, use the same value for all alpha. Set tol = inf to prescribe the rank.
- max_rankint or list or numpy.ndarray
An array containing the maximum alpha-ranks (the length depends on the format). If len(max_rank)==1, use the same value for all alpha. Set max_rank = np.inf to prescribe the precision.
- basestensap.FunctionalBases
The functional bases used for the projection of the function.
- gridtensap.FullTensorGrid
FullTensorGrid for the projection of the function on the functional bases.
- displaybool
Boolean specifying the verbosity of the methods.
- pca_sampling_factorint
A factor to determine the number of samples N for the estimation of the principal components (1 by default):
if prescribed precision, N = pca_sampling_factor*N_alpha,
if prescribed rank, N = pca_sampling_factor*t.
- pca_adaptive_samplingbool
Adaptive sampling to determine the principal components with prescribed precision.
- projection_typestr
The type of projection. The default is ‘interpolation’.
Methods
hopca
(fun)Return the set of alpha-principal components of a tensor, for all alpha in {0,1,…,d-1}.
tree_based_approximation
(fun, tree[, …])Approximation of a function of d variables in tree based tensor format based on a Principal Component Analysis.
tt_approximation
(fun)Approximation of a function of d variables in tensor train format based on a Principal Component Analysis.
tucker_approximation
(fun)Approximation of a function of d variables in Tucker format based on a Principal Component Analysis.
-
hopca
(fun)¶ Return the set of alpha-principal components of a tensor, for all alpha in {0,1,…,d-1}.
For prescribed precision, set FPCA.max_rank = np.inf and FPCA.tol to the desired precision (possibly an array of length d).
For prescribed rank, set FPCA.tol = np.inf and FPCA.max_rank to the desired rank (possibly an array of length d).
See also the documentation of the class FunctionalTensorPrincipalComponentAnalysis.
- Parameters
- funfunction
A function of d variables.
- Returns
- f_pclist
List of the alpha-principal components of the function.
- outputslist
List containing the outputs of the method alpha_principal_components.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.
-
tree_based_approximation
(fun, tree, is_active_node=None)¶ Approximation of a function of d variables in tree based tensor format based on a Principal Component Analysis.
For a prescribed precision, set TPCA.max_rank = np.inf and TPCA.tol to the desired precision (possibly an array of length d-1).
For a prescribed rank, set TPCA.tol = np.inf and TPCA.max_rank to the desired rank (possibly an array of length d-1).
See also the documentation of the class FunctionalTensorPrincipalComponentAnalysis.
- Parameters
- funfun or tensap.Function
Function of d variables i_1, …, i_d which returns the entries of the tensor.
- shapelist or numpy.ndarray
The shape of the tensor.
- treetensap.DimensionTree
The required dimension tree.
- is_active_nodelist or numpy.ndarray, optional
An array of booleans indicating which nodes of the tree are active. The default is None, settings all the nodes active.
- Returns
- tensap.FunctionalTensor
A function in tree based format.
- dict
Dictionnary containing the outputs of the method.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.
-
tt_approximation
(fun)¶ Approximation of a function of d variables in tensor train format based on a Principal Component Analysis.
For a prescribed precision, set TPCA.max_rank = np.inf and TPCA.tol to the desired precision (possibly an array of length d).
For a prescribed rank, set TPCA.tol = np.inf and TPCA.max_rank to the desired rank (possibly an array of length d).
See also the documentation of the class FunctionalTensorPrincipalComponentAnalysis.
- Parameters
- funfunction
A function of d variables.
- Returns
- tensap.FunctionalTensor
A function in tree based format with a linear tree.
- dict
Dictionnary containing the outputs of the method.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.
-
tucker_approximation
(fun)¶ Approximation of a function of d variables in Tucker format based on a Principal Component Analysis.
For a prescribed precision, set TPCA.max_rank = np.inf and TPCA.tol to the desired precision (possibly an array of length d).
For a prescribed rank, set TPCA.tol = np.inf and TPCA.max_rank to the desired rank (possibly an array of length d).
See also the documentation of the class FunctionalTensorPrincipalComponentAnalysis.
- Parameters
- funfunction
A function of d variables.
- Returns
- tensap.FunctionalTensor
A function in tree based format with a trivial tree.
- dict
Dictionnary containing the outputs of the method.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.
tensap.approximation.tensor_approximation.principal_component_analysis.tensor_principal_component_analysis module¶
Module tensor_principal_component_analysis.
-
class
tensap.approximation.tensor_approximation.principal_component_analysis.tensor_principal_component_analysis.
TensorPrincipalComponentAnalysis
¶ Bases:
object
Class TensorPrincipalComponentAnalysis: principal component analysis of an algebraic tensor.
- Attributes
- displaybool
Boolean specifying the verbosity of the methods.
- pca_sampling_factorint
A factor to determine the number of samples N for the estimation of the principal components (1 by default):
if prescribed precision, N = pca_sampling_factor*N_alpha,
if prescribed rank, N = pca_sampling_factor*t.
- pca_adaptive_samplingbool
Adaptive sampling to determine the principal components with prescribed precision.
- tolint or float or list or numpy.ndarray
An array containing the prescribed relative precisions (the length depends on the format). If len(tol)==1, use the same value for all alpha. Set tol = inf to prescribe the rank.
- max_rankint or list or numpy.ndarray
An array containing the maximum alpha-ranks (the length depends on the format). If len(max_rank)==1, use the same value for all alpha. Set max_rank = np.inf to prescribe the precision.
Methods
alpha_principal_components
(fun, shape, …)Evaluate the alpha-principal components of a tensor f.
hopca
(fun, shape)Return the set of alpha-principal components of an algebraic tensor, for all alpha in {0,1,…,d-1}.
tree_based_approximation
(fun, shape, tree[, …])Approximation of a tensor of order d in tree based tensor format based on a Principal Component Analysis.
tt_approximation
(fun, shape)Approximation of a tensor of order d in tensor train format based on a Principal Component Analysis.
tucker_approximation
(fun, shape)Approximation of a tensor of order d in Tucker format based on a Principal Component Analysis.
-
alpha_principal_components
(fun, shape, alpha, tol, B_alpha, I_alpha)¶ Evaluate the alpha-principal components of a tensor f.
For alpha in {0,…,d-1}, it evaluates the alpha-principal components of a tensor f, meaning the principal components of the matricisations f_alpha(i_alpha,i_notalpha), where i_alpha and i_notalpha are groups of indices.
It evaluates f_alpha on the product of a set of indices in dimension alpha (of size Nalpha) and a set of random indices (N samples) in the complementary dimensions. Then, it computes approximations of the alpha-principal components in a given basis phi_1(i_alpha) … phi_Nalpha(i_alpha).
If t is an integer, t is the rank (number of principal components). If t<1, the rank (number of principal components) is determined such that the relative error after truncation is t.
- Parameters
- funfun or tensap.Function
Function of d variables i_1, …, i_d which returns the entries of the tensor.
- shapelist or numpy.ndarray
The shape of the tensor.
- alphaint
An array containing a tuple in {0,…,d-1}.
- tolint or float
The number of principal components or a positive number smaller than 1 (tolerance).
- B_alphanumpy.ndarray
Array of shape (N_lpha, N_lpha) whose i-th column is the evaluation of phi_i at the set of indices i_alpha in Ialpha.
- I_alphanumpy.ndarray
Array of shape (N_alpha, #alpha) containing N_alpha tuples i_alpha.
- Returns
- pcnumpy.ndarray
The principal components of the tensor.
- outputdict
A dictionnary of outputs, containing the singular values corresponding to the principal components, as well as the set of indices at which the tensor has been evaluated.
-
hopca
(fun, shape)¶ Return the set of alpha-principal components of an algebraic tensor, for all alpha in {0,1,…,d-1}.
For prescribed precision, set TPCA.max_rank = np.inf and TPCA.tol to the desired precision (possibly an array of length d).
For prescribed rank, set TPCA.tol = np.inf and TPCA.max_rank to the desired rank (possibly an array of length d).
See also the documentation of the class TensorPrincipalComponentAnalysis.
- Parameters
- funfun or tensap.Function
Function of d variables i_1, …, i_d which returns the entries of the tensor.
- shapelist or numpy.ndarray
The shape of the tensor.
- Returns
- f_pclist
List of the alpha-principal components of the tensor.
- outputlist
List containing the outputs of the method alpha_principal_components.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.
-
tree_based_approximation
(fun, shape, tree, is_active_node=None)¶ Approximation of a tensor of order d in tree based tensor format based on a Principal Component Analysis.
For a prescribed precision, set TPCA.max_rank = np.inf and TPCA.tol to the desired precision (possibly an array of length d-1).
For a prescribed rank, set TPCA.tol = np.inf and TPCA.max_rank to the desired rank (possibly an array of length d-1).
See also the documentation of the class TensorPrincipalComponentAnalysis.
- Parameters
- funfun or tensap.Function
Function of d variables i_1, …, i_d which returns the entries of the tensor.
- shapelist or numpy.ndarray
The shape of the tensor.
- treetensap.DimensionTree
The required dimension tree.
- is_active_nodelist or numpy.ndarray, optional
An array of booleans indicating which nodes of the tree are active. The default is None, settings all the nodes active.
- Returns
- tensap.TreeBasedTensor
A tensor in tree based format.
- dict
Dictionnary containing the outputs of the method.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.
-
tt_approximation
(fun, shape)¶ Approximation of a tensor of order d in tensor train format based on a Principal Component Analysis.
For a prescribed precision, set TPCA.max_rank = np.inf and TPCA.tol to the desired precision (possibly an array of length d-1).
For a prescribed rank, set TPCA.tol = np.inf and TPCA.max_rank to the desired rank (possibly an array of length d-1).
See also the documentation of the class TensorPrincipalComponentAnalysis.
- Parameters
- funfun or tensap.Function
Function of d variables i_1, …, i_d which returns the entries of the tensor.
- shapelist or numpy.ndarray
The shape of the tensor.
- Returns
- tensap.TreeBasedTensor
A tensor in tree based format with a linear tree.
- dict
Dictionnary containing the outputs of the method.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.
-
tucker_approximation
(fun, shape)¶ Approximation of a tensor of order d in Tucker format based on a Principal Component Analysis.
For a prescribed precision, set TPCA.max_rank = np.inf and TPCA.tol to the desired precision (possibly an array of length d).
For a prescribed rank, set TPCA.tol = np.inf and TPCA.max_rank to the desired rank (possibly an array of length d).
See also the documentation of the class TensorPrincipalComponentAnalysis.
- Parameters
- funfun or tensap.Function
Function of d variables i_1, …, i_d which returns the entries of the tensor.
- shapelist or numpy.ndarray
The shape of the tensor.
- Returns
- tensap.TreeBasedTensor
A tensor in tree based format with a trivial tree.
- dict
Dictionnary containing the outputs of the method.
- Raises
- ValueError
If the provided tolerance and max ranks are not correct.