optframework.kernel_opt.opt_core module
Calculate the difference between the PSD of the simulation results and the experimental data.
- class optframework.kernel_opt.opt_core.OptCore[source]
Bases:
object
Class definition for calculations within the optimization process.
This class is responsible for handling experimental data processing, calculating the error (delta) between the experimental particle size distribution (PSD) and the PSD generated by the population balance equation (PBE). It accepts trial parameters from the optimizer, processes and computes the results, and passes the calculated delta back to the optimizer to be used as the optimization objective.
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.
- init_attr(core_params)[source]
Initialize the attributes of the class based on the provided core parameters.
This method sets up the time vectors (t_init and t_vec), initializes the number of time steps, and validates the delta_t_start_step. It combines the initial and main time vectors into a single array and calculates the corresponding indices for initialization.
Parameters
- core_paramsdict
Dictionary containing the core parameters for initializing the optimization process.
Raises
- Exception
If delta_t_start_step is out of bounds of the time vector (t_vec).
- init_pbe(pop_params, data_path)[source]
Initialize the PBE solver.
This method creates and initializes a DPBESolver for solving the population balance equations. If the dimension (dim) is 2, it also creates a 1D PBE solver to assist with the initialization of the 2D system.
Parameters
- pop_paramsdict
The parameters used for initializing the PBE solver.
- data_pathstr
The path to the data directory for loading component parameters.
- calc_delta(params_in, x_uni_exp, data_exp)[source]
This method calculates the PSD difference (delta). It first converts the input corr_agg (agglomeration rate) into the equivalent CORR_BETA and alpha_prim.Then the method runs the population balance equation (PBE) with the computed parameters and compares the generated PSD with the experimental PSD to calculate the delta value.
Parameters
- params_indict
The population parameters.
- x_uni_exparray-like
The unique particle diameters in experimental data.
- data_exparray-like
The experimental PSD data that will be compared with the PBE-generated PSD.
Returns
- float
The calculated delta value representing the difference between the experimental PSD and the PBE-generated PSD. If the PBE calculation fails, it returns a large positive value (e.g., 10) to indicate failure.
- check_corr_agg(params_in)[source]
Process the corr_agg parameter by converting it to equivalent CORR_BETA and alpha_prim. Since corr_agg is not a parameter in the PBE calculations, it is an artificially defined parameter that accounts for the characteristics of Frank’s collision model.
Parameters
- params_indict
A dictionary of input parameters that may include corr_agg.
Returns
- dict
The updated parameters dictionary with CORR_BETA and alpha_prim, and without corr_agg.
- return_syth_beta(corr_agg)[source]
Calculate and return a synthetic beta value based on corr_agg.
Parameters
- corr_aggarray-like
The correction factors for agglomeration rate.
Returns
- float
The synthetic beta value, which is a scaling factor derived from corr_agg.
- array_dict_transform(array_dict_in)[source]
Transform the dictionary to handle corr_agg arrays based on the dimensionality.
This method processes a dictionary containing corr_agg values and adjusts them based on the dimensionality of the PBE problem. For 1D problems, it keeps a single value, and for 2D problems, it creates an array with three elements. After transforming the dictionary, it deletes the original keys.
Parameters
- array_dictdict
A dictionary containing the corr_agg values that need to be transformed.
Returns
- dict
The transformed dictionary with corr_agg as an array.
- cost_fun(data_exp, data_mod, cost_func_type, flag)[source]
Calculate the cost (error) between experimental and PBE-generated data using various cost functions such as MSE, RMSE, MAE, and Kullback-Leibler (KL) divergence.
Parameters
- data_exparray-like
The experimental data.
- data_modarray-like
The model-generated data from the PBE simulation.
- cost_func_typestr
- The type of cost function to use. Options include:
‘MSE’: Mean Squared Error
‘RMSE’: Root Mean Squared Error
‘MAE’: Mean Absolute Error
‘KL’: Kullback-Leibler divergence (only for ‘qx’ or ‘Qx’).
- flagstr
A flag indicating whether to use ‘qx’ or ‘Qx’ for KL divergence.
Returns
- float
The calculated cost between the experimental and simulated data.
Raises
- Exception
If an unsupported cost function type is provided.
- print_notice(message)[source]
Print a formatted notice message with a border and padding.
Parameters
- messagestr
The message to be displayed in the notice.
- optimierer_bo(opt_params, hyperparameter=None, exp_data_paths=None, known_params=None)