Util

Handle low level functionalities of the doce module.

doce.util.compress_description(description, desc_type='long', atom_length=2)[source]

reduces the number of letters for each word in a given description structured with underscores (python_case) or capital letters (camel_case).

Parameters:
descriptionstr

the structured description.

desc_typestr, optional

can be ‘long’ (default), do not lead to any reduction, ‘short_underscore’ assumes python_case delimitation, ‘short_capital’ assumes camel_case delimitation, and ‘short’ attempts to perform reduction by guessing the type of delimitation.

Returns:
compressed_descriptionstr

The compressed description.

Examples

>>> import doce
>>> doce.util.compress_description(
... 'myVeryLongParameter',
... desc_type='short'
... )
'myvelopa'
>>> doce.util.compress_description(
...  'that_very_long_parameter',
...  desc_type='short',
...  atom_length=3
...  )
'thaverlonpar'
doce.util.constant_column(table=None)[source]

detect which column(s) have the same value for all lines.

Parameters:
tablelist of equal size lists or None

table of literals.

Returns:
valueslist of literals

values of the constant valued columns, None if the column is not constant.

Examples

>>> import doce
>>> table = [['a', 'b', 1, 2], ['a', 'c', 2, 2], ['a', 'b', 2, 2]]
>>> doce.util.constant_column(table)
['a', None, None, 2]
doce.util.in_notebook()[source]

detect if the experiment is running from Ipython notebook.

doce.util.prune_setting_description(setting_description, column_header=None, nb_column_factor=0, factor_display='long', show_unique_setting=False)[source]

remove the columns corresponding to factors with only one modality from the setting_description and the column_header.

Remove the columns corresponding to factors with only one modality from the setting_description and the column_header and describes the factors with only one modality in a separate string.

Parameters:
setting_description: list of list of literals

the body of the table.

column_header: list of string (optional)

the column header of the table.

nb_column_factor: int (optional)

the number of columns corresponding to factors (default 0).

factor_display:

type of description of the factors (default ‘long’), see doce.util.compress_description() for reference.

show_unique_setting: bool

If True, show the description of the unique setting in cst_setting_desc.

Returns:
setting_description: list of list of literals

setting_description where the columns corresponding to factors with only one modality are removed.

column_header: list of str

column_header where the columns corresponding to factors with only one modality are removed.

cst_setting_desc: str

description of the settings with constant modality.

nb_column_factor: int

number of factors in the new setting_description.

Examples

>>> import doce
>>> header = ['factor_1', 'factor_2', 'metric_1', 'metric_2']
>>> table = [['a', 'b', 1, 2], ['a', 'c', 2, 2], ['a', 'b', 2, 2]]
>>> (setting_description,
...  column_header,
...  cst_setting_desc,
...  nb_column_factor) = doce.util.prune_setting_description(table, header, 2)
>>> print(nb_column_factor)
1
>>> print(cst_setting_desc)
factor_1: a
>>> print(column_header)
['factor_2', 'metric_1', 'metric_2']
>>> print(setting_description)
[['b', 1, 2], ['c', 2, 2], ['b', 2, 2]]
doce.util.query_yes_no(question, default='yes')[source]

ask a yes/no question via input() and return their answer.

The ‘answer’ return value is True for ‘yes’ or False for ‘no’.

Parameters:
questionstr

phrase presented to the user.

defaultstr or None (optional)

presumed answer if the user just hits <Enter>. It must be ‘yes’ (default), ‘no’ or None. The latter meaning an answer is required of the user.

Returns:
answerbool

True if prompt is ‘yes’.

False if prompt is ‘no’.