set_post_processing

Class method.

do_mpc.sampling.datahandler.DataHandler.set_post_processing(self, name, post_processing_function)

Set a post processing function. The post processing function is applied to all loaded samples, e.g. with __getitem__() or filter(). Users can set an arbitrary amount of post processing functions by repeatedly calling this method.

Note

Setting a post processing function with an already existing name will overwrite the previously set post processing function.

Example:

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.set_sample_function(sample_function)

sampler.sample_data()

# Create DataHandler object with same plan:
dh = do_mpc.sampling.DataHandler(plan)

# Assume you want to compute the square of the result of each sample
dh.set_post_processing('square', lambda res: res**2)

# As well as the value itself:
dh.set_post_processing('default', lambda res: res)

# Query all post-processed results with:
dh[:]
Parameters:
  • name (string) – Name of the output of the post-processing operation
  • post_processing_function – The post processing function to be evaluted
Raises:
  • assertion – name must be string
  • assertion – post_processing_function must be either Function of BuiltinFunction

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