HMF

class pydl.pydlspec2d.spec1d.HMF(spectra, invvar, K=4, n_iter=None, seed=None, nonnegative=False, epsilon=None, verbose=False)[source]

Bases: object

Class used to manage data for Heteroscedastic Matrix Factorization (HMF).

This is a replacement for pca_solve(). It can be called with:

hmf = HMF(spectra, invvar)
output = hmf.solve()

The input spectra should be pre-processed through combine1fiber().

Parameters:
spectraarray-like

The input spectral flux, assumed to have a common wavelength and redshift system.

invvararray-like

The inverse variance of the spectral flux.

Kint, optional

The number of dimensions of the factorization (default 4).

n_iterint, optional

Number of iterations.

seedint, optional.

If set, pass this value to numpy.random.seed().

nonnegativebool, optional

Set this to True to perform nonnegative HMF.

epsilonfloat, optional

Regularization parameter. Set to any non-negative float value to turn it on.

verbosebool, optional

If True, print extra information.

Notes

See [1] and [2] for the original derivation of this method.

The HMF iteration is initialized using kmeans(), which itself uses random numbers to initialize its state. If you need to ensure reproducibility, call numpy.random.seed() before initializing HMF.

The current algorithm cannot handle input data that contain columns of zeros. Columns of this type need to be carefully removed from the input data. This could also result in the output data having a different size compared to the input data.

References

Methods Summary

astep()

Update for coefficients at fixed component spectra.

astepnn()

Non-negative update for coefficients at fixed component spectra.

badness()

Compute \(\chi^2\), including possible non-smoothness penalty.

chi()

Compute \(\chi\), the scaled residual.

gstep()

Update for component spectra at fixed coefficients.

gstepnn()

Non-negative update for component spectra at fixed coefficients.

iterate()

Handle the HMF iteration.

model()

Compute the model.

normbase()

Apply standard component normalization.

penalty()

Compute penalty for non-smoothness.

reorder()

Reorder and rotate basis analogous to PCA.

resid()

Compute residuals.

solve()

Process the inputs.

Methods Documentation

astep()[source]

Update for coefficients at fixed component spectra.

astepnn()[source]

Non-negative update for coefficients at fixed component spectra.

badness()[source]

Compute \(\chi^2\), including possible non-smoothness penalty.

chi()[source]

Compute \(\chi\), the scaled residual.

gstep()[source]

Update for component spectra at fixed coefficients.

gstepnn()[source]

Non-negative update for component spectra at fixed coefficients.

iterate()[source]

Handle the HMF iteration.

Returns:
tuple of numpy.ndarray

The fitting coefficients and fitted functions, respectively.

model()[source]

Compute the model.

normbase()[source]

Apply standard component normalization.

penalty()[source]

Compute penalty for non-smoothness.

reorder()[source]

Reorder and rotate basis analogous to PCA.

resid()[source]

Compute residuals.

solve()[source]

Process the inputs.

Returns:
dict

The HMF solution.