Main Content

rlIsDoneFunction

Is-done function approximator object for neural network-based environment

    Description

    When creating a neural network-based environment using rlNeuralNetworkEnvironment, you can specify the is-done function approximator using an rlIsDoneFunction object. Do so when you do not know a ground-truth termination signal for your environment.

    The is-done function approximator object uses a deep neural network as internal approximation model to predict the termination signal for the environment given one of the following input combinations.

    • Observations, actions, and next observations

    • Observations and actions

    • Actions and next observations

    • Next observations

    Creation

    Description

    example

    isdFcnAppx = rlIsDoneFunction(net,observationInfo,actionInfo,Name=Value) creates the is-done function approximator object isdFcnAppx using the deep neural network net and sets the ObservationInfo and ActionInfo properties.

    When creating an is-done function approximator you must specify the names of the deep neural network inputs using one of the following combinations of name-value pair arguments.

    You can also specify the UseDeterministicPredict and UseDevice properties using optional name-value pair arguments. For example, to use a GPU for prediction, specify UseDevice="gpu".

    Input Arguments

    expand all

    Deep neural network with a scalar output value, specified as a dlnetwork object.

    The input layer names for this network must match the input names specified using the ObservationInputNames, ActionInputNames, and NextObservationInputNames. The dimensions of the input layers must match the dimensions of the corresponding observation and action specifications in ObservationInfo and ActionInfo, respectively.

    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. Specify ObservationInputNames when you expect the termination signal to depend on the current environment observation.

    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. Specify ActionInputNames when you expect the termination signal to depend on the current action value.

    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 input layer names, specified as a string or string array. Specify NextObservationInputNames when you expect the termination signal to depend on the next environment observation.

    The number of next observation input names must match the length of ObservationInfo and the order of the names must match the order of the specifications in ObservationInfo.

    Properties

    expand all

    This property is read-only.

    Observation specifications, specified as a reinforcement learning specification object or an array of specification objects defining properties such as dimensions, data type, and names of the observation signals.

    You can extract the observation specifications from an existing environment or agent using getObservationInfo. You can also construct the specifications manually using rlFiniteSetSpec or rlNumericSpec.

    This property is read-only.

    Action specifications, specified as a reinforcement learning specification object or an array of specification objects defining properties such as dimensions, data type, and names of the action signals.

    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 terminal signal deterministically, specified as one of the following values.

    • true — Use deterministic network prediction.

    • false — Use stochastic network prediction.

    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 Support by Release (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

    collapse all

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

    Create a deep neural network. The network has one input channel for the next observations. The single output channel is for the predicted termination signal.

    commonPath = [featureInputLayer(obsInfo.Dimension(1), ...
                       Normalization="none",Name="nextState");
        fullyConnectedLayer(64,Name="FC1")
        reluLayer(Name="CriticRelu1")
        fullyConnectedLayer(64,Name="FC3")
        reluLayer(Name="CriticCommonRelu2")
        fullyConnectedLayer(2,Name="isdone0")
        softmaxLayer(Name="isdone")];
    
    isDoneNetwork = layerGraph(commonPath);
    
    plot(isDoneNetwork)

    Figure contains an axes object. The axes object contains an object of type graphplot.

    Covert the network to a dlnetwork object.

    isDoneNetwork = dlnetwork(isDoneNetwork);

    Create an is-done function approximator object.

    isDoneFcnAppx = rlIsDoneFunction(...
        isDoneNetwork,obsInfo,actInfo,...
        NextObservationInputNames="nextState");

    Using this is-done function approximator object, you can predict the termination signal based on the next observation. For example, predict the termination signal for a random next observation. Since for this example the termination signal only depends on the next observation, use empty cell arrays for the current action and observation inputs.

    nxtobs = rand(obsInfo.Dimension);
    predIsDone = predict(isDoneFcnAppx,{},{},{nxtobs})
    predIsDone = 0
    

    You can obtain the termination probability using evaluate.

    predIsDoneProb = evaluate(isDoneFcnAppx,{nxtobs})
    predIsDoneProb = 1x1 cell array
        {2x1 single}
    
    
    predIsDoneProb{1}
    ans = 2x1 single column vector
    
        0.5405
        0.4595
    
    

    The first number is the probability of obtaining a 0 (no termination predicted), the second one is the probability of obtaining a 1 (termination predicted).

    Version History

    Introduced in R2022a