delo.LogReader¶
- class delo.LogReader(file)¶
Read log created with Logger.
Example
>>> import delo >>> import numpy as np >>> >>> def square(x): ... return np.sum(x ** 2, axis=1) >>> >>> file_name = 'square_opt.log' >>> logger = Logger(file=file_name) >>> described_function = delo.DescribedFunction(square, dimension=2, domain_lower_limit=-10, domain_upper_limit=10) >>> algorithm = delo.DElo(10, logger=logger) >>> >>> algorithm.optimize(described_function, rng_seed=2022) >>> >>> logreader = LogReader(file_name) >>> best_fs = logreader.read_variable('current_best_f') Looking for current_best_f in log file Found 100 occurences of `current_best_f`. >>> print(best_fs[:5]) [27.935020304146946, 13.606498015936902, 4.37874090480261, 2.9852266609374456, 0.29795569609533]
- __init__(file)¶
Constructor
- Parameters
file (str) – path to *.log file created with
LogReader.
Methods
__init__(file)Constructor
Get a list of names of variables recorded in logs.
Print on console initial parameters and hyperparameters.
read_variable(variable_name[, type_name, ...])Get a list of a single variable recorded in logs.
read_variables(variable_name_list[, ...])Get a list of multiple variables recorded in log.
- get_variable_names()¶
Get a list of names of variables recorded in logs.
- Returns
names of variables stored in logs.
- Return type
list of str
- read_solver_configuration()¶
Print on console initial parameters and hyperparameters.
- read_variable(variable_name, type_name=None, silence=False)¶
Get a list of a single variable recorded in logs.
- Parameters
variable_name (str) – name of variable to be read from log. Run
get_variable_namesmethod for acceptable values.type_name (str, optional) – type of variable to be read. If not provided, default variable type will be used. Acceptable types: “str”, “int”, “float”, “bool”, “list”, “np.array”.
silence (bool) – Whether to print messages about progress (False) ot not (True).
- Returns
variable values in consecutive iterations.
- Return type
list
- read_variables(variable_name_list, type_name_list=None, silence=False)¶
Get a list of multiple variables recorded in log.
- Parameters
variable_name_list (list of str) – names of variables to be read from log.
type_name_list (list of str, optional) – types of variables to be read. If not provided, default variable types will be used. Acceptable types: “str”, “int”, “float”, “bool”, “list”, “np.array”.
silence (bool) – Whether to print messages about progress (False) ot not (True).
- Returns
keys: variable names, values: lists of variable values in consecutive iterations.
- Return type
dict