Choose randomly between two functions

1 Ansicht (letzte 30 Tage)
GCats
GCats am 18 Aug. 2020
Kommentiert: dpb am 18 Aug. 2020
Hello!
I'm implementing a Double Q-Learning Algorithm to the pendulum-v0. I'm looking at the pseudocode and there's one part of the algorithm which I'm not sure how to write.
If you see on line 8, it states:
With Pr = 0.5:
Q_a(s,a)
else
Q_b(s,a)
Alternatively the choice between Q_a and Q_b can be random. How can I implement this in my code so that for each episode either Q_a or Q_b are selected and run?
Thank you in advance!
  1 Kommentar
dpb
dpb am 18 Aug. 2020
P = 0.5; % the split level
if rand()>=P
res=fnA();
else
res=fnB();
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

David Hill
David Hill am 18 Aug. 2020
randbit=randi(2,1,numEpisodes)-1;
for k=1:numEpisodes
if randbit(k)
Q_a(s,a)
else
Q_b(s,a)
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by