visualizations

Module of classes used to create visualizations of data produced by the experiment and learners.

class mloop.visualizations.ControllerVisualizer(filename, file_type=None, **kwargs)

Bases: object

ControllerVisualizer creates figures from a Controller Archive.

Parameters:filename (String) – Filename of the controller archive.
Keyword Arguments:
 file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
create_visualizations(plot_cost_vs_run=True, plot_parameters_vs_run=True, plot_parameters_vs_cost=True, max_parameters_per_plot=None)

Runs the plots for a controller file.

Keyword Arguments:
 
  • plot_cost_vs_run (Optional [bool]) – If True plot cost versus run number, else do not. Default True.
  • plot_parameters_vs_run (Optional [bool]) – If True plot parameters versus run number, else do not. Default True.
  • plot_parameters_vs_cost (Optional [bool]) – If True plot parameters versus cost number, else do not. Default True.
  • max_parameters_per_plot (Optional [int]) – The maximum number of parameters to include in plots that display the values of parameters. If the number of parameters is larger than parameters_per_plot, then the parameters will be divided into groups and each group will be plotted in its own figure. If set to None, then all parameters will be included in the same plot regardless of how many there are. Default None.
plot_cost_vs_run()

Create a plot of the costs versus run number.

plot_parameters_vs_cost(parameter_subset=None)

Create a plot of the parameters versus run number.

Parameters:parameter_subset (list-like) – The indices of parameters to plot. The indices should be 0-based, i.e. the first parameter is identified with index 0. Generally the values of the indices in parameter_subset should be between 0 and the number of parameters minus one, inclusively. If set to None, then all parameters will be plotted. Default None.
plot_parameters_vs_run(parameter_subset=None)

Create a plot of the parameters versus run number.

Parameters:parameter_subset (list-like) – The indices of parameters to plot. The indices should be 0-based, i.e. the first parameter is identified with index 0. Generally the values of the indices in parameter_subset should be between 0 and the number of parameters minus one, inclusively. If set to None, then all parameters will be plotted. Default None.
class mloop.visualizations.DifferentialEvolutionVisualizer(filename, file_type=None, **kwargs)

Bases: object

DifferentialEvolutionVisualizer creates figures from a differential evolution archive.

Parameters:filename (String) – Filename of the DifferentialEvolutionVisualizer archive.
Keyword Arguments:
 file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
create_visualizations(plot_params_vs_generations=True, plot_costs_vs_generations=True, max_parameters_per_plot=None)

Runs the plots from a differential evolution learner file.

Keyword Arguments:
 
  • plot_params_generations (Optional [bool]) – If True plot parameters vs generations, else do not. Default True.
  • plot_costs_generations (Optional [bool]) – If True plot costs vs generations, else do not. Default True.
  • max_parameters_per_plot (Optional [int]) – The maximum number of parameters to include in plots that display the values of parameters. If the number of parameters is larger than parameters_per_plot, then the parameters will be divided into groups and each group will be plotted in its own figure. If set to None, then all parameters will be included in the same plot regardless of how many there are. Default None.
plot_costs_vs_generations()

Create a plot of the costs versus run number.

plot_params_vs_generations(parameter_subset=None)

Create a plot of the parameters versus run number.

Parameters:parameter_subset (list-like) – The indices of parameters to plot. The indices should be 0-based, i.e. the first parameter is identified with index 0. Generally the values of the indices in parameter_subset should be between 0 and the number of parameters minus one, inclusively. If set to None, then all parameters will be plotted. Default None.
class mloop.visualizations.GaussianProcessVisualizer(filename, file_type=None, **kwargs)

Bases: mloop.learners.GaussianProcessLearner

GaussianProcessVisualizer extends of GaussianProcessLearner, designed not to be used as a learner, but to instead post process a GaussianProcessLearner archive file and produce useful data for visualization of the state of the learner. Fixes the Gaussian process hyperparameters to what was last found during the run.

Parameters:filename (String) – Filename of the GaussianProcessLearner archive.
Keyword Arguments:
 file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
create_visualizations(plot_cross_sections=True, plot_hyperparameters_vs_run=True, plot_noise_level_vs_run=True, max_parameters_per_plot=None)

Runs the plots from a gaussian process learner file.

Keyword Arguments:
 
  • plot_cross_sections (Optional [bool]) – If True plot predicted landscape cross sections, else do not. Default True.
  • plot_hyperparameters_vs_run (Optional [bool]) – If True plot fitted hyperparameters as a function of run number, else do not. Default True.
  • plot_noise_level_vs_run (Optional [bool]) – If True plot the fitted noise level as a function of run number, else do not. If there is no fitted noise level (i.e. cost_has_noise was set to False), then this plot will not be made regardless of the value passed for plot_noise_level_vs_run. Default True.
  • max_parameters_per_plot (Optional [int]) – The maximum number of parameters to include in plots that display the values of parameters. If the number of parameters is larger than parameters_per_plot, then the parameters will be divided into groups and each group will be plotted in its own figure. If set to None, then all parameters will be included in the same plot regardless of how many there are. Default None.
plot_cross_sections(parameter_subset=None)

Produce a figure of the cross section about best cost and parameters.

Parameters:parameter_subset (list-like) – The indices of parameters to plot. The indices should be 0-based, i.e. the first parameter is identified with index 0. Generally the values of the indices in parameter_subset should be between 0 and the number of parameters minus one, inclusively. If set to None, then all parameters will be plotted. Default None.
plot_hyperparameters_vs_run(parameter_subset=None)

Produce a figure of the hyperparameters as a function of run number.

Parameters:parameter_subset (list-like) – The indices of parameters to plot. The indices should be 0-based, i.e. the first parameter is identified with index 0. Generally the values of the indices in parameter_subset should be between 0 and the number of parameters minus one, inclusively. If set to None, then all parameters will be plotted. Default None.
plot_noise_level_vs_run()

This method plots the fitted noise level as a function of run number.

This plot is only relevant to optimizations for which cost_has_noise is True. If cost_has_noise is False then this method does nothing and silently returns.

return_cross_sections(points=100, cross_section_center=None)

Finds the predicted global minima, then returns a list of vectors of parameters values, costs and uncertainties, corresponding to the 1D cross sections along each parameter axis through the predicted global minima.

Keyword Arguments:
 
  • points (int) – the number of points to sample along each cross section. Default value is 100.
  • cross_section_center (array) – parameter array where the centre of the cross section should be taken. If None, the parameters for the best returned cost are used.
Returns:

a tuple (cross_arrays, cost_arrays, uncer_arrays) cross_parameter_arrays (list): a list of arrays for each cross section, with the values of the varied parameter going from the minimum to maximum value. cost_arrays (list): a list of arrays for the costs evaluated along each cross section about the minimum. uncertainty_arrays (list): a list of uncertainties

run()

Overides the GaussianProcessLearner multiprocessor run routine. Does nothing but makes a warning.

class mloop.visualizations.NeuralNetVisualizer(filename, file_type=None, **kwargs)

Bases: mloop.learners.NeuralNetLearner

NeuralNetVisualizer extends of NeuralNetLearner, designed not to be used as a learner, but to instead post process a NeuralNetLearner archive file and produce useful data for visualization of the state of the learner.

Parameters:filename (String) – Filename of the NeuralNetLearner archive.
Keyword Arguments:
 file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
create_visualizations(plot_cross_sections=True, max_parameters_per_plot=None)

Creates plots from a neural net’s learner file.

Keyword Arguments:
 
  • plot_cross_sections (Optional [bool]) – If True plot predicted landscape cross sections, else do not. Default True.
  • max_parameters_per_plot (Optional [int]) – The maximum number of parameters to include in plots that display the values of parameters. If the number of parameters is larger than parameters_per_plot, then the parameters will be divided into groups and each group will be plotted in its own figure. If set to None, then all parameters will be included in the same plot regardless of how many there are. Default None.
do_cross_sections(parameter_subset=None)

Produce a figure of the cross section about best cost and parameters.

Parameters:parameter_subset (list-like) – The indices of parameters to plot. The indices should be 0-based, i.e. the first parameter is identified with index 0. Generally the values of the indices in parameter_subset should be between 0 and the number of parameters minus one, inclusively. If set to None, then all parameters will be plotted. Default None.
plot_density_surface()

