TP-traitement-audio-visuel/TP4/estimation_non_super.m
2023-06-22 20:47:16 +02:00

23 lines
647 B
Matlab
Executable file

function [moyennes, variances, poids] = estimation_non_super(I, nb_classes, nb_tirages)
[fx, x] = ksdensity(I(:), 1:255);
MU = rand(nb_classes, nb_tirages) * 255;
SIGMA = rand(nb_classes, nb_tirages) * 15 + 10;
POIDS = zeros(nb_classes, nb_tirages);
R = zeros(nb_tirages, 1);
for i=1:nb_tirages
A = (1 ./ (SIGMA(:, i).*sqrt(2*pi))) .* exp( -(x-MU(:, i)).^2 ./ (2*SIGMA(:, i).^2) );
POIDS(:, i) = A' \ fx';
R(i) = sum( ( fx - sum( POIDS(:, i) .* A ) ).^2 );
end
[~, index] = min(R);
moyennes = MU(:, index);
variances = SIGMA(:, index).^2;
poids = POIDS(:, index);
end