AMPCSampler#
- class AMPCSampler(mpc)[source]#
Bases:
objectClass to sample data for the ApproxMPC.
Added in version >v4.6.0..
This class randomly samples the MPC to generate data. This data can further be used to train the ApproxMPC.
Configuring and setting up the Sampler involves the following steps:
Configure the Sampler controller with
SamplerSettings. The Sampler instance has the attributesettingswhich is an instance ofSamplerSettings.To finalize the class configuration
setup()may be called. This method sets up the MPC and Simulator, if needed.
Usage:
The Sampler can be used in a closed loop setting by calling the
default_sampling()method. This method starts generating data based on the user settings.Example:
# pushing to class mpc.x0 = x0 mpc.set_initial_guess() # approximate mpc approx_mpc = ApproxMPC(mpc) approx_mpc.settings.n_hidden_layers = 3 approx_mpc.settings.n_neurons = 50 approx_mpc.setup() # sampler sampler = Sampler(mpc) sampler.settings.closed_loop_flag = True sampler.settings.trajectory_length = 5 sampler.settings.n_samples = 100 sampler.setup() sampler.default_sampling()
- Parameters:
mpc (do_mpc.controller.MPC) – The MPC class which is sampled.
Methods#
approx_mpc_closed_loop_sampling#
- approx_mpc_closed_loop_sampling(self)#
Closed loop sampling for the ApproxMPC.
This method generates closed loop samples for the ApproxMPC. The samples are saved in the data directory.
- Returns:
None
- Return type:
None
approx_mpc_open_loop_sampling#
- approx_mpc_open_loop_sampling(self)#
Open loop sampling for the ApproxMPC.
This method generates open loop samples for the ApproxMPC. The samples are saved in the data directory.
- Returns:
None
- Return type:
None
approx_mpc_sampling_plan_box#
- approx_mpc_sampling_plan_box(self)#
Generate sampling plan for the ApproxMPC.
This method generates a sampling plan for the ApproxMPC. The sampling plan is saved in the data directory.
- Returns:
None
- Return type:
None
default_sampling#
- default_sampling(self)#
Default sampling method.
This method is used to sample data for the ApproxMPC. The method generates data based on the user settings.
- Returns:
None
- Return type:
None
setup#
- setup(self)#
Setup the Sampler class.
This method sets up the MPC, and the Simulator if needed.
Note
This method should be called before calling any other method.
- Returns:
None
- Return type:
None
setup_simulator#
- setup_simulator(self)#
Setup the Simulator.
This function is only used when the closed_loop_flag is set to True. It sets up the Simulator for the closed loop sampling.
Warning
Ensure that mpc.settings.n_robust == 0, when closed_loop_flag is set to True. Currently the Sampler does not support robust mpc.
- Returns:
None
- Return type:
None
Attributes#
settings#
- AMPCSampler.settings#
Sampler settings. This attribute is an instance of
SamplerSettings. It is used to configure the Sampler.- Returns:
The settings for the Sampler.
- Return type:
SamplerSettings
simulator_settings#
- AMPCSampler.simulator_settings#
Simulator settings.
This attribute is an instance of
do_mpc.simulator.SimulatorSettings. It is used to configure the Simulator.- Returns:
The settings for the Simulator.
- Return type: