module documentation

various math utilities, notably eig and a collection of simple functions in Mh

Class MathHelperFunctions static convenience math helper functions, if the function name is preceded with an "a", a numpy array is returned
Class UpdatingAverage use instead of a list when too many values must be averaged
Function eig eigendecomposition of a symmetric matrix, much slower than numpy.linalg.eigh, return (EVals, Basis), the eigenvalues and an orthonormal basis of the corresponding eigenvectors, where
Function geometric_sd return geometric standard deviation of vals.
Function Hessian Hessian estimate for f at x0
Function moving_average rolling average without biasing boundary effects.
Function randhss n iid dim-dimensional vectors with length norm_(vector).
Function randhss_mixin n iid vectors uniformly distributed on the hypersphere surface with mixing in of normal distribution, which can be beneficial in smaller dimension.
Function to_correlation_matrix change C in place into a correlation matrix, AKA whitening
Function _sqrt_len Undocumented
def eig(C):

eigendecomposition of a symmetric matrix, much slower than numpy.linalg.eigh, return (EVals, Basis), the eigenvalues and an orthonormal basis of the corresponding eigenvectors, where

Basis[i]
the i-th row of Basis
columns of Basis, [Basis[j][i] for j in range(len(Basis))]
the i-th eigenvector with eigenvalue EVals[i]
def geometric_sd(vals, **kwargs):

return geometric standard deviation of vals.

The gsd is invariant under linear scaling and independent of the choice of the log-exp base.

kwargs are passed to np.std, in particular ddof.

def Hessian(f, x0, eps=1e-06):

Hessian estimate for f at x0

def moving_average(x, w=7):

rolling average without biasing boundary effects.

The first entries give the average over all first values (until the window width is reached).

If w is not an integer, expontential smoothing with weights proportionate to (1 - 1/w)**i summing to one is executed, thereby putting about 1 - exp(-1) ≈ 0.63 of the weight sum on the last w entries.

Details: the average is mainly based on np.convolve, whereas exponential smoothing is for the time being numerically inefficient and scales quadratically with the length of x.

def randhss(n, dim, norm_=_sqrt_len, randn=np.random.randn):

n iid dim-dimensional vectors with length norm_(vector).

The vectors are uniformly distributed on a hypersphere surface.

CMA-ES diverges with popsize 100 in 15-D without option 'CSA_clip_length_value': [0,0].

>>> from cma.utilities.math import randhss
>>> dim = 3
>>> assert dim - 1e-7 < sum(randhss(1, dim)[0]**2) < dim + 1e-7
def randhss_mixin(n, dim, norm_=_sqrt_len, c=(lambda d: 1.0 / d), randn=np.random.randn):

n iid vectors uniformly distributed on the hypersphere surface with mixing in of normal distribution, which can be beneficial in smaller dimension.

def to_correlation_matrix(c):

change C in place into a correlation matrix, AKA whitening

def _sqrt_len(x):

Undocumented