tensor.slinalg – Linear Algebra Ops Using Scipy

Note

This module is not imported by default. You need to import it to use it.

API

class theano.tensor.slinalg.Cholesky(lower=True, on_error='raise')[source]

Return a triangular matrix square root of positive semi-definite x.

L = cholesky(X, lower=True) implies dot(L, L.T) == X.

Parameters:
  • lower (bool, default=True) – Whether to return the lower or upper cholesky factor
  • on_error (['raise', 'nan']) – If on_error is set to ‘raise’, this Op will raise a scipy.linalg.LinAlgError if the matrix is not positive definite. If on_error is set to ‘nan’, it will return a matrix containing nans instead.
L_op(inputs, outputs, gradients)[source]

Cholesky decomposition reverse-mode gradient update.

Symbolic expression for reverse-mode Cholesky gradient taken from [1]

References

[1]I. Murray, “Differentiation of the Cholesky decomposition”, http://arxiv.org/abs/1602.07527
make_node(x)[source]

Construct an Apply node that represent the application of this operation to the given inputs.

This must be implemented by sub-classes.

Returns:node – The constructed Apply node.
Return type:Apply
perform(node, inputs, outputs)[source]

Calculate the function on the inputs and put the variables in the output storage.

Parameters:
  • node (Apply) – The symbolic Apply node that represents this computation.
  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.
  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.
  • params (tuple) – A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

class theano.tensor.slinalg.Eigvalsh(lower=True)[source]

Generalized eigenvalues of a Hermitian positive definite eigensystem.

grad(inputs, g_outputs)[source]

Construct a graph for the gradient with respect to each input variable.

Each returned Variable represents the gradient with respect to that input computed based on the symbolic gradients with respect to each output. If the output is not differentiable with respect to an input, then this method should return an instance of type NullType for that input.

Parameters:
  • inputs (list of Variable) – The input variables.
  • output_grads (list of Variable) – The gradients of the output variables.
Returns:

grads – The gradients with respect to each Variable in inputs.

Return type:

list of Variable

make_node(a, b)[source]

Construct an Apply node that represent the application of this operation to the given inputs.

This must be implemented by sub-classes.

Returns:node – The constructed Apply node.
Return type:Apply
perform(node, inputs, outputs)[source]

Calculate the function on the inputs and put the variables in the output storage.

Parameters:
  • node (Apply) – The symbolic Apply node that represents this computation.
  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.
  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.
  • params (tuple) – A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

class theano.tensor.slinalg.EigvalshGrad(lower=True)[source]

Gradient of generalized eigenvalues of a Hermitian positive definite eigensystem.

make_node(a, b, gw)[source]

Construct an Apply node that represent the application of this operation to the given inputs.

This must be implemented by sub-classes.

Returns:node – The constructed Apply node.
Return type:Apply
perform(node, inputs, outputs)[source]

Calculate the function on the inputs and put the variables in the output storage.

Parameters:
  • node (Apply) – The symbolic Apply node that represents this computation.
  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.
  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.
  • params (tuple) – A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

class theano.tensor.slinalg.Expm[source]

Compute the matrix exponential of a square array.

grad(inputs, outputs)[source]

Construct a graph for the gradient with respect to each input variable.

Each returned Variable represents the gradient with respect to that input computed based on the symbolic gradients with respect to each output. If the output is not differentiable with respect to an input, then this method should return an instance of type NullType for that input.

Parameters:
  • inputs (list of Variable) – The input variables.
  • output_grads (list of Variable) – The gradients of the output variables.
Returns:

grads – The gradients with respect to each Variable in inputs.

Return type:

list of Variable

make_node(A)[source]

Construct an Apply node that represent the application of this operation to the given inputs.

This must be implemented by sub-classes.

Returns:node – The constructed Apply node.
Return type:Apply
perform(node, inputs, outputs)[source]

Calculate the function on the inputs and put the variables in the output storage.

Parameters:
  • node (Apply) – The symbolic Apply node that represents this computation.
  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.
  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.
  • params (tuple) – A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

class theano.tensor.slinalg.ExpmGrad[source]

Gradient of the matrix exponential of a square array.

make_node(A, gw)[source]

Construct an Apply node that represent the application of this operation to the given inputs.

This must be implemented by sub-classes.

Returns:node – The constructed Apply node.
Return type:Apply
perform(node, inputs, outputs)[source]

Calculate the function on the inputs and put the variables in the output storage.

Parameters:
  • node (Apply) – The symbolic Apply node that represents this computation.
  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.
  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.
  • params (tuple) – A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

class theano.tensor.slinalg.Solve(A_structure='general', lower=False, overwrite_A=False, overwrite_b=False)[source]

Solve a system of linear equations.

For on CPU and GPU.

L_op(inputs, outputs, output_gradients)[source]

Reverse-mode gradient updates for matrix solve operation c = A \b.

Symbolic expression for updates taken from [2].

References

[2]M. B. Giles, “An extended collection of matrix derivative results for forward and reverse mode automatic differentiation”, http://eprints.maths.ox.ac.uk/1079/
make_node(A, b)[source]

Construct an Apply node that represent the application of this operation to the given inputs.

This must be implemented by sub-classes.

Returns:node – The constructed Apply node.
Return type:Apply
perform(node, inputs, output_storage)[source]

Calculate the function on the inputs and put the variables in the output storage.

Parameters:
  • node (Apply) – The symbolic Apply node that represents this computation.
  • inputs (Sequence) – Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.
  • output_storage (list of list) – List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.
  • params (tuple) – A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.

theano.tensor.slinalg.kron(a, b)[source]

Kronecker product.

Same as scipy.linalg.kron(a, b).

Parameters:
  • a (array_like) –
  • b (array_like) –
Returns:

Return type:

array_like with a.ndim + b.ndim - 2 dimensions

Notes

numpy.kron(a, b) != scipy.linalg.kron(a, b)! They don’t have the same shape and order when a.ndim != b.ndim != 2.

theano.tensor.slinalg.solve_symmetric = Solve{('symmetric', False, False, False)}[source]

Optimized implementation of theano.tensor.slinalg.solve() when A is symmetric.

theano.tensor.slinalg.solve(a, b)[source]

Solves the equation a x = b for x, where a is a matrix and b can be either a vector or a matrix.

Parameters:
  • a ((M, M) symbolix matrix) – A square matrix
  • b ((M,) or (M, N) symbolic vector or matrix) – Right hand side matrix in a x = b
Returns:

x – x will have the same shape as b

Return type:

(M, ) or (M, N) symbolic vector or matrix

theano.tensor.slinalg.solve_lower_triangular(a, b)[source]

Optimized implementation of theano.tensor.slinalg.solve() when A is lower triangular.

theano.tensor.slinalg.solve_upper_triangular(a, b)[source]

Optimized implementation of theano.tensor.slinalg.solve() when A is upper triangular.