Comparer

This module handles comparison.

Documentation

The comparer module is responsible for analyzing the effects of changing a variable. It takes care of running the simulations, compiling the data, and producing graphs.

class pykaryote.utils.comparison.Comparer(sim_config, cmp_config, name='Experiment', data='.', clear=True, identical_genomes=True)

Runs a bunch of simulations with slight differences and aggregates the results.

Args:

sim_config (str) the template configuration file for the experiment

cmp_config (str) the comparison configuration file for the experiment

name (str): the name of the comparison; defaults to Experiment

data (str): the data directory; defaults to the current directory.

identical_genomes (bool): whether all of the trials simulations should start out with the same set of genomes (identical generation 0)

run(verbose=True)
Args:
verbose
class pykaryote.utils.comparison.AnalyzerAggregator(data_dir, comparison_name, cmp_values, sim_config)

Aggregates data from multiple simulations into a comparative-analyzer directory.

When a comparison is run, it creates an analyzer directory for each type of simulation. AnalyzerAggregator combines them by putting the columns next to each other. For example, combining three simulations, each with one column of data, produces a data file with three columns - one for each simulation.

compile_all()

Compiles all data files into a single comparative-analyzer dir.

compile_metric(metric, read_style)

Compile a single type of data file.

Args:

metric (str): the filename to read and write

read_style (str):

  • if one_col, then the metric is assumed to have only one column.

  • if each_col, then each column is treated as its own metric,

    and they are each written to “<metric_name>-<col#>”

class pykaryote.utils.comparison.Grapher(data_folder, sim_config, cmp_config_filename=None, verbose=True)

Takes a comparison’s analyzer directory and provides methods for plotting the data.

Args:
data_folder (str): a folder which contains a folder named comparative-analyzer, which has the necessary data.
draw_environment(save_dir)

Draws the chemical environment and saves as an image.

plot(metric)
Args:
metric (str): the name of the file to be plotted, inside of the directory “comparative-analyzer”. Columns must correspond to values of vary_attr and rows to generations.
plot_final_values(metric)

Plots a bar graph of the final values of a metric.

Each var_attr is a bar on the x axis. metric is the y axis. The value of each bar is the value of metric at the last generation.

Input files contain 2d numpy arrays containing values for metric, where each row is a generation and each column corresponds to a value of self.vary_attrs.

For example:
x-axis (bars) = varying config parameter
(ex: cost of genome length)
y-axis = final value for a metric after 1000 runs
(ex: average complexity)
Args:
metric (str): The metric to plot.
plot_threshold(metric, thresholds, save_dir=None)

Plots a scatter plot of the number of generations it took a metric to pass a threshold value.

These graphs are specified in the ‘threshold-metrics’ section of a simulation’s configuration file.

save_all()

Saves images of the plots of all of the metrics

save_time_spent_in_gaussian()

Plots time_spent_in_gaussian data.

Data should only be present if num_runs == 0. Data files are located in folders named comparative-analyzer/sim-x/, where x is a number associated with each simulation.

pykaryote.utils.comparison.get_config(filename)

Reads a comparison configuration file.

Args:
filename: The filename of comparison configuration file.

Returns a tuple of (tuple of option names, list of tuples of values to use)

If a line begins with a (, it is simply eval-ed. (options should
have quotes!)
If the first line doesn’t begin with a (, then the text is surrounded
by quotes and put in a tuple.
If subsequent lines don’t begin with a (, then they are simply
placed into tuples.
pykaryote.utils.comparison.make_cfg(options, replacement_values, base_config, out_filename)

Create a sim config file by replacing options in base_config.

Replaces options in base_config with values from replacement_values and saves the resulting simulation configuration file to out_filename.

Used to create a sim.cfg config file from a cmp.cfg comparison config.

pykaryote.utils.comparison.get_metrics_files(folder, metric)

Gets the list of files associated with metric.

Args:
folder (str): the path to the “comparative-analyzer” folder. Must have a trailing ‘/’. metric (str): the name of the metric.

Returns [str..]: the filenames that match.

Table Of Contents

Previous topic

Globals

Next topic

Test

This Page