Using ALS algorithm for writing a code

Is ALS algorithm supported by MATLAB R2019a. What is the best source of downloading the alogorithm and the reference to write the code for analysing spectral data?

回答 (1 件)

Star Strider
Star Strider 2019 年 4 月 26 日

2 投票

I’ve not run this, so I have no experience with it. It’s the only MATLAB code for the algorithm that I could find.
The slightly corrected version of the function:
function z = baseline(y, lambda, p)
% Estimate baseline with asymmetric least squares
m = length(y);
D = diff(speye(m), 2);w = ones(m, 1);
for it = 1:10
W = spdiags(w, 0, m, m);
C = chol(W + lambda * D' * D);
z = C \ (C' \ (w .* y));
w = p * (y > z) + (1 - p) * (y < z);
end
Also consider:
function z = baseline(y, lambda, p)
% Estimate baseline with asymmetric least squares
m = length(y);
D = diff(speye(m), 2);w = ones(m, 1);
for it = 1:10
W = spdiags(w, 0, m, m);
C = chol(W + lambda * (D' * D));
z = C \ (C' \ (w .* y));
w = p * (y > z) + (1 - p) * (y < z);
end
The documentation for the function is in the paper.
Experiment to get the result you want.

5 件のコメント

Csaba
Csaba 2019 年 10 月 2 日
at the very beginning I would add:
if isrow(y)
y=y';
end
Timothy Loayza
Timothy Loayza 2020 年 8 月 23 日
Thanks a lot, it works very well for Raman's spectras. (lambda = 100'000, p = 0.01)
BTW : I don't know who to cite for it as the link is not working anymore.
Star Strider
Star Strider 2020 年 8 月 23 日
Timothy Loayza — I actually saved it. I am attaching it here. (It was apparently open-access at the time, so I doubt that I am violating any copyright by posting it here.)
Also, with respect to Csaba’s comment, if you want to force it to be a column vector, just do this:
y(:)
.
Raimund
Raimund 2025 年 11 月 4 日
移動済み: Star Strider 2025 年 11 月 4 日
Hi,
thanks. This implementation works great.
Best regards,
Raimund
Star Strider
Star Strider 2025 年 11 月 4 日
移動済み: Star Strider 2025 年 11 月 4 日
My pleasure!
A Vote would be appreciated!

サインインしてコメントする。

質問済み:

2019 年 4 月 26 日

移動済み:

2025 年 11 月 4 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by