TP-traitement-audio-visuel/TP2/moindres_carres_ecretes.m

23 lines
563 B
Mathematica
Raw Normal View History

2023-06-22 18:47:16 +00:00
function estimation = moindres_carres_ecretes(D_app, beta_0, beta_d, d, lambda)
X = D_app(1, :)';
Y = D_app(2, :)';
B = Y - beta_0 * (1 - X).^d - beta_d * (X.^d);
A = zeros(length(X), d - 1);
for i = 1:(d - 1)
A(:, i) = nchoosek(d, i) .* X.^i .* (1 - X).^(d - i);
end
slope = (beta_d - beta_0) / (X(length(X)) - X(1));
beta_barre = slope * (1 / d:1 / d:1 - 1 / d)' + beta_0;
C = B - A * beta_barre;
delta_chapeau = (A' * A + lambda * eye(d - 1)) \ (A' * C);
estimation = beta_barre + delta_chapeau;
end