main content

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

stochastic gaussian transition function approximator object for neural network-based environment

since r2022a

description

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

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

to specify deterministic transition function approximators, use rlcontinuousgaussiantransitionfunction objects.

creation

description

example

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

when creating a stochastic transition function approximator, you must specify the names of the deep neural network inputs and outputs using the observationinputnames, actioninputnames, nextobservationmeanoutputnames, and nextobservationstandarddeviationoutputnames 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 mean output layer names, specified as a string or string array.

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

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

the number of next observation standard deviation 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.

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.

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.

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);

define the layers for the deep neural network. the network has two input channels, one for the current observations and one for the current actions. the output of the network is the predicted gaussian distribution for each next observation. the two output channels correspond to the means and standard deviations of these distribution.

statepath = featureinputlayer(obsinfo.dimension(1),name="obs");
actionpath = featureinputlayer(actinfo.dimension(1),name="act");
commonpath = [concatenationlayer(1,2,name="concat")
  fullyconnectedlayer(32,name="fc")
  relulayer(name="criticrelu1")
  fullyconnectedlayer(32,name="fc2")];
meanpath = [relulayer(name="nextobsmeanrelu")
  fullyconnectedlayer(obsinfo.dimension(1),name="nextobsmean")];
stdpath = [relulayer(name="nextobsstdrelu")
  fullyconnectedlayer(obsinfo.dimension(1),name="nextobsstdrelufull")
  softpluslayer(name="nextobsstd")];
tsnnet = layergraph(statepath);
tsnnet = addlayers(tsnnet,actionpath);
tsnnet = addlayers(tsnnet,commonpath);
tsnnet = addlayers(tsnnet,meanpath);
tsnnet = addlayers(tsnnet,stdpath);
tsnnet = connectlayers(tsnnet,"obs","concat/in1");
tsnnet = connectlayers(tsnnet,"act","concat/in2");
tsnnet = connectlayers(tsnnet,"fc2","nextobsmeanrelu");
tsnnet = connectlayers(tsnnet,"fc2","nextobsstdrelu");
plot(tsnnet)

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

create a dlnetwork object.

tsnnet = dlnetwork(tsnnet);

create a stochastic transition function object.

tsnfcnappx = rlcontinuousgaussiantransitionfunction(tsnnet,obsinfo,actinfo, ...
    observationinputnames="obs",...
    actioninputnames="act",...
    nextobservationmeanoutputnames="nextobsmean",...
    nextobservationstandarddeviationoutputnames="nextobsstd");

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. the next observation values are sampled from gaussian distributions with the means and standard deviations output by the transition network.

observation = rand(obsinfo.dimension);
action = rand(actinfo.dimension);
nextobs = predict(tsnfcnappx,{observation},{action})
nextobs = 1x1 cell array
    {4x1 single}
nextobs{1}
ans = 4x1 single column vector
    1.2414
    0.7307
   -0.5588
   -0.9567

you can also obtain the mean value and standard deviation of the gaussian distribution of the predicted next observation using evaluate.

nextobsdist = evaluate(tsnfcnappx,{observation,action})
nextobsdist=1×2 cell array
    {4x1 single}    {4x1 single}

version history

introduced in r2022a

网站地图