class do_mpc.sampling.sampler.Sampler(sampling_plan)[source]

Generate samples based on a sampling plan. Initiate the class by passing a do_mpc.sampling.samplingplanner.SamplingPlanner (sampling_plan) object. The class can be configured to create samples based on the defined cases in the sampling_plan.

Configuration and sampling:

  1. (Optional) use set_param() to configure the class. Use data_dir to choose the save location for the samples.
  2. Set the sample generating function with set_sample_function(). This function is executed for each of the samples in the sampling_plan.
  3. Use sample_data() to generate all samples defined in the sampling_plan. A new file is written for each sample.
  4. Or: Create an individual sample result with sample_idx(), where an index (int) referring to the sampling_plan determines the sampled case.


By default, the Sampler will only create samples that do not already exist in the chosen data_dir.


sp = do_mpc.sampling.SamplingPlanner()

# Plan with two variables alpha and beta:
sp.set_sampling_var('alpha', np.random.randn)
sp.set_sampling_var('beta', lambda: np.random.randint(0,5))

plan = sp.gen_sampling_plan(n_samples=10)

sampler = do_mpc.sampling.Sampler(plan)

# Sampler computes the product of two variables alpha and beta
# that were created in the SamplingPlanner:

def sample_function(alpha, beta):
    return alpha*beta




Sampler.data_dir Set the save directory for the results.


Sampler.sample_data Sample data after having configured the Sampler.
Sampler.sample_idx Sample case based on the index of the sample.
Sampler.set_param Configure the Sampler class.
Sampler.set_sample_function Set sample generating function.

This page is auto-generated. Page source is not available on Github.