optilab.utils package

Submodules

optilab.utils.aggregate_pvalues module

Aggregate pvalues for multiple algorithms and functions into one table.

aggregate_pvalues(pvalues_df: DataFrame, significance: float) DataFrame[source]

Aggregate p-values for multiple algorithms and functions into one table.

Parameters:
  • pvalues_df – DataFrame with columns: model, function, alternative, pvalue.

  • significance – Statistical significance threshold for the tests.

Returns:

DataFrame with function and alternative as the first two columns,

model names as remaining columns, and p-values as values.

optilab.utils.aggregate_stats module

Aggregation of median and iqr stats for various functions and models.

aggregate_stats(stats_df: DataFrame) DataFrame[source]

Aggregate median and iqr stats for various functions and models.

Parameters:

stats_df – DataFrame with columns: model, function, y_median, y_iqr.

Returns:

Dataframe with model names as columns, function names as rows,

and median and iqr as values.

optilab.utils.pickle_utils module

Functions related to loading and dumping optimization results to pickle files.

dump_to_pickle(data: Any, pickle_path: Path, zstd_compression: int | None = 1) None[source]

Dump data (such as List[OptimizationRun]) to a pickle file, with option to compress the data using zstandard. Compressed pickles should have *.zstd.pkl extension.

Parameters:
  • data – Data to save to a pickle file.

  • pickle_path – Path to file to save the data.

  • zstd_compression – Zstandard compression level. If None, then no compression is used.

load_from_pickle(pickle_path: Path) Any[source]

Load data (such as List[OptimizationRun]) from a pickle file. Zstandard compression is detected from the file extension (*.zstd.pkl).

Parameters:

pickle_path – Pickle file path to read from.

Returns:

Data read from the pickle.

list_all_pickles(path: Path) List[Path][source]

Given a path to either a file or directory return a list of all pickle files present there.

Parameters:

path – Either a path to a pickle file or path to directory containing pickle files.

Returns:

List of paths to found pickle files.

Raises:

ValueError – If the path is a file and not a pickle, or when the path is a directory and contains no pickles.

optilab.utils.stat_test module

Functions related to statistical testing.

mann_whitney_u_test_grid(data_lists: List[List[float]]) List[List[float]][source]

Perform a grid run of Mann-Whitney U test on given list of data values and return a 2d array with results.

Parameters:

data_lists – List of lists of values to perform test on.

Returns:

Results as a 2d array with p-values.

display_test_grid(test_results: List[List[float]]) str[source]

Given a grid of statistical test results, display them in a printable table.

Parameters:

test_results – Grid of p-values from the statistical test.

Returns:

Stat tests as a tabulated, ready to print table with p-values.

Module contents

Submodule with various utilities.