亲爱的 Stack Overflow 社区,
我目前正在使用 matlab 对集成到 simevents 系统中的强化学习代理进行建模。我的模型能够运行,但是实体服务器块“任务”中应该有一个随机数生成器。如果我拔掉 RL 代理并仅运行 simevents 模型,随机数会按预期随机生成,但是如果我使用 RL 代理运行完整模型,结果总是给出相同的值,而且根本不是随机的。我知道 matlab rng 是确定性的并且取决于预定义的种子,您认为我应该如何继续为我的模型获得实际的随机数?我提供了我的模型的一些屏幕截图,以便您熟悉它。
这是我目前拥有的代码行:
% Generate rng1 as a uniform random number between 0 and 100
rng1 = randi([0, 100]);
% Generate rng2 as a random number between 1 and 2
rng2 = randi([1, 2]);
% Determine the type of mission based on each Probability
if (rng1 > 10 && rng1 <= 100) && (rng2 == 1)
% General Purpose mission with load 1
entity.Part.Nj = 10; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 2; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 2; % [hours]
elseif (rng1 > 10 && rng1 <= 100) && (rng2 == 2)
% General Purpose mission with load 2
entity.Part.Nj = 100; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 4; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 4; % [hours]
elseif (rng1 <= 10) && (rng2 == 1)
% Combat Mission with load 1
entity.Part.Nj = 1080; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 6; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 6; % [hours]
elseif (rng1 <= 10) && (rng2 == 2)
% Combat Mission with load 2
entity.Part.Nj = 3600; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 10; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 10; % [hours]
end
如果我需要提供任何进一步的信息,以便更清楚地了解我的问题,请告诉我。 预先感谢您。
将强化学习代理 (RL) 与 SimEvents 模型集成时,如果 RNG 管理不当,MATLAB 的 RNG 的确定性可能会导致非随机行为。
如果您想在使用 RL 代理时保持 SimEvents 模型的随机性,我建议您这样做:
RandStream
创建多个独立的随机数流。它应该看起来像这样:
% Create a separate random stream for SimEvents
simEventsRng = RandStream('mt19937ar','Seed','shuffle'); % 'shuffle' initializes based on the current time
% Generate random numbers using the separate stream
rng1 = randi(simEventsRng, [0, 100]);
rng2 = randi(simEventsRng, [1, 2]);
% Your decision logic based on rng1 and rng2 remains the same
if (rng1 > 10 && rng1 <= 100) && (rng2 == 1)
entity.Part.Nj = 10; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 2; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 2; % [hours]
elseif (rng1 > 10 && rng1 <= 100) && (rng2 == 2)
entity.Part.Nj = 100; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 4; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 4; % [hours]
elseif (rng1 <= 10) && (rng2 == 1)
entity.Part.Nj = 1080; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 6; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 6; % [hours]
elseif (rng1 <= 10) && (rng2 == 2)
entity.Part.Nj = 3600; % [Cycles]
entity.Ops.FH = entity.Ops.FH + 10; % [hours]
entity.Ops.IntervalFH = entity.Ops.IntervalFH + 10; % [hours]
end
rng('shuffle')
来完成此操作。既然你已经说过你已经这样做了,那么上面的方法可能会更有效。entity
函数将信号转换为实体来弥补这一差距。只需仔细检查我编写的代码是否符合您的环境。