setActor
Set actor of reinforcement learning agent
Description
Examples
修改Actor参数值
Assume that you have an existing trained reinforcement learning agent. For this example, load the trained agent fromTrain DDPG Agent to Control Double Integrator System。
load('doubleintegddpg.mat','agent')
从代理获取参与者函数近似器。
actor = getActor(agent);
从演员那里获取可学习的参数。
params = getLearnableParameters(Actor)
参数=2×1 cell array{[-15.4689 -7.1635]} {[ 0]}
Modify the parameter values. For this example, simply multiply all of the parameters by2
。
modifiedParams = cellfun(@(x) x*2,params,'UniformOutput',错误的);
Set the parameter values of the actor to the new modified values.
actor = setLearnableParameters(actor,modifiedParams);
Set the actor in the agent to the new modified actor.
setActor(agent,actor);
显示新的参数值。
getLearnableParameters(getActor(agent))
ans=2×1 cell array{[-30.9378 -14.3269]} {[ 0]}
Modify Deep Neural Networks in Reinforcement Learning Agent
创建一个具有连续动作空间的环境,并获得其观察和行动规范。对于此示例,加载示例中使用的环境Train DDPG Agent to Control Double Integrator System。
Load the predefined environment.
env = rlPredefinedEnv(“双整合器连续”);
获得观察和行动规格。
obsinfo = getObservationinfo(env);actinfo = getActionInfo(env);
Create a PPO agent from the environment observation and action specifications. This agent uses default deep neural networks for its actor and critic.
agent = rlPPOAgent(obsInfo,actInfo);
为了修改加强学习代理中的深层神经网络,您必须首先提取演员和评论家功能近似器。
actor = getActor(agent); critic = getCritic(agent);
从演员和评论家功能近似器中提取深神网络。
actornet = getModel(Actor);评论家= getModel(评论家);
The networks aredlnetwork
objects. To view them using theplot
function, you must convert them toLayerGraph
objects.
例如,查看演员网络。
plot(layerGraph(actorNet))
To validate a network, useanalyzeNetwork
。例如,验证评论家网络。
analyzeNetwork(criticNet)
You can modify the actor and critic networks and save them back to the agent. To modify the networks, you can use the深网设计师app. To open the app for each network, use the following commands.
DeepNetworkDesigner(layergraph(Crivernet))deepnetworkDesigner(layergraph(actornet))
In深网设计师, modify the networks. For example, you can add additional layers to your network. When you modify the networks, do not change the input and output layers of the networks returned byGetModel
。有关构建网络的更多信息,请参阅Build Networks with Deep Network Designer。
验证修改后的网络深网设计师,您必须点击分析DLNETWORK, under theAnalysis部分。要将修改后的网络结构导出到MATLAB®工作区,请生成用于创建新网络的代码,并从命令行运行此代码。请勿在深网设计师。For an example that shows how to generate and run code, see使用深网设计师创建代理,并使用图像观测来训练。
For this example, the code for creating the modified actor and critic networks is in thecreateModifiedNetworks
助手脚本。
createModifiedNetworks
每个修改的网络都包括一个附加的fullyConnectedLayer
和reluLayer
在他们的主要公共路径中。查看修改后的演员网络。
绘图(LayerGraph(ModifiedActornet))
导出网络后,将网络插入演员和评论家功能近似器中。
Actor = SetModel(Actor,ModifiedActornet);评论家= setModel(评论家,修改Criticnet);
Finally, insert the modified actor and critic function approximators into the actor and critic objects.
agent = setActor(agent,actor); agent = setCritic(agent,critic);
Input Arguments
agent
—Reinforcement learning agent
rlpgagent
|rlDDPGAgent
|rlTD3Agent
|rlACAgent
|rlSACAgent
|rlPPOAgent
|rlTRPOAgent
Reinforcement learning agent that contains an actor, specified as one of the following:
rlpgagent
objectrlDDPGAgent
objectrlTD3Agent
objectrlACAgent
objectrlSACAgent
objectrlPPOAgent
objectrlTRPOAgent
object
Note
agent
is an handle object. Therefore is updated bysetActor
无论agent
是否作为输出参数返回。有关处理对象的更多信息,请参阅处理对象行为。
actor
—Actor
rlContinuousDeterministicActor
object|rlDiscreteCategoricalActor
object|rlContinuousGaussianActor
object
rlContinuousDeterministicActor
rlDiscreteCategoricalActor
rlContinuousGaussianActor
Actor object, specified as one of the following:
rlContinuousDeterministicActor
object — Specify whenagent
is anrlDDPGAgent
或者rlTD3Agent
objectrlDiscreteCategoricalActor
object — Specify whenagent
is anrlACAgent
,rlpgagent
,rlPPOAgent
,rlTRPOAgent
或者rlSACAgent
object for an environment with a discrete action space.rlContinuousGaussianActor
object — Specify whenagent
is anrlACAgent
,rlpgagent
,rlPPOAgent
,rlTRPOAgent
或者rlSACAgent
object for an environment with a continuous action space.
演员中近似模型的输入和输出(通常是神经网络)必须匹配原始代理的观察和动作规范。
To create an actor, use one of the following methods:
Create the actor using the corresponding function approximator object.
Obtain the existing actor from an agent using
getActor
。
Output Arguments
agent
- 更新的强化学习代理
rlpgagent
|rlDDPGAgent
|rlTD3Agent
|rlACAgent
|rlSACAgent
|rlPPOAgent
|rlTRPOAgent
Updated agent, returned as an agent object. Note thatagent
is an handle object. Therefore its actor is updated bysetActor
无论agent
是否作为输出参数返回。有关处理对象的更多信息,请参阅处理对象行为。
Version History
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(English)
- United States(English)
欧洲
- Belgium(English)
- 丹麦(English)
- Deutschland(德意志)
- España(Español)
- Finland(English)
- 法国(Français)
- 爱尔兰(English)
- 意大利(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(德意志)
- Portugal(English)
- Sweden(English)
- 瑞士
- 英国(English)