How to improve elements of a weight array related to a matrix using weighted sampling without replacement?

2 vues (au cours des 30 derniers jours)
I have a 4 by 12 matrix (M) as a solution for a recursive function (f). f(M) = fitness where fitness is a real number. In each iteration of an optimization algorithm, some elements in M would change in order to maximize the fitness. The selection of the elements is through weighted sampling by datasample. So we have a 4 by 12 array as weight matrix (W), which has equal elements at the very beginning (e.g., W=ones(4,12); ). In each iteration, after assessing the new solution by the fitness function, the weight matrix should be updated according to the effect of the elements' changes on the fitness. If those elements improve the fitness, the related weight should increase; otherwise, it should be decreased.
Assume that we have M_1 (as the parent) and W_1 and fit_1 as initial parameters. In the first iteration, after weighted sampling from M_1, we make some changes, so we have M_2 (as offspring) and fit_2. I'm looking for a way to update the W_1 according to the change rate. Attached please find my code. I think that at the end of run, W(4,:) should be larger than W(1,:) according to the Benefit matrix.
Any idea for optimizing the code would be appreciated.
Here is a kind of simple pseudo-code that I hope it can help:
M = randi([0.5,8],4,12);
W = ones(4,12);
f = @(x) x.^2;
fit_1 = f(M);
for i =1:1000
[~,ind] = datasample(M,2,'Replace',false,'Weights',W)
M_offspring = Update (M(ind)) using a function
fit_2 = f(M_offspring)
if fit_2 > fit_1
W (ind) = get award (increase)
else
W (ind) = get penalty (decrease)
end
fit_1 = fit_2
M = M_offspring
end
  4 commentaires
darova
darova le 24 Avr 2020
Don't know, maybe becauses of a lot of explanations. I like questions as following
Is it possible to simplify your question to see something like that?
emami.m
emami.m le 29 Avr 2020
Modifié(e) : emami.m le 29 Avr 2020
I did my best to simplify the question by adding a pseudo-code in addition to initial code. I hope this helps.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Surrogate Optimization dans Help Center et File Exchange

Produits


Version

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by