Now that we know how to compute the distance between two spectra let us proceed to the description of the Magnetstein algorithm. Suppose that we want to estimate p j,t for all t = 1, 2, . . . , T. We further developed this approach, 26 by assuming that some parts of spectra µ t and ν pt can be excessive or missing, i.e. both µ t and ν pt can contain noise and signals from contamination but also can lack signals that are expected. This assumption is modelled by adding the auxiliary points ω (that represents signal present in µ t , but missing in ν pt ) and ξ (that represents signal present in ν pt , but missing in µ t ). The proportion of signal removed to those points is equal to p 0,t and p ′ 0,t for points ω and ξ, respectively. To properly define the Wasserstein distance for this new augmented space, we need to define the cost of signal transport to auxiliary points ω and ξ. We assume that transport from any point to ω costs κ mixture and transport from any point to ξ costs κ components . These are so-called denoising penalties that are user-defined parameters of the Magnetstein algorithm and can be interpreted as soft tolerance thresholds for shifting of the signal along the horizontal axis for the spectrum µ t and for the library ν 1 , ν 2 , . . . , ν k , respectively. After including these new assumptions, the final formulation of the problem is as follows: