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.

The post_processing_function can have two possible signatures:

  1. post_processing_function(case_definition, sample_result)
  2. post_processing_function(sample_result)

Where case_definition is a dict of all variables introduced in the do_mpc.sampling.samplingplanner.SamplingPlanner and sample_results is the result obtained from the function introduced with do_mpc.sampling.sampler.Sampler.set_sample_function.


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


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



# 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:
  • name (string) – Name of the output of the post-processing operation
  • post_processing_function – The post processing function to be evaluted
  • 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.