ijazz.RegionalFitter ==================== .. py:module:: ijazz.RegionalFitter Classes ------- .. autoapisummary:: ijazz.RegionalFitter.RegionalFitter Module Contents --------------- .. py:class:: RegionalFitter(dt: pandas.DataFrame, mc: pandas.DataFrame, n_par: int = -1, name_cat='cat', name_mll='mee', name_weights: str = None, min_nevt_region_dt=10, min_nevt_region_mc=100, win_z_dt=(70, 110), win_z_mc=(50, 130), bin_width_dt='Q', bin_width_mc=0.1, double_gaussian=False, single_parameters=[], error_parameters=['resp', 'reso'], fast_hist=False) .. py:attribute:: bin_width_dt :value: 'Q' .. py:attribute:: name_cat :value: 'cat' .. py:attribute:: name_mll :value: 'mee' .. py:attribute:: win_z_dt :value: (70, 110) .. py:attribute:: idx_pars :value: None .. py:attribute:: eresp :value: None .. py:attribute:: ereso :value: None .. py:attribute:: corr :value: None .. py:attribute:: err :value: None .. py:attribute:: cov :value: None .. py:attribute:: hess :value: None .. py:attribute:: double_gaussian :value: False .. py:attribute:: single_parameters :value: [] .. py:attribute:: error_parameters :value: ['resp', 'reso'] .. py:attribute:: n_par :value: -1 .. py:attribute:: resp .. py:attribute:: reso .. py:attribute:: error_variables .. py:attribute:: eresp_mc .. py:attribute:: ereso_mc .. py:attribute:: regions .. py:attribute:: idt :value: 0 .. py:attribute:: imc :value: 1 .. py:attribute:: regional_electron_indices .. py:attribute:: n_reg .. py:attribute:: bins_mc .. py:attribute:: bins_mean_mc :value: [] .. py:attribute:: bins_mid_mc .. py:attribute:: bins_dt :value: [] .. py:attribute:: bins_width :value: [] .. py:attribute:: pi_mask .. py:attribute:: n_ic .. py:attribute:: m_jc .. py:attribute:: m_ic .. py:attribute:: b_ic .. py:attribute:: b_jc .. py:attribute:: s2_m_jc .. py:method:: rll_sll(cats=slice(None)) Compute the dilepton rll and sll for each gaussian. In the case of double gaussian, we end up with 4 gaussians. :param cats: categories where to compute the rll and sll. Defaults to slice(None). :type cats: slice, optional :returns: tuple of rll and sll for each gaussian :rtype: tuple .. py:method:: pi(cats: slice = slice(None), rll_sll: tuple = None) Compute the probabilities of being in the bin i (after smearing) in each categories :param cats: categories where to compute the pis. Defaults to slice(None). :type cats: slice, optional :param rll_sll: tuple with the rll and sll for each gaussian. Defaults to None. :type rll_sll: tuple, optional :returns: 2D array of probabilities per category :rtype: np.array .. py:method:: nll_cat(cats: slice = slice(None)) Compute the negative log likelihood (multinomial law) :param cats: categories where to compute the nll. Defaults to slice(None). :type cats: slice, optional :returns: nll :rtype: tf.float64 .. py:method:: dnll_dmjc(cats) Compute the gradient of the negative log likelihood with respect to the MC histogram. :param cats: categories where to compute the gradient. :type cats: slice :returns: gradient of the nll with respect to the MC histogram. :rtype: tf.float64 .. py:method:: nll_batch(**kwargs) .. py:method:: batcher(afunc, batch_size=-1, shuffle=False, cats=slice(None)) Compute the likelihood in batch and then sum-up the result. :param batch_size: size of the batch. :type batch_size: int :param shuffle: shuffle the events before (this is useless in this case but kept for timing tests). :type shuffle: bool :returns: the summed likelihood. :rtype: tf.float64 .. py:method:: train_epoch(optimizer, batch_size=-1, batch_training=True, cats=slice(None)) Train a single epoch for the model. :param optimizer: The Keras optimizer used to apply gradients. :type optimizer: tf.keras.optimizers.Optimizer :param batch_size: The size of the batch for negative log-likelihood (NLL) computation. Defaults to -1, which means no batching. :type batch_size: int, optional :param batch_training: If True, updates parameters at each batch for faster training. Defaults to True. :type batch_training: bool, optional :param cats: A slice object to select specific categories of data. Defaults to slice(None). :type cats: slice, optional :returns: The total negative log-likelihood (NLL) for the epoch. :rtype: tf.Tensor .. py:method:: minimize(optimizer, dnll_tol=0.1, max_epochs=1000, minimizer='Adam', init_rand=False, nepoch_print=10, init_resp=None, init_reso=None, device='CPU', batch_size=-1, batch_training=True, cats=slice(None)) Minimizes the negative log-likelihood using a TensorFlow optimizer. :param optimizer: TensorFlow optimizer to apply gradients. :type optimizer: tf.keras.optimizers.Optimizer :param dnll_tol: Tolerance for the change in -2logL to determine convergence. :type dnll_tol: float :param max_epochs: Maximum number of epochs for optimization. :type max_epochs: int :param minimizer: Optimization method, either 'Adam' or a SciPy minimizer (e.g., 'TNC'). :type minimizer: str :param init_rand: If True, initializes variables randomly. :type init_rand: bool :param nepoch_print: Frequency of printing progress (every `nepoch_print` epochs). :type nepoch_print: int :param device: Device to use for computation ('CPU' or 'GPU'). :type device: str :param batch_size: Size of the batch for likelihood computation. :type batch_size: int :param batch_training: If True, updates parameters at each batch for faster training. :type batch_training: bool :returns: List of negative log-likelihood values for each epoch. :rtype: List[float] .. py:method:: minimize_tf(optimizer, dnll_tol=0.1, max_epochs=1000, init_rand=False, nepoch_print=10, init_resp=None, init_reso=None, device='CPU', batch_size=-1, batch_training=True, cats=slice(None)) Minimizes the negative log-likelihood using a TensorFlow optimizer. :param optimizer: TensorFlow optimizer to apply gradients. :type optimizer: tf.keras.optimizers.Optimizer :param dnll_tol: Tolerance for the change in -2logL to determine convergence. :type dnll_tol: float :param max_epochs: Maximum number of epochs for optimization. :type max_epochs: int :param init_rand: If True, initializes variables randomly. :type init_rand: bool :param nepoch_print: Frequency of printing progress (every `nepoch_print` epochs). :type nepoch_print: int :param device: Device to use for computation ('CPU' or 'GPU'). :type device: str :param batch_size: Size of the batch for likelihood computation. :type batch_size: int :param batch_training: If True, updates parameters at each batch for faster training. :type batch_training: bool :param cats: A slice object to select specific categories of data. :type cats: slice :returns: Array of negative log-likelihood values for each epoch. :rtype: np.ndarray .. py:method:: minimize_sp(dnll_tol=0.1, minimizer='TNC', init_rand=False, init_resp=None, init_reso=None, device='CPU', batch_size=-1, cats=slice(None)) Minimizes the negative log-likelihood using a SciPy optimizer. :param dnll_tol: Tolerance for the change in -2logL to determine convergence. :type dnll_tol: float :param minimizer: SciPy minimizer method (e.g., 'TNC', 'L-BFGS-B'). :type minimizer: str :param init_rand: If True, initializes variables randomly. :type init_rand: bool :param init_resp: Initial values for the response parameters. Defaults to None. :type init_resp: np.ndarray, optional :param init_reso: Initial values for the resolution parameters. Defaults to None. :type init_reso: np.ndarray, optional :param device: Device to use for computation ('CPU' or 'GPU'). :type device: str :param batch_size: Size of the batch for likelihood computation. :type batch_size: int :param cats: A slice object to select specific categories of data. :type cats: slice :returns: Array containing the final negative log-likelihood value. :rtype: np.ndarray .. py:method:: get_index(e1=None, e2=None, c=None) Get indices based on electron or pair categories. :param e1: List of electron indices to match. :type e1: list, optional :param e2: List of electron indices to match. If both `e1` and `e2` :type e2: list, optional :param are provided: :param pairs of indices will be matched.: :param c: List of electron index pairs to match. :type c: list[tuple], optional :returns: Unique indices matching the categories. Returns all indices if no categories. :rtype: pd.Index .. rubric:: Notes - If both `e1` and `e2` are provided, all combinations of pairs, including reversed, are considered. - Assumes `self.regional_electron_indices` is a pandas DataFrame. .. py:method:: plot_region_fits(cols=5, show_mc=False, n_plots=None, e1=None, e2=None, cats=None, rll_sll=None) Plot the data and fit for each region. :param cols: Number of columns in the plot. :type cols: int :param show_mc: If True, show the Monte Carlo uncorrected. :type show_mc: bool :param n_plots: Number of plots to show. :type n_plots: int :param e1: List of electron indices to match. :type e1: list :param e2: List of electron indices to match. If both `e1` and `e2` :type e2: list :param are provided: :param pairs of indices will be matched.: :param cats: List of electron index pairs to match. :type cats: list[tuple] :param rll_sll: Tuple with the rll and sll for each gaussian. :type rll_sll: tuple :returns: Tuple containing the figure and axes objects. :rtype: tuple .. py:method:: get_hessian(afunc, numerical=True, **kwargs) Compute the hessain of a function numerically or analytically :param afunc: function to get hessian of :type afunc: function :param numerical: type of computation. Defaults to True. :type numerical: bool, optional :returns: hessian matrix :rtype: np.array .. py:method:: covariance(numerical=True, force=False, **kwargs) Computes and stores the Hessian, covariance, and correlation matrices. :param numerical: Whether to compute the Hessian numerically. Defaults to True. :type numerical: bool, optional :param force: If True, recompute all matrices even if they already exist. Defaults to False. :type force: bool, optional :param \*\*kwargs: Additional parameters for the `nll_batch` function (e.g., batch_size). :returns: None .. py:method:: calc_err_mc() -> None Compute the uncertainty due to MC limited statistic :returns: store the error in dedicated variables in the fitter :rtype: None