optframework.kernel_opt.opt_base module
- class optframework.kernel_opt.opt_base.OptBase(config_path=None, data_path=None, multi_flag=None)[source]
Bases:
object
A class to manage the optimization process for finding the kernel of PBE.
This class is responsible for instantiating either the opt_algo or opt_algo_multi classes based on the provided configuration. It facilitates passing parameters, executing optimization, generating synthetic data, and visualizing results.
Note
This class uses the bind_methods_from_module function to dynamically bind methods from external modules. Some methods in this class are not explicitly defined here, but instead are imported from other files. To fully understand or modify those methods, please refer to the corresponding external files, such as optframework.kernel_opt.opt_base_ray, from which methods are bound to this class.
Methods
- __init__(config_path=None, data_path=None)
Initializes the class with configuration and data paths.
- check_config_path(config_path)[source]
Checks if the configuration file exists and loads it.
Parameters
- config_pathstr
Path to the configuration file. If None, a default path is used.
Returns
- configdict
The loaded configuration dictionary.
Raises
- Exception
If the configuration file is not found at the specified path.
- init_opt_core()[source]
Initializes the optimization core based on whether 1D data is used as auxiliary for 2D-PBE kernels.
The multi_flag indicates whether to use 1D data as auxiliary input to help calculate 2D kernels. If multi_flag is True, the optimization process uses both 1D and 2D data. If False, only 2D data is used for the kernel calculation.
- find_opt_kernels(method='kernels', data_names=None, known_params=None)[source]
Finds optimal kernels for the PBE model by minimizing the difference between simulation results and experimental data.
This method optimizes kernel parameters for the PBE (Population Balance Equation) model. It supports two optimization methods: ‘kernels’ and ‘delta’. The ‘kernels’ method optimizes the kernel for each dataset and computes an average kernel, while ‘delta’ uses averaged delta values before optimization.
Parameters
- methodstr, optional
- The optimization method to use. Options are:
‘kernels’: Optimizes kernel parameters for each data set and averages the results.
‘delta’: Averages the delta values before optimization, leading to a single kernel.
- data_namesstr or list of str, optional
The name(s) of the experimental data file(s). If multiple datasets are provided, the optimization will be performed for each dataset.
- known_paramslist, optional
Known parameters to be used during optimization. This should match the length of data_names.
Returns
- dict or list of dict
A dictionary (or a list of dictionaries for multiple datasets) containing optimized kernels and their respective optimization results.
- calc_PSD_delta(params, exp_data_path)[source]
Directly calculates the delta value using the input parameters. Culated delta by comparing the PSD from the input parameters with the experimental data. It can also be used to compute the theoretical minimum delta. This method is used to validate the accuracy of the calcvalue for synthetically. generated data.
Parameters
- paramsdict
The parameters used to calculate the particle size distribution (PSD) and delta value.
- exp_data_pathstr or list of str
The path(s) to the experimental or synthetic PSD data file(s). For multi-dimensional data, this is a list containing paths for both 1D and 2D data.
Returns
- tuple
- A tuple containing:
- deltafloat
The calculated difference between the input parameters and the experimental PSD.
- exp_data_path_oristr
The original experimental data path.