Metrics

RamanSPy also provides a set or relevant metrics that can be used to measure the similarity between spectra. This can be useful for the evaluatiion of different methods for preprocessing and analysis.

Metrics are available in the ramanspy.metrics module.

MAE

ramanspy.metrics.MAE(a: Spectrum, b: Spectrum, *args, **kwargs)[source]

Mean Absolute Error (MAE).

MAE is an Euclidean distance-based measure equal to the average of the absolute errors. The smaller the MAE, the more similar the two spectra are.

\[MAE = \frac{1}{n} \sum_{i=1}^{n} |a_i - b_i|\]

Examples:

import ramanspy as rp

rp.metrics.MAE(spectrum_1, spectrum_2)

MSE

ramanspy.metrics.MSE(a: Spectrum, b: Spectrum, *args, **kwargs)[source]

Mean Squared Error (MSE).

MSE is an Euclidean distance-based measure equal to the average of the square of the errors. The smaller the MSE, the more similar the two spectra are.

\[MSE = \frac{1}{n} \sum_{i=1}^{n} (a_i - b_i)^2\]

Examples:

import ramanspy as rp

rp.metrics.MSE(spectrum_1, spectrum_2)

RMSE

ramanspy.metrics.RMSE(a: Spectrum, b: Spectrum, *args, **kwargs)[source]

Root-mean-square error (RMSE).

The RMSE is the square root of the MSE. The smaller the RMSE, the more similar the two spectra are.

\[RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (a_i - b_i)^2}\]

Examples:

import ramanspy as rp

rp.metrics.RMSE(spectrum_1, spectrum_2)

SAD

ramanspy.metrics.SAD(a: Spectrum, b: Spectrum, *args, **kwargs)[source]

Spectral Angle Distance (SAD).

The SAD is the angle between two spectra in the n-dimensional space. The smaller the SAD, the more similar the two spectra are.

\[SAD = \arccos \left( \frac{a \cdot b}{||a|| \cdot ||b||} \right)\]

References

Kruse, F.A., Lefkoff, A.B., Boardman, J.W., Heidebrecht, K.B., Shapiro, A.T., Barloon, P.J. and Goetz, A.F.H., 1993. The spectral image processing system (SIPS)—interactive visualization and analysis of imaging spectrometer data. Remote sensing of environment, 44(2-3), pp.145-163.

Examples:

import ramanspy as rp

rp.metrics.SAD(spectrum_1, spectrum_2)

SID

ramanspy.metrics.SID(a: Spectrum, b: Spectrum, *args, **kwargs)[source]

Spectral Information Divergence (SID).

The SID is a information-theoretic measure of the difference between two spectra based on Kullback-Leibler divergence. The smaller the SID, the more similar the two spectra are.

\[SID = D_{KL}(a||b) + D_{KL}(b||a),\]

where

\[D_{KL}(p||q) = \sum_{i=1}^{n} p_i \log \frac{p_i}{q_i}\]

References

Chang, C.I., 1999, June. Spectral information divergence for hyperspectral image analysis. In IEEE 1999 International Geoscience and Remote Sensing Symposium. IGARSS’99 (Cat. No. 99CH36293) (Vol. 1, pp. 509-511). IEEE.

Examples:

import ramanspy as rp

rp.metrics.SID(spectrum_1, spectrum_2)

See also

Check relevant tutorials in the Datasets and metrics section for more information about how to use RamanSPy to access and use the metrics built into the package.