aixcalibuha.utils package

Package containing utility functions used in different packages. Contains a statistics analyzer and a visualizer.

exception aixcalibuha.utils.MaxIterationsReached[source]

Bases: Exception

Exception raised for when the calibration ends because the maximum number of allowed iterations is reached.

exception aixcalibuha.utils.MaxTimeReached[source]

Bases: Exception

Exception raised for when the calibration ends because the maximum calibration time is reached.

aixcalibuha.utils.convert_mat_to_suffix(mat_result_file, variable_names, suffix_files, parquet_engine='pyarrow', compression='snappy')[source]

Postprocess the mat result files.

Parameters:
  • mat_result_file (str) – The path to the MATLAB result file.

  • variable_names (List[str]) – The names of the variables to extract.

  • suffix_files (str) – The suffix for the output files.

  • parquet_engine (str) – The engine to use for saving parquet files.

aixcalibuha.utils.empty_postprocessing(mat_result, **_kwargs)[source]
aixcalibuha.utils.validate_cal_class_input(calibration_classes: CalibrationClass | List[CalibrationClass]) List[CalibrationClass][source]

Check if given list contains only CalibrationClass objects or is one and return a list in both cases. Else raise an error

Submodules

aixcalibuha.utils.configuration module

aixcalibuha.utils.visualizer module

Module with classes and function to help visualize different processes inside the framework. Both plots and print-function/log-function will be implemented here. The Visualizer Class inherits the Logger class, as logging will always be used as a default.

class aixcalibuha.utils.visualizer.CalibrationLogger(working_directory, name, calibration_class, logger=None)[source]

Bases: object

Base class for showing the process of functions in this Framework with print-statements and saving everything relevant as a log-file.

Parameters:
  • working_directory (str,Path) – Directory where to store the output of the Logger and possible child-classes. If the given directory can not be created, an error will be raised.

  • name (str) – Name of the reason of logging, e.g. classification, processing etc.

  • calibration_class (aixcalibuha.CalibrationClass) – Calibration class used in the calibration-process.

  • logger (logging.Logger) – If given, this logger is used to print and or save the messsages. Else, a new one is set up.

calibrate_new_class(calibration_class, working_directory=None, for_validation=False)[source]

Function to setup the figures for a new class of calibration. This function is called when instantiating this Class. If you uses continuuos calibration classes, call this function before starting the next calibration-class.

Parameters:
  • calibration_class (aixcalibuha.CalibrationClass) – Class holding information on names, tuner_paras, goals and time-intervals of calibration.

  • working_directory (str,Path) – Optional change in working directory to store files

  • for_validation (bool) – If it’s only for validation, only plot the goals

calibration_callback_func(xk, obj, verbose_information, penalty=None)[source]

Logs the current values of the objective function.

Parameters:
  • xk (np.array) – Array with the current values of the calibration

  • obj (float) – Current objective value.

  • verbose_information (dict) – A dict with difference-values of for all goals and the corresponding weightings

  • penalty (float) – Penaltyfactor from current evaluation

property calibration_class: CalibrationClass

Get current calibration class object

decimal_prec = 6
error(msg)[source]

Wrapper function to directly log an error

property goals: Goals

Get current goals instance

integer_prec = 4
log(msg, level=20)[source]

Wrapper function to directly log in the internal logger

log_initial_names()[source]

Function to log the initial names and the statistical measure before calibration.

log_intersection_of_tuners(intersected_tuner_parameters, **kwargs)[source]

If an intersection for multiple classes occurs, an information about the statistics of the dataset has to be provided.

Parameters:

intersected_tuner_parameters (dict) – Dict with cols being the name of the tuner parameter and the value being the list with all the different “best” values for the tuner parameter.

save_calibration_result(best_iterate, model_name, **kwargs)[source]

Process the result, re-run the simulation and generate a logFile for the minimal quality measurement

Parameters:
  • best_iterate (dict) – Result object of the minimization

  • model_name (str) – Name of the model being calibrated

property tuner_paras: TunerParas
validation_callback_func(obj)[source]

Log the validation result information

Parameters:

obj (float) – Objective value of validation.

property working_directory: str

Get the current working directory for storing plots.

class aixcalibuha.utils.visualizer.CalibrationVisualizer(working_directory, name, calibration_class, logger=None, **kwargs)[source]

Bases: CalibrationLogger

More advanced class to not only log ongoing function evaluations but also show the process of the functions by plotting interesting causalities and saving these plots.

Parameters:
  • show_plot (boolean) – If False, all created plots are not shown during calibration but only stored at the end of the process.

  • create_tsd_plot (boolean) – If False, the plot of the time series data (goals) is not created and thus shown in during calibration. It therefore is also not stored, even if you set the save_tsd_plot keyword-argument to true.

  • save_tsd_plot (boolean) – If True, at each iteration the created plot of the time-series is saved. This may make the process much slower

  • show_plot_pause_time (float) – Set the time (in seconds) the plt.draw() pauses. May be altered if show_plot yields plot which disappear to fast. Default is 1-e3 s.

calibrate_new_class(calibration_class, working_directory=None, for_validation=False)[source]

Function to setup the figures for a new class of calibration. This function is called when instantiating this Class. If you uses continuuos calibration classes, call this function before starting the next calibration-class.

Parameters:
  • calibration_class (aixcalibuha.CalibrationClass) – Class holding information on names, tuner_paras, goals and time-intervals of calibration.

  • working_directory (str,Path) – Optional change in working directory to store files

  • for_validation (bool) – If it’s only for validation, only plot the goals

calibration_callback_func(xk, obj, verbose_information, penalty=None)[source]

Logs the current values of the objective function.

Parameters:
  • xk (np.array) – Array with the current values of the calibration

  • obj (float) – Current objective value.

  • verbose_information (dict) – A dict with difference-values of for all goals and the corresponding weightings

log_intersection_of_tuners(intersected_tuner_parameters, **kwargs)[source]

If an intersection for multiple classes occurs, an information about the statistics of the dataset has to be provided.

Parameters:

intersected_tuner_parameters (dict) – Dict with cols being the name of the tuner parameter and the value being the list with all the different “best” values for the tuner parameter.

save_calibration_result(best_iterate, model_name, **kwargs)[source]

Process the result, re-run the simulation and generate a logFile for the minimal quality measurement

Parameters:
  • best_iterate (scipy.optimize.minimize.result) – Result object of the minimization

  • model_name (str) – Name of the model being calibrated

validation_callback_func(obj)[source]

Log the validation result information. Also plot if selected.

Parameters:

obj (float) – Objective value of validation.

aixcalibuha.utils.visualizer.short_name(ini_name: str, max_len: int)[source]

Shortens long strings to a max length from the front. long_string_name => …ing_name with len(new_name) = max_len

Parameters:
  • ini_name (str) – Long string to shorten.

  • max_len (int) – Max len of the new string.

Returns:

str The shorten string.