tensap.approximation.learning package

Submodules

tensap.approximation.learning.learning module

Module learning.

class tensap.approximation.learning.learning.Learning(loss)

Bases: object

Methods

linear_model

risk_estimation

static linear_model(loss_function)
risk_estimation(fun, sample, *args)

tensap.approximation.learning.linear_model_learning module

Module linear_model_learning.

class tensap.approximation.learning.linear_model_learning.LinearModelLearning(loss)

Bases: tensap.approximation.learning.learning.Learning

Methods

initialize

linear_model

risk_estimation

initialize()

tensap.approximation.learning.linear_model_learning_custom_loss module

Module linear_model_learning_custom_loss.

class tensap.approximation.learning.linear_model_learning_custom_loss.LinearModelLearningCustomLoss(custom_loss)

Bases: tensap.approximation.learning.linear_model_learning.LinearModelLearning

Class LinearModelLearningCustomLoss.

Attributes
optimizertensorflow.keras.optimizers.Optimizer

The optimizer used to solve the learning problem. The default is Adam.

initial_guessnumpy.ndarray or tensorflow.Tensor

The initial guess used as a starting point of the optimization algorithm. The default is a tensor with components drawn according to a standard normal random variable.

optionsdict

Options for the optimizer:

  • max_iter: the maximum number of iterations of an iterative minimization algorithm,

  • stagnation: the value of a stopping criterion based on the relative stagnation between two iterates

Methods

solve()

Solution of the minimization problem.

initialize

linear_model

risk_estimation

solve()

Solution of the minimization problem.

Returns
solnumpy.ndarray or tensap.FunctionalBasisArray

The solution of the minimization problem.

outputdict

Outputs of the algorithm.

tensap.approximation.learning.linear_model_learning_density_l2 module

Module linear_model_learning_density_l2.

class tensap.approximation.learning.linear_model_learning_density_l2.LinearModelLearningDensityL2

Bases: tensap.approximation.learning.linear_model_learning.LinearModelLearning

Class LinearModelLearningDensityL2.

Attributes
is_basis_orthonormalbool, optional

Boolean indicating if the basis used to compute the approximation is orthonormal according to some reference measure. The default is True.

Methods

solve()

Solution (Ordinary or Regularized) of the minimization problem and cross-validation procedure.

initialize

linear_model

risk_estimation

solve()

Solution (Ordinary or Regularized) of the minimization problem and cross-validation procedure.

Returns
solnumpy.ndarray or tensap.FunctionalBasisArray

The solution of the minimization problem.

outputdict

Outputs of the algorithm.

tensap.approximation.learning.linear_model_learning_square_loss module

Module linear_model_learning_square_loss.

class tensap.approximation.learning.linear_model_learning_square_loss.LinearModelLearningSquareLoss(weights=None)

Bases: tensap.approximation.learning.linear_model_learning.LinearModelLearning

Class LinearModelLearningSquareLoss.

Attributes
weightslist or numpy.ndarray, optional

The arrays for the weighted least-squares minimization. The default is None.

linear_solverstr

The selected solver: ‘solve’ to directly solve the normal equation using numpy.solve, ‘qr’ to perform a QR decomposition, and solve the resulting system using numpy.solve. The default is ‘qr’.

shared_coefficientsbool

When approximating a vector-valued function, indicates if the coefficients of the approximation are common to all the outputs. The default is True.

Methods

solve()

Solution (Ordinary or Regularized) of the Least-Squares problem and cross-validation procedure.

initialize

linear_model

risk_estimation

solve()

Solution (Ordinary or Regularized) of the Least-Squares problem and cross-validation procedure.

Returns
solnumpy.ndarray or tensap.FunctionalBasisArray

The solution of the minimization problem.

outputdict

Outputs of the algorithm.

tensap.approximation.learning.loss_functions module

Module loss_functions.

class tensap.approximation.learning.loss_functions.CustomLossFunction(loss_function)

Bases: tensap.approximation.learning.loss_functions.LossFunction

Class CustomLossFunction.

Attributes
loss_functiontensorflow.function

The custom loss function, defined using tensorflow operations.

error_functionfunction, optional

The function used to compute the test error. The default is None, indicating to use the risk function.

relative_error_functionfunction, optional

The function used to compute the relative test error. The default is None, indicating to use the risk function.

error_typestring, optional

The error type. The default is ‘relative’. Can also be ‘absolute’.

Methods

eval(fun, sample, *args[, nargout])

Evaluate the loss function using the function fun and the provided sample.

relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

risk_estimation(fun, sample, *args[, nargout])

Compute an estimation of the risk associated with the function fun and the loss function using the provided sample.

test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

eval(fun, sample, *args, nargout=1)

Evaluate the loss function using the function fun and the provided sample.

Parameters
funfunction

The function used to evaluate the loss function

samplelist

The sample used to evaluate the loss function

*argstuple

Additional parameters used by a specific loss function.

nargoutint, optional

Specifies the number of output variables. The default is 1, returning only the evaluations of the loss. Set to 2 to also return the so-called reference evaluations of the loss.

Returns
None.
relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

risk_estimation(fun, sample, *args, nargout=1)

Compute an estimation of the risk associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the risk is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

nargoutint, optional

Specifies the number of output variables. The default is 1, returning only the risk. Set to 2 to also return the so-called estimated reference risk.

Returns
np.float

The estimated risk.

np.float

The estimated reference risk.

test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

class tensap.approximation.learning.loss_functions.DensityL2LossFunction

Bases: tensap.approximation.learning.loss_functions.LossFunction

Class DensityL2LossFunction.

Attributes
error_typestring, optional

The error type. The default is ‘relative’.

Methods

eval(fun, sample, *args[, nargout])

Evaluate the loss function using the function fun and the provided sample.

relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

risk_estimation(fun, sample, *args[, nargout])

Compute an estimation of the risk associated with the function fun and the loss function using the provided sample.

test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

eval(fun, sample, *args, nargout=1)

Evaluate the loss function using the function fun and the provided sample.

Parameters
funfunction

The function used to evaluate the loss function

samplelist

The sample used to evaluate the loss function

*argstuple

Additional parameters used by a specific loss function.

nargoutint, optional

Specifies the number of output variables. The default is 1, returning only the evaluations of the loss. Set to 2 to also return the so-called reference evaluations of the loss.

Returns
None.
relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

class tensap.approximation.learning.loss_functions.LossFunction

Bases: abc.ABC

Class LossFunction.

Methods

eval(fun, sample, *args, nargout)

Evaluate the loss function using the function fun and the provided sample.

relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

risk_estimation(fun, sample, *args[, nargout])

Compute an estimation of the risk associated with the function fun and the loss function using the provided sample.

test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

abstract eval(fun, sample, *args, nargout)

Evaluate the loss function using the function fun and the provided sample.

Parameters
funfunction

The function used to evaluate the loss function

samplelist

The sample used to evaluate the loss function

*argstuple

Additional parameters used by a specific loss function.

nargoutint, optional

Specifies the number of output variables. The default is 1, returning only the evaluations of the loss. Set to 2 to also return the so-called reference evaluations of the loss.

Returns
None.
abstract relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

risk_estimation(fun, sample, *args, nargout=1)

Compute an estimation of the risk associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the risk is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

nargoutint, optional

Specifies the number of output variables. The default is 1, returning only the risk. Set to 2 to also return the so-called estimated reference risk.

Returns
np.float

The estimated risk.

np.float

The estimated reference risk.

abstract test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

class tensap.approximation.learning.loss_functions.SquareLossFunction

Bases: tensap.approximation.learning.loss_functions.LossFunction

Class SquareLossFunction.

Attributes
error_typestring, optional

The error type. The default is ‘relative’. Can also be ‘absolute’.

Methods

eval(fun, sample, *args[, nargout])

Evaluate the loss function using the function fun and the provided sample.

relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

risk_estimation(fun, sample, *args[, nargout])

Compute an estimation of the risk associated with the function fun and the loss function using the provided sample.

test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

eval(fun, sample, *args, nargout=1)

Evaluate the loss function using the function fun and the provided sample.

Parameters
funfunction

The function used to evaluate the loss function

samplelist

The sample used to evaluate the loss function

*argstuple

Additional parameters used by a specific loss function.

nargoutint, optional

Specifies the number of output variables. The default is 1, returning only the evaluations of the loss. Set to 2 to also return the so-called reference evaluations of the loss.

Returns
None.
relative_test_error(fun, sample, *args)

Compute the relative test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

test_error(fun, sample, *args)

Compute the test error associated with the function fun and the loss function using the provided sample.

Parameters
funfunction

The function to which the error is associated.

samplelist

The sample used to estimate the risk.

*argstuple

Additional parameters used by a specific loss function.

Returns
np.float

The relative test error.

Module contents