testing

Module of classes used to test M-LOOP.

class mloop.testing.FakeExperiment(test_landscape=None, experiment_file_type='txt', exp_wait=0, poll_wait=1, **kwargs)

Bases: threading.Thread

Pretends to be an experiment and reads files and prints files based on the costs provided by a TestLandscape. Executes as a thread.

Keyword Arguments:
 
  • test_landscape (Optional TestLandscape) – landscape to generate costs from.
  • experiment_file_type (Optional [string]) – currently supports: ‘txt’ where the output is a text file with the parameters as a list of numbers, and ‘mat’ a matlab file with variable parameters with the next_parameters. Default is ‘txt’.
Attributes
self.end_event (Event): Used to trigger end of experiment.
run()

Implementation of file read in and out. Put parameters into a file and wait for a cost file to be returned.

set_landscape(test_landscape)

Set new test landscape.

Parameters:test_landscape (TestLandscape) – Landscape to generate costs from.
class mloop.testing.TestLandscape(num_params=1)

Bases: object

Produces fake landscape data for testing, default functions are set for each of the methods which can then be over ridden.

Keyword Arguments:
 num_parameters (Optional [int]) – Number of parameters for landscape, defaults to 1.
get_cost_dict(params)

Return cost from fake landscape given parameters.

Parameters:params (array) – Parameters to evaluate cost.
set_bad_region(min_boundary, max_boundary, bad_cost=None, bad_uncer=None)

Adds a region to landscape that is reported as bad.

Parameters:
  • min_boundary (array) – mininum boundary for bad region
  • max_boundary (array) – maximum boundary for bad region
set_default_landscape()

Set landscape functions to their defaults

set_noise_function(proportional=0.0, absolute=0.0)

Adds noise to the function.

with the formula:

c'(c,x) = c (1 + s_p p) + s_a a

where s_i are gaussian random variables, p is the proportional noise factor and a is the absolute noise factor, and c is the cost before noise is added

the uncertainty is then:

u = sqrt((cp)^2 + a^2)
Keyword Arguments:
 
  • proportional (Optional [float]) – the proportional factor. Defaults to 0
  • absolute (Optional [float]) – the absolute factor. Defaults to 0
set_quadratic_landscape(minimum=None, scale=None)

Set deterministic part of landscape to be a quadratic.

with the formula:

c(x) = \sum_i a_i * (x_i - x_0,i)^2

where x_i are the parameters, x_0,i is the location of the minimum and a_i are the scaling factors.

Keyword Arguments:
 
  • minimum (Optional [array]) – Location of the minimum. If set to None is at the origin. Default None.
  • scales (Optional [array]) – scaling of quadratic along the dimention specified. If set to None the scaling is one.
set_random_quadratic_landscape(min_region, max_region, random_scale=True, min_scale=0, max_scale=3)

Make a quadratic function with a minimum randomly placed in a region with random scales

Parameters:
  • min_region (array) – minimum region boundary
  • max_region (array) – maximum region boundary
Keyword Arguments:
 
  • random_scale (Optional bool) – If true randomize the scales of the parameters. Default True.
  • min_scale (float) – Natural log of minimum scale factor. Default 0.
  • max_scale (float) – Natural log of maximum scale factor. Default 3.