sample
Description
Examples
Compute State Samples Using MPNet State Sampler
Load Pretrained MPNet
Load a data file containing a pretrained MPNet into the MATLAB® workspace. The MPNet has been trained on various 2-D maze maps with widths and heights of 10 meters and resolutions of 2.5 cells per meter. Each maze map contains a passage width of 5 grid cells and wall thickness of 1 grid cell.
data = load("mazeMapTrainedMPNET.mat")
data = struct with fields:
encodingSize: [9 9]
lossWeights: [100 100 0]
mazeParams: {[5] [1] 'MapSize' [10 10] 'MapResolution' [2.5000]}
stateBounds: [3x2 double]
trainedNetwork: [1x1 dlnetwork]
Create Maze Map for Sampling
Create a random maze map for sampling. The grid size () must be the same as that of the maps used for training the MPNet.
map = mapMaze(5,1,MapSize=[10 10],MapResolution=2.5);
Specify the start pose and goal pose.
start = [1 1 0]; goal = [9 9 0];
Create MPNet State Sampler
Specify the state bounds, and create an SE(2) state space object.
x = map.XWorldLimits; y = map.YWorldLimits; z = [-pi pi]; stateBounds = [x; y; z]; stateSpace = stateSpaceSE2(stateBounds);
Configure the mpnetSE2
object to use the pretrained MPNet for predicting state samples on a random map. Set the EncodingSize
property values of the mpnetSE2
object to that of the value used for training the network.
mpnet = mpnetSE2(Network=data.trainedNetwork,StateBounds=stateBounds,EncodingSize=data.encodingSize);
Create an MPNet state sampler for the computing state samples. Specify the map environment, the start pose and the goal pose as inputs to the state sampler.
sampler = stateSamplerMPNET(stateSpace,mpnet,Environment=map,StartState=start,GoalState=goal);
Compute State Samples and Plot Results
Generate 40 state samples using the MPNet state sampler.
states = sample(sampler,40);
Plot the input data and the computed samples.
show(map) hold on plot(start(1),start(2),plannerLineSpec.start{:}) plot(goal(1),goal(2),plannerLineSpec.goal{:}) plot(states(:,1),states(:,2),plannerLineSpec.state{:}) hold off legend(Location="bestoutside")
Input Arguments
sampler
— MPNet state sampler
stateSamplerMPNET
object
MPNet state sampler, specified as a stateSamplerMPNET
object.
numsamples
— Number of samples
1
(default) | positive integer
Number of samples, specified as a positive integer.
Data Types: double
Output Arguments
states
— State samples
M-by-N matrix of real values
State samples, returned as an M-by-N matrix of real values. M is the number of state samples. N is the number of state variables. Each row of the matrix contains state variables corresponding to the input state space model. For the SE(2) state space model, N is 3 and each row is of the form [x y θ].
Data Types: double
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2023b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
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: .
You can also select a web site from the following list
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érica Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)