main content

deterministic transition function approximator object for neural network-凯发k8网页登录

deterministic transition function approximator object for neural network-based environment

since r2022a

description

when creating a neural network-based environment using rlneuralnetworkenvironment, you can specify deterministic transition function approximators using rlcontinuousdeterministictransitionfunction objects.

a transition function approximator object uses a deep neural network to predict the next observations based on the current observations and actions.

to specify stochastic transition function approximators, use rlcontinuousgaussiantransitionfunction objects.

creation

description

example

tsnfcnappx = rlcontinuousdeterministictransitionfunction(net,observationinfo,actioninfo,name=value) creates a deterministic transition function approximator object using the deep neural network net and sets the observationinfo and actioninfo properties.

when creating a deterministic transition function approximator you must specify the names of the deep neural network inputs and outputs using the observationinputnames, actioninputnames, and nextobservationoutputnames name-value pair arguments.

you can also specify the predictdiff and usedevice properties using optional name-value pair arguments. for example, to use a gpu for prediction, specify usedevice="gpu".

input arguments

deep neural network, specified as a dlnetwork object.

the input layer names for this network must match the input names specified using observationinputnames and actioninputnames. the dimensions of the input layers must match the dimensions of the corresponding observation and action specifications in observationinfo and actioninfo, respectively.

the output layer names for this network must match the output names specified using nextobservationoutputnames. the dimensions of the input layers must match the dimensions of the corresponding observation specifications in observationinfo.

name-value arguments

specify optional pairs of arguments as name1=value1,...,namen=valuen, where name is the argument name and value is the corresponding value. name-value arguments must appear after other arguments, but the order of the pairs does not matter.

example: observationinputnames="velocity"

observation input layer names, specified as a string or string array.

the number of observation input names must match the length of observationinfo and the order of the names must match the order of the specifications in observationinfo.

action input layer names, specified as a string or string array.

the number of action input names must match the length of actioninfo and the order of the names must match the order of the specifications in actioninfo.

next observation output layer names, specified as a string or string array.

the number of next observation output names must match the length of observationinfo and the order of the names must match the order of the specifications in observationinfo.

properties

this property is read-only.

observation specifications, specified as an rlnumericspec object or an array of such objects. each element in the array defines the properties of an environment observation channel, such as its dimensions, data type, and name.

you can extract the observation specifications from an existing environment or agent using getobservationinfo. you can also construct the specifications manually using rlnumericspec.

this property is read-only.

action specifications, specified as an rlfinitesetspec or rlnumericspec object. this object defines the properties of the environment action channel, such as its dimensions, data type, and name.

note

only one action channel is allowed.

you can extract the action specifications from an existing environment or agent using getactioninfo. you can also construct the specification manually using rlfinitesetspec or rlnumericspec.

option to predict the difference between the current observation and the next observation, specified as one of the following logical values.

  • false — select this option if net outputs the value of the next observation.

  • true — select this option if net outputs the difference between the next observation and the current observation. in this case, the predict function computes the next observation by adding the current observation to the output of net.

computation device used to perform operations such as gradient computation, parameter updates, and prediction during training and simulation, specified as either "cpu" or "gpu".

the "gpu" option requires both parallel computing toolbox™ software and a cuda®-enabled nvidia® gpu. for more information on supported gpus see gpu computing requirements (parallel computing toolbox).

you can use gpudevice (parallel computing toolbox) to query or select a local gpu device to be used with matlab®.

note

training or simulating a network on a gpu involves device-specific numerical round-off errors. these errors can produce different results compared to performing the same operations using a cpu.

object functions

rlneuralnetworkenvironmentenvironment model with deep neural network transition models

examples

create an environment interface and extract observation and action specifications. alternatively, you can create specifications using rlnumericspec and rlfinitesetspec.

env = rlpredefinedenv("cartpole-continuous");
obsinfo = getobservationinfo(env);
actinfo = getactioninfo(env);

to approximate the transition function, create a deep neural network. the network has two input layers, one for the current observation channel and one for the current action channel. the single output layer is for the predicted next observation.

define each network path as an array of layer objects. get the dimensions of the observation and action spaces from the environment specifications, and specify a name for the input and output layers, so you can later explicitly associate them with the appropriate environment channel.

statepath = featureinputlayer(obsinfo.dimension(1),name="state");
actionpath = featureinputlayer(actinfo.dimension(1),name="action");
commonpath = [concatenationlayer(1,2,name="concat")
    fullyconnectedlayer(64)
    relulayer
    fullyconnectedlayer(64)
    relulayer
    fullyconnectedlayer(obsinfo.dimension(1),name="nextobservation")];
tsnnet = layergraph(statepath);
tsnnet = addlayers(tsnnet,actionpath);
tsnnet = addlayers(tsnnet,commonpath);
tsnnet = connectlayers(tsnnet,"state","concat/in1");
tsnnet = connectlayers(tsnnet,"action","concat/in2");
plot(tsnnet)

figure contains an axes object. the axes object contains an object of type graphplot.

create a dlnetwork object, and display the number of weights.

tsnnet = dlnetwork(tsnnet);
summary(tsnnet)
   initialized: true
   number of learnables: 4.8k
   inputs:
      1   'state'    4 features
      2   'action'   1 features

create a deterministic transition function object.

tsnfcnappx = rlcontinuousdeterministictransitionfunction(...
    tsnnet,obsinfo,actinfo,...
    observationinputnames="state", ...
    actioninputnames="action", ...
    nextobservationoutputnames="nextobservation");

using this transition function object, you can predict the next observation based on the current observation and action. for example, predict the next observation for a random observation and action.

obs = rand(obsinfo.dimension);
act = rand(actinfo.dimension);
nextobsp = predict(tsnfcnappx,{obs},{act})
nextobsp = 1x1 cell array
    {4x1 single}
nextobsp{1}
ans = 4x1 single column vector
   -0.1172
    0.1168
    0.0493
   -0.0155

you can also obtain the same result using evaluate.

nextobse = evaluate(tsnfcnappx,{obs,act})
nextobse = 1x1 cell array
    {4x1 single}
nextobse{1}
ans = 4x1 single column vector
   -0.1172
    0.1168
    0.0493
   -0.0155

version history

introduced in r2022a

网站地图