Produce a density plot of the cost surface (only works when there are 2 parameters)

plot_losses()

Produce a figure of the loss as a function of training run for each net.

plot_surface()

Produce a figure of the cost surface (only works when there are 2 parameters)

return_cross_sections(points=100, cross_section_center=None)

Finds the predicted global minima, then returns a list of vectors of parameters values, costs and uncertainties, corresponding to the 1D cross sections along each parameter axis through the predicted global minima.

Keyword Arguments:
 
  • points (int) – the number of points to sample along each cross section. Default value is 100.
  • cross_section_center (array) – parameter array where the centre of the cross section should be taken. If None, the parameters for the best returned cost are used.
Returns:

a tuple (cross_arrays, cost_arrays, uncer_arrays) cross_parameter_arrays (list): a list of arrays for each cross section, with the values of the varied parameter going from the minimum to maximum value. cost_arrays (list): a list of arrays for the costs evaluated along each cross section about the minimum. uncertainty_arrays (list): a list of uncertainties

run()

Overides the GaussianProcessLearner multiprocessor run routine. Does nothing but makes a warning.

mloop.visualizations._color_from_controller_name(controller_name)

Gives a color (as a number betweeen zero an one) corresponding to each controller name string.

mloop.visualizations._color_list_from_num_of_params(num_of_params)

Gives a list of colors based on the number of parameters.

mloop.visualizations._ensure_parameter_subset_valid(visualizer, parameter_subset)

Make sure indices in parameter_subset are acceptable.

Parameters:
  • visualizer (ControllerVisualizer-like) – An instance of one of the visualization classes defined in this module, which should have the attributes param_numbers and log.
  • parameter_subset (list-like) – The indices corresponding to a subset of the optimization parameters. The indices should be 0-based, i.e. the first parameter is identified with index 0. Generally the values of the indices in parameter_subset should be integers between 0 and the number of parameters minus one, inclusively.
mloop.visualizations.configure_plots()

Configure the setting for the plots.

mloop.visualizations.create_controller_visualizations(filename, file_type=None, **kwargs)

Runs the plots for a controller file.

Parameters:

filename (String) – Filename of the controller archive.

Keyword Arguments:
 
  • file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
  • **kwargs – Additional keyword arguments are passed to the visualizer’s create_visualizations() method.
mloop.visualizations.create_differential_evolution_learner_visualizations(filename, file_type=None, **kwargs)

Runs the plots from a differential evolution learner file.

Parameters:

filename (String) – Filename for the differential evolution learner archive.

Keyword Arguments:
 
  • file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
  • **kwargs – Additional keyword arguments are passed to the visualizer’s create_visualizations() method.
mloop.visualizations.create_gaussian_process_learner_visualizations(filename, file_type=None, **kwargs)

Runs the plots from a gaussian process learner file.

Parameters:

filename (String) – Filename for the gaussian process learner archive.

Keyword Arguments:
 
  • file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
  • **kwargs – Additional keyword arguments are passed to the visualizer’s create_visualizations() method.
mloop.visualizations.create_learner_visualizations(filename, max_parameters_per_plot=None, learner_visualization_kwargs=None, learner_visualizer_init_kwargs=None)

Runs the plots for a learner archive file.

Parameters:

filename (str) – Filename for the learner archive.

Keyword Arguments:
 
  • max_parameters_per_plot (Optional [int]) – The maximum number of parameters to include in plots that display the values of parameters. If the number of parameters is larger than parameters_per_plot, then the parameters will be divided into groups and each group will be plotted in its own figure. If set to None, then all parameters will be included in the same plot regardless of how many there are. If a value for max_parameters_per_plot is included in learner_visualization_kwargs, then the value in that dictionary will override this setting. Default None.
  • learner_visualization_kwargs (dict) – Keyword arguments to pass to the learner visualizer’s create_visualizations() method. If set to None, no additional keyword arguments will be passed. Default None.
  • learner_visualizer_init_kwargs (dict) – Keyword arguments to pass to the learner visualizer’s __init__() method. If set to None, no additional keyword arguments will be passed. Default None.
mloop.visualizations.create_learner_visualizer_from_archive(filename, controller_type=None, **kwargs)

