2.1.4.1.3. sf_tools.math.matrix module

MATRIX ROUTINES

This module contains methods for matrix operations.

Author:Samuel Farrens <samuel.farrens@gmail.com>
Version:1.2
Date:20/10/2017
sf_tools.math.matrix.gram_schmidt(matrix, return_opt='orthonormal')[source]

Gram-Schmit

This method orthonormalizes the row vectors of the input matrix.

Parameters:
  • matrix (np.ndarray) – Input matrix array
  • return_opt (str {orthonormal, orthogonal, both}) – Option to return u, e or both.
Returns:

Return type:

Lists of orthogonal vectors, u, and/or orthonormal vectors, e

Todo

Add citation and equation

sf_tools.math.matrix.nuclear_norm(data)[source]

Nuclear norm

This method computes the nuclear (or trace) norm of the input data.

Parameters:data (np.ndarray) – Input data array
Returns:
Return type:float nuclear norm value

Todo

Add equation

sf_tools.math.matrix.project(u, v)[source]

Project vector

This method projects vector v onto vector u.

Parameters:
  • u (np.ndarray) – Input vector
  • v (np.ndarray) – Input vector
Returns:

Return type:

np.ndarray projection

Todo

Add equation

sf_tools.math.matrix.rot_matrix(angle)[source]

Rotation matrix

This method produces a 2x2 rotation matrix for the given input angle.

Parameters:angle (float) – Rotation angle
Returns:
Return type:np.ndarray 2x2 rotation matrix
sf_tools.math.matrix.rotate(matrix, angle)[source]

Rotate

This method rotates an input matrix about the input angle.

Parameters:
  • matrix (np.ndarray) – Input matrix array
  • angle (float) – Rotation angle
Returns:

Return type:

np.ndarray rotated matrix

Raises:

ValueError – For invalid matrix shape

class sf_tools.math.matrix.PowerMethod(operator, data_shape, auto_run=True)[source]

Bases: object

Power method class

This method performs implements power method to calculate the spectral radius of the input data

Parameters:
  • operator (class) – Operator class instance
  • data_shape (tuple) – Shape of the data array
  • auto_run (bool) – Option to automatically calcualte the spectral radius upon initialisation
set_initial_x()[source]

Set initial value of x

This method sets the initial value of x to an arrray of random values

get_spec_rad(tolerance=1e-06, max_iter=10)[source]

Get spectral radius

This method calculates the spectral radius

Parameters:
  • tolerance (float, optional) – Tolerance threshold for convergence (default is “1e-6”)
  • max_iter (int, optional) – Maximum number of iterations