Main Content

mpnetLayers

Create custom motion planning networks

Since R2024a

Description

example

layers = mpnetLayers(numInputs,numOutputs) creates layers for motion planning networks (MPNet) with specified number of inputs and outputs.

The default network layer comprises one input layer, four hidden layers, and a fully connected output layer. The first two hidden layers contain a fully connected layer, ReLU layer, and a dropout layer. The last two hidden layers contain a fully connected layer and a ReLU layer. For more information about the MPNet, see Get Started with Motion Planning Networks.

example

layers = mpnetLayers(numInputs,numOutputs,Name=Value) specifies options to modify hidden layers and dropout layers in the network using one or more name-value arguments.

Note

To run this function, you will require the Deep Learning Toolbox™.

Examples

collapse all

Load the training data into the MATLAB® workspace.

load("mazeMapDatasetSmall.mat","dataset")

The training data consists of the optimal state samples computed for multiple, random values of start poses and goal poses on a maze map. Extract a map from the training data.

trainData = dataset;
map = trainData(1,1).Map;

Get the state bounds of the input map.

x = map.XWorldLimits;
y = map.YWorldLimits;
theta = [-pi pi];
stateBounds = [x; y; theta];

Create a custom Motion Planning Networks (MPNet) with two hidden layers and two dropout layers. Set the number of inputs to 308 and the number of outputs to 4.

layers = mpnetLayers(308,4,HiddenSizes=[256;128],DropoutProbabilities=[0.2;0.1])
layers = 
  1x8 Layer array with layers:

     1   'input'      Feature Input                308 features
     2   'fc1'        Fully Connected              256 fully connected layer
     3   'relu1'      ReLU                         ReLU
     4   'dropout1'   nav.algs.mpnetDropoutLayer   nav.algs.mpnetDropoutLayer
     5   'fc2'        Fully Connected              128 fully connected layer
     6   'relu2'      ReLU                         ReLU
     7   'dropout2'   nav.algs.mpnetDropoutLayer   nav.algs.mpnetDropoutLayer
     8   'output'     Fully Connected              4 fully connected layer

Create a mpnetSE2 object to store the custom MPNet.

  • Set the EncodingSize property value to [30 10]. The encoding size must be equal to the number of inputs to the network minus 8.

  • Set the StateBounds property value to the state bounds of the input map.

  • Set the LossWeights property value to [10 10 0].

  • Set the Network property value to the layer array representing the customized MPNet.

mpnet = mpnetSE2(EncodingSize=[30 10],StateBounds=stateBounds,LossWeights=[10 10 0],Network=layers)
mpnet = 
  mpnetSE2 with properties:

     StateBounds: [3x2 double]
     LossWeights: [10 10 0]
    EncodingSize: [30 10]
       NumInputs: 308
      NumOutputs: 4
         Network: [1x1 dlnetwork]

Display and inspect the network architecture. You can now train this custom network by using the trainnet (Deep Learning Toolbox) function for state space sampling or motion planning.

analyzeNetwork(mpnet.Network)

Input Arguments

collapse all

Number of inputs to the network, specified as a positive integer scalar.

The number of inputs to the input layer must be sum of the number of state space variables representing the start state and goal state and the size of the encoded environment. For an SE(2) state space, the number of state variables given as inputs to the network is 4 for each of the start state and the goal state. If the size of the encoded environment is M-by-N then the number of inputs to the network is (M*N)+8

.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of outputs from the network, specified as a positive integer scalar. For SE(2) state space, number of outputs from the network must be specified as 4.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

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: mpnetlayers(numInputs,numOutputs,HiddenSizes=[256 128 64])

Size of hidden layers in the network, specified as a vector of positive integers. The length of the vector determines the number of hidden layers to add to the network, while the values in the vector specify the size for each hidden layer.trainnet (Deep Learning Toolbox).

The length of the vector must be greater than or equal to two. This implies that the network must have at least two hidden layers.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Probability of dropping out input elements in dropout layers, specified as a vector in the range [0, 1).

The length of the vector determines the number of dropout layers to add to the network, while the values in the vector specify the dropout probability for each dropout layer. The number of dropout layers in the network must be less than or equal to the number of hidden layers in the network.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

MPNet layers, returned as a layer array. The layer array represent the network architecture of a MPNet to use for state space sampling or motion planning. For more information about layer array, see Layer (Deep Learning Toolbox).

Version History

Introduced in R2024a