mva Package

Lanczos Module

class PyMca5.PyMcaMath.mva.Lanczos.Lanczos(sparse, metrica=None, tol=1e-15)[source]
GramSchmidt(vect, n, NT=4)[source]
allocaMemory()[source]
cerca(nd, shift)[source]
converged(m)[source]
countdumpab = 0
diago(k, m)[source]
diagoCustom(minDim=5, shift=None)[source]
dump_count = 0
passeggia(k, m, start, gram=0, NT=4)[source]
ricipolla(k, m)[source]
class PyMca5.PyMcaMath.mva.Lanczos.LanczosNumericMatrix(mR)[source]

Bases: object

Moltiplica(res, v)[source]
getClass4Vect()[source]
tipo

alias of float64

trasforma(fattore, addendo)[source]
class PyMca5.PyMcaMath.mva.Lanczos.LanczosNumericVector(*dim)[source]

Bases: object

add_from_vect(b)[source]
add_from_vect_with_fact(b, fact)[source]
copy()[source]
copy_to_a_from_b(b)[source]
dividebyarray(prec)[source]
len()[source]
mat_mult(evect, q)[source]
multbyarray(prec)[source]
normalizza(norma)[source]
normalizzaauto()[source]
rescale(fact)[source]
scalare(b)[source]
set_all_random(v)[source]
set_to_one()[source]
set_to_zero()[source]
set_value(n, val)[source]
sqrtscalare(b)[source]
tipo

alias of float64

PyMca5.PyMcaMath.mva.Lanczos.REAL(a)[source]
PyMca5.PyMcaMath.mva.Lanczos.Real(x)[source]
PyMca5.PyMcaMath.mva.Lanczos.solveEigenSystem(S_base, nsearchedeigen, shift=None, metrica=None, tol=1e-15)[source]

NNMAModule Module

This module is a simple wrapper to the py_nnma module of Uwe Schmitt (uschmitt@mineway.de) in order to integrate it into PyMca. What follows is the documentation of py_nnma

py_nnma: python modules for nonnegative matrix approximation (NNMA)

  1. 2009 Uwe Schmitt, uschmitt@mineway.de

NNMA minimizes dist(Y, A X)

where: Y >= 0, m x n

A >= 0, m x k X >= 0, n x k

k < min(m,n)

dist(A,B) can be || A - B ||_fro
or KL(A,B)

This moudule provides the following functions:

NMF, NMFKL, SNMF, RRI, ALS, GDCLS, GDCLS_L1, FNMAI, FNMAI_SPARSE, NNSC and FastHALS

The common parameters when calling such a function are:

input:

Y – the matrix for decomposition, maybe dense
from numpy or sparse from scipy.sparse package

k – number of componnets to estimate

Astart Xstart – matrices to start iterations. Maybe None

for using random start matrices.

eps – termination swell value

maxcount – max number of iterations to be performed

verbose – if False: produce no output durint interations
if integer: give all ‘verbose’ itetations some output about current state of iterations

output:

A, X – result matrices of algorithm

obj – value of objective function of last iteration

count – number of iterations done

converged – flag: indicates if iterations stoped within
max number of iterations

The following extra parameters exist depending on algorithm:

RRI : damping parameter ‘psi’ (default: 1e-12)

SNMF : sparsity parameter ‘sparse_par’ (default: 0)

ALS : regularization parameter ‘regul’ for stabilizing iterations
(default value 0). needed if objective value jitters.

GCDLS : ‘regul’ for l2-smoothness of X (default 0)

GDCLS_L1 : ‘regul’ for l1-smoothness of X (default 0)

FNMAI : ‘stabil’ for stabilizing algorithm (default value 1e-12)
‘alpha’ for stepsize (default value 0.1) ‘tau’ for number of inner iterations (default value 2)
FNMAI_SPARSE : as FNMAI plus
‘regul’ for l1-smoothness of X (default 0)
NNSC : ‘alpha’ for stepsize of gradient update of A
‘sparse_par’ for sparsity

This module is based on:

  • Daniel D. Lee and H. Sebastian Seung:

    “Algorithms for non-negative matrix factorization”, in Advances in Neural Information Processing 13 (Proc. NIPS*2000) MIT Press, 2001.

    “Learning the parts of objects by non-negative matrix

    factorization”,

    Nature, vol. 401, no. 6755, pp. 788-791, 1999.

    1. Cichocki and A-H. Phan:

      “Fast local algorithms for large scale Nonnegative Matrix and

      Tensor Factorizations”,

      IEICE Transaction on Fundamentals, in print March 2009.

      1. Hoyer
      “Non-negative Matrix Factorization with sparseness

      constraints”,

      Journal of Machine Learning Research, vol. 5, pp. 1457-1469, 2004.

  • Dongmin Kim, Suvrit Sra,Inderjit S. Dhillon:

    “Fast Newton-type Methods for the Least Squares Nonnegative Matrix Approximation Problem” SIAM Data Mining (SDM), Apr. 2007

  • Ngoc-Diep Ho:


Copyright (c) 2009 Uwe Schmitt, uschmitt@mineway.de

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright
  • notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above
  • copyright notice, this list of conditions and the following
  • disclaimer in the documentation and/or other materials provided
  • with the distribution. Neither the name of the <ORGANIZATION>
  • nor the names of its contributors may be used to endorse or
  • promote products derived from this software without specific
  • prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PyMca5.PyMcaMath.mva.NNMAModule.nnma(stack, ncomponents, binning=None, function=None, eps=5e-05, verbose=0, maxcount=1000, kmeans=False)[source]

PCAModule Module

PyMca5.PyMcaMath.mva.PCAModule.expectationMaximizationPCA(stack, ncomponents=10, binning=None, **kw)[source]

This is a fast method when the number of components is small

PyMca5.PyMcaMath.mva.PCAModule.lanczosPCA(stack, ncomponents=10, binning=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCAModule.lanczosPCA2(stack, ncomponents=10, binning=None, **kw)[source]

This is a fast method, but it may loose information

PyMca5.PyMcaMath.mva.PCAModule.main()[source]
PyMca5.PyMcaMath.mva.PCAModule.mdpICA(stack, ncomponents=10, binning=None, dtype='float64', svd='True', mask=None, spectral_mask=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCAModule.mdpICAFloat32(stack, ncomponents=10, binning=None, mask=None, spectral_mask=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCAModule.mdpICAFloat64(stack, ncomponents=10, binning=None, mask=None, spectral_mask=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCAModule.mdpPCA(stack, ncomponents=10, binning=None, dtype='float64', svd='True', mask=None, spectral_mask=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCAModule.mdpPCASVDFloat32(stack, ncomponents=10, binning=None, mask=None, spectral_mask=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCAModule.mdpPCASVDFloat64(stack, ncomponents=10, binning=None, mask=None, spectral_mask=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCAModule.multipleArrayPCA(stackList, ncomponents=10, binning=None, **kw)[source]

Given a list of arrays, calculate the requested principal components from the matrix resulting from their column concatenation. Therefore, all the input arrays must have the same number of rows.

PyMca5.PyMcaMath.mva.PCAModule.numpyPCA(stack, ncomponents=10, binning=None, **kw)[source]

This is a covariance method using numpy

PCATools Module

PyMca5.PyMcaMath.mva.PCATools.getCovarianceMatrix(stack, index=None, binning=None, dtype=<type 'numpy.float64'>, force=True, center=True, weights=None, spatial_mask=None)[source]

Calculate the covariance matrix of input data (stack) array. The input array is to be understood as a set of observables (spectra) taken at different instances (for instance spatial coordinates).

Parameters:
  • stack (Numpy ndarray.) – Array of data. Dimension greater than one.
  • index – Integer specifying the array dimension containing the “observables”. Only the first

the first (index = 0) or the last dimension (index = -1 or index = (ndimensions - 1)) supported. :type index: Integer (default is -1 to indicate it is the last dimension of input array) :param binning: Current implementation corresponds to a sampling of the spectral data and not to an actual binning. This may change in future versions. :type binning: Positive integer (default 1) :param dtype: Keyword indicating the data type of the returned covariance matrix. :type dtype: A valid numpy data type (default numpy.float64) :param force: Indicate how to calculate the covariance matrix:

  • False : Perform the product data.T * data in one call
  • True : Perform the product data.T * data progressively (smaller memory footprint)
Parameters:
  • center (Boolean (default True)) – Indicate if the mean is to be subtracted from the observables.
  • weights – Weight to be applied to each observable. It can therefore be used as a spectral mask

setting the weight to 0 on the values to ignore. :type weights: Numpy ndarray of same size as the observables or None (default). :spatial_mask: Array of size n where n is the number of measurement instances. In mapping experiments, n would be equal to the number of pixels. :type spatial_mask: Numpy array of unsigned bytes (numpy.uint8) or None (default). :returns: The covMatrix, the average spectrum and the number of used pixels.

PyMca5.PyMcaMath.mva.PCATools.numpyPCA(stack, index=-1, ncomponents=10, binning=None, center=True, scale=True, mask=None, spectral_mask=None, **kw)[source]
PyMca5.PyMcaMath.mva.PCATools.test()[source]