25 lines
539 B
Mathematica
25 lines
539 B
Mathematica
|
function [U, k] = recuit_simule(U, k, AD, T, beta)
|
||
|
|
||
|
N = size(AD, 3);
|
||
|
k_p = mod(k + randi([0, N-2], size(k)), N) + 1;
|
||
|
|
||
|
U_p = zeros(size(U));
|
||
|
for i = 1:size(U, 1)
|
||
|
for j = 1:size(U, 2)
|
||
|
U_p(i, j) = AD(i, j, k_p(i, j)) + beta * regularisation(i, j, k, k_p(i, j));
|
||
|
end
|
||
|
end
|
||
|
|
||
|
% indices des énergies inférieurs
|
||
|
less = (U_p <= U);
|
||
|
probas = exp( (U - U_p) / T );
|
||
|
|
||
|
U(less) = U_p(less);
|
||
|
k(less) = k_p(less);
|
||
|
|
||
|
rd = rand(size(probas)) < probas;
|
||
|
U(rd) = U_p(rd);
|
||
|
k(rd) = k_p(rd);
|
||
|
|
||
|
end
|