-
Notifications
You must be signed in to change notification settings - Fork 0
/
Train.m
58 lines (45 loc) · 1.35 KB
/
Train.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
rng(0);
% get env
env = env();
% get net
ObservationInfo = getObservationInfo(env);
ActionInfo = getActionInfo(env);
% bug here? 等号右侧的输出数目不足,不满足赋值要求。
[critic,actor] = net(ObservationInfo,ActionInfo);
% set agent parameters
criticOptions = rlOptimizerOptions( ...
LearnRate=1e-3, ...
GradientThreshold=1);
actorOptions = rlOptimizerOptions( ...
LearnRate=2e-4, ...
GradientThreshold=1);
agentOpts = rlPPOAgentOptions(...
SampleTime=-1,...
ActorOptimizerOptions=actorOptions,...
CriticOptimizerOptions=criticOptions,...
ExperienceHorizon=200,...
ClipFactor=0.2,...
EntropyLossWeight=0.01,...
MiniBatchSize=64,...
NumEpoch=3,...
AdvantageEstimateMethod="gae",...
GAEFactor=0.95,...
DiscountFactor=0.998);
agent = rlPPOAgent(actor,critic,agentOpts);
% Test
%getAction(agent,{rand(ObservationInfo.Dimension)});
% train parameters
trainOpts = rlTrainingOptions(...
MaxEpisodes=10000,...
MaxStepsPerEpisode=1,...
ScoreAveragingWindowLength=10,...
Plots="training-progress",...
StopTrainingCriteria="AverageReward",...
StopTrainingValue=10000);
doTraining = true;
if doTraining
trainingStats = train(agent,env,trainOpts);
save('Agent.mat','agent');
else
load('Agent.mat','agent');
end