Create an instance of the appropriate visualizer class for a learner archive.

Parameters:

filename (String) – Filename of the learner archive.

Keyword Arguments:
 
  • controller_type (String) – The type of controller used during the optimization that created the provided learner archive. Options include ‘gaussian_process’, ‘neural_net’, and ‘differential_evolution’. If set to None, then controller_type will be determined automatically from the archive. Default None.
  • **kwargs – Additional keyword arguments are passed to the visualizer’s __init__() method.
Returns:

An instance of the appropriate visualizer class for plotting

data from filename.

Return type:

visualizer

mloop.visualizations.create_neural_net_learner_visualizations(filename, file_type=None, **kwargs)

Creates plots from a neural net’s learner file.

Parameters:

filename (String) – Filename for the neural net learner archive.

Keyword Arguments:
 
  • file_type (String) – Can be ‘mat’ for matlab, ‘pkl’ for pickle or ‘txt’ for text. If set to None, then the type will be determined from the extension in filename. Default None.
  • **kwargs – Additional keyword arguments are passed to the visualizer’s create_visualizations() method.
mloop.visualizations.set_legend_location(loc=None)

Set the location of the legend in future figures.

Note that this function doesn’t change the location of legends in existing figures. It only changes where legends will appear in figures generated after the call to this function. If called without arguments, the legend location for future figures will revert to its default value.

Keyword Arguments:
 loc (Optional str, int, or pair of floats) – The value to use for loc in the calls to matplotlib’s legend(). Can be e.g. 2, ‘upper right’, (1, 0). See matplotlib’s documentation for more options and additional information. If set to None then the legend location will be set back to its default value. Default None.
mloop.visualizations.show_all_default_visualizations(controller, show_plots=True, max_parameters_per_plot=None)

Plots all visualizations available for a controller, and it’s internal learners.

Parameters:

controller (Controller) – The controller to extract plots from

Keyword Arguments:
 
  • show_plots (Optional, bool) – Determine whether to run plt.show() at the end or not. For debugging. Default True.
  • max_parameters_per_plot (Optional, int) – The maximum number of parameters to include in plots that display the values of parameters. If the number of parameters is larger than parameters_per_plot, then the parameters will be divided into groups and each group will be plotted in its own figure. If set to None, then all parameters will be included in the same plot regardless of how many there are. Default None.
mloop.visualizations.show_all_default_visualizations_from_archive(controller_filename, learner_filename, controller_type=None, show_plots=True, max_parameters_per_plot=None, controller_visualization_kwargs=None, learner_visualization_kwargs=None, learner_visualizer_init_kwargs=None)

Plots all visualizations available for a controller and its learner from their archives.

Parameters:
  • controller_filename (str) – The filename, inlcuding path, of the controller archive.
  • learner_filename (str) – The filename, inlcuding path, of the learner archive.
Keyword Arguments:
 
  • controller_type (str) – The value of controller_type type used in the optimization corresponding to the learner learner archive, e.g. ‘gaussian_process’, ‘neural_net’, or ‘differential_evolution’. If set to None then controller_type will be determined automatically. Default None.
  • show_plots (bool) – Determine whether to run plt.show() at the end or not. For debugging. Default True.
  • max_parameters_per_plot (Optional [int]) – The maximum number of parameters to include in plots that display the values of parameters. If the number of parameters is larger than parameters_per_plot, then the parameters will be divided into groups and each group will be plotted in its own figure. If set to None, then all parameters will be included in the same plot regardless of how many there are. If a value for max_parameters_per_plot is included in controller_visualization_kwargs, then the value in that dictionary will override this setting. The same applies to learner_visualization_kwargs. Default None.
  • controller_visualization_kwargs (dict) – Keyword arguments to pass to the controller visualizer’s create_visualizations() method. If set to None, no additional keyword arguments will be passed. Default None.
  • learner_visualization_kwargs (dict) – Keyword arguments to pass to the learner visualizer’s create_visualizations() method. If set to None, no additional keyword arguments will be passed. Default None.
  • learner_visualizer_init_kwargs (dict) – Keyword arguments to pass to the learner visualizer’s __init__() method. If set to None, no additional keyword arguments will be passed. Default None.