bus2RLSpec
Create reinforcement learning data specifications for elements of a Simulink bus
Description
creates a set of reinforcement learning data specifications from the Simulink® bus object specified by specs
= bus2RLSpec(busName
)busName
. One specification
element is created for each leaf element in the corresponding Simulink bus. Use these
specifications to define an observations containing multiple channels for a Simulink reinforcement learning environment.
specifies options for creating specifications using one or more
specs
= bus2RLSpec(busName
,Name=Value
)Name=Value
arguments.
Examples
Create an Observation Specification Object from a Bus Object
This example shows how to use the function bus2RLSpec
to create an observation specification object from a Simulink® bus object.
Create a bus object.
obsBus = Simulink.Bus();
Create three elements in the bus and specify their names.
obsBus.Elements(1) = Simulink.BusElement; obsBus.Elements(1).Name = "sin_theta"; obsBus.Elements(2) = Simulink.BusElement; obsBus.Elements(2).Name = "cos_theta"; obsBus.Elements(3) = Simulink.BusElement; obsBus.Elements(3).Name = "dtheta";
Create the observation specification objects using the Simulink bus object.
obsInfo = bus2RLSpec("obsBus");
You can then use obsInfo
, together with the corresponding Simulink model, to create a reinforcement learning environment. For an example, see Train DDPG Agent to Swing Up and Balance Pendulum with Bus Signal.
Create an Action Specification Object from a Bus Object
This example shows how to call the function bus2RLSpec
using name and value pairs to create an action specification object from a Simulink® bus object.
Create a bus object.
actBus = Simulink.Bus();
Create one element in the bus and specify the name.
actBus.Elements(1) = Simulink.BusElement;
actBus.Elements(1).Name = "actuator";
Create the observation specification objects using the Simulink bus object.
actInfo = bus2RLSpec("actBus","DiscreteElements",{"actuator",[-1 1]});
This specifies that the "actuator" bus element can carry two possible values, -1
, and 1
.
You can then use actInfo
, together with the corresponding Simulink model, to create a reinforcement learning environment. Specifically the function that creates the environment uses actInfo to determine the right bus output of the agent block.
For an example, see Train DDPG Agent to Swing Up and Balance Pendulum with Bus Signal.
Input Arguments
busName
— Name of Simulink bus object
string | character vector
Name of Simulink bus object, specified as a string or character vector.
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.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: DiscreteElements={'force',[-5 0 5]}
sets the
'force'
bus element to be a discrete data specification with three
possible values, -5
, 0
, and
5
Model
— Name of Simulink model
string | character vector
Name of the Simulink model, specified as the comma-separated pair consisting of
'Model'
and a string or character vector. Specify the model name
when the bus object is defined in the model global workspace (for example, in a data
dictionary) instead of the MATLAB® workspace.
BusElementNames
— Names of bus leaf elements
string array
Names of bus leaf elements for which to create specifications, specified as the
comma-separated pair consisting of 'BusElementNames'
and a string
array. To create observation specifications for a subset of the elements in a
Simulink bus object, specify BusElementNames
. If you do not
specify BusElementNames
, a data specification is created for each
leaf element in the bus.
Note
Do not specify BusElementNames
when creating specifications
for action signals. The RL Agent block must output the full bus
signal.
DiscreteElements
— Finite values for discrete bus elements
cell array of name-value pairs
Finite values for discrete bus elements, specified as the comma-separated pair
consisting of 'DiscreteElements'
and a cell array of name-value
pairs. Each name-value pair consists of a bus leaf element name and an array of
discrete values. The specified discrete values must be castable to the data type of
the specified action signal.
If you do not specify discrete values for an element specification, the element is continuous.
Example: 'ActionDiscretElements',{'force',[-10 0 10],'torque',[-5 0
5]}
specifies discrete values for the 'force'
and
'torque'
leaf elements of a bus action signal.
Output Arguments
specs
— Data specifications
rlNumericSpec
object | rlFiniteSetSpec
object | array of data specification objects
Data specifications for reinforcement learning actions or observations, returned as one of the following:
rlNumericSpec
object for a single continuous bus elementrlFiniteSetSpec
object for a single discrete bus elementArray of data specification objects for multiple bus elements
By default, all data specifications for bus elements are
rlNumericSpec
objects. To create a discrete specification for one or
more bus elements, specify the element names using the
DiscreteElements
name-value pair.
Version History
Introduced in R2019a
See Also
Functions
Objects
Blocks
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)