Home | Trees | Indices | Help |
---|
|
Created on Tue Jul 30 20:55:58 2013
Copyright (c) 2013-2014, CEA/DSV/I2BM/Neurospin. All rights reserved.
Author: Tommy Löfstedt
License: BSD 3-clause.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
__package__ =
|
|
Returns the L2-norm for matrices (i.e. the Frobenius norm) or vectors. Examples -------- >>> import numpy as np >>> from parsimony.utils.maths import norm >>> matrix = np.array([[0.2, 1.0, 0.4], [2.0, 1.5, 0.1]]) >>> round(norm(matrix), 15) 2.731300056749533 >>> vector = np.array([[0.2], [1.0], [0.4]]) >>> round(norm(vector), 15) 1.095445115010332 |
Returns the Frobenius norm for matrices or the L2-norm for vectors. This is an alias for norm(.). Examples -------- >>> import numpy as np >>> from parsimony.utils.maths import norm >>> matrix = np.array([[0.2, 1.0, 0.4], [2.0, 1.5, 0.1]]) >>> round(norm(matrix), 15) 2.731300056749533 >>> vector = np.array([[0.2], [1.0], [0.4]]) >>> round(norm(vector), 15) 1.095445115010332 |
Returns the L1-norm or a matrix or vector. For vectors: sum(abs(x)**2)**(1./2) For matrices: max(sum(abs(x), axis=0)) Examples -------- >>> from parsimony.utils.maths import norm1 >>> matrix = np.array([[0.2, 1.0, 0.4], [2.0, 1.5, 0.1]]) >>> norm1(matrix) 2.5 >>> vector = np.array([[0.2], [1.0], [0.4]]) >>> norm1(vector) 1.6000000000000001 |
Returns the L0-norm of a vector. Examples -------- >>> from parsimony.utils.maths import norm0 >>> matrix = np.array([[0.2, 1.0, 0.4], [2.0, 1.5, 0.1]]) >>> norm0(matrix) Traceback (most recent call last): ... ValueError: The L0 norm is not defined for matrices. >>> vector = np.array([[0.2], [1.0], [0.4]]) >>> norm0(vector) 3 |
Return the infinity norm of a matrix or vector. For vectors : max(abs(x)) For matrices : max(sum(abs(x), axis=1)) Examples -------- >>> from parsimony.utils.maths import normInf >>> matrix = np.array([[0.2, 1.0, 0.4], [2.0, 1.5, 0.1]]) >>> normInf(matrix) 3.6000000000000001 >>> vector = np.array([[0.2], [1.0], [0.4]]) >>> normInf(vector) 1.0 |
Example ------- >>> import numpy as np >>> from parsimony.utils.maths import corr >>> v1 = np.asarray([[1., 2., 3.], [1., 2., 3.]]) >>> v2 = np.asarray([[1., 2., 3.], [1., 2., 3.]]) >>> print corr(v1, v2) [[ 1. 0. -1.] [ 0. 0. 0.] [-1. 0. 1.]] |
Example ------- >>> import numpy as np >>> from parsimony.utils.maths import cov >>> v1 = np.asarray([[1., 2., 3.], [1., 2., 3.]]) >>> v2 = np.asarray([[1., 2., 3.], [1., 2., 3.]]) >>> print cov(v1, v2) [[ 2. 0. -2.] [ 0. 0. 0.] [-2. 0. 2.]] |
The function max(x, 0). Returns a numpy array. Example ------- >>> import numpy as np >>> from parsimony.utils.maths import positive >>> np.maximum([1,-1,2], [0,0,0]) array([1, 0, 2]) |
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Apr 6 23:52:10 2015 | http://epydoc.sourceforge.net |