Is there any way to add perturbation to a variable in Matlab?
I have a 101x82
size matrix called A
. I am trying to minimize an objective function obj_fun
, whose value is com开发者_如何学运维puted indirectly using A
.
Now in order to minimize this objective function obj_fun
, I need to perturb the values of A
. I want to check if obj_fun
is going down in values or not. If not, then I need to do perturb/change values of A
to a certain percentage such that it minimizes obj_fun
. Keep on perturbing/changing values of A
until we get minimum obj_fun
. My average value of A
before any perturbation is ~ 1.1529e+003.
Does any one have suggestion how can I do this? Also, I care a bit about speed i.e. the method/algorithm should not be too slow. Thanks.
You can add random Gaussian noise to A
:
A = 0; % seed value for A with something more interesting than 0
best = obj_fun(A);
for iter = 1:max_iter % max_iter should be the maximum number of iterations
newA = A + normrnd(0, 1, size(A));
newObj = obj_fun(A);
if( newObj < best )
best = newObj;
A = newA;
end
end
精彩评论