def compute_auc(true_model,
                W_xcorr=None,
                bfgs_model=None,
                sgd_model=None,
                gibbs_samples=None,
                gibbs_ss_samples=None,
                vb_models=None,
                svi_models=None):
    aucs = {}

    # Get the true adjacency matrix
    A_true = true_model.weight_model.A.ravel()

    if W_xcorr is not None:
        aucs['xcorr'] = roc_auc_score(A_true,
                                     W_xcorr.ravel())

    if bfgs_model is not None:
        assert isinstance(bfgs_model, DiscreteTimeStandardHawkesModel)
        aucs['bfgs'] = roc_auc_score(A_true,
                                     bfgs_model.W.ravel())

    if sgd_model is not None:
        assert isinstance(sgd_model, DiscreteTimeStandardHawkesModel)
        aucs['sgd'] = roc_auc_score(A_true,
                                     sgd_model.W.ravel())

    if gibbs_samples is not None:
        # Compute ROC based on mean value of W_effective in second half of samples
        Weff_samples = np.array([s.weight_model.W_effective for s in gibbs_samples])
        N_samples    = Weff_samples.shape[0]
        offset       = N_samples // 2
        Weff_mean    = Weff_samples[offset:,:,:].mean(axis=0)

        aucs['gibbs'] = roc_auc_score(A_true, Weff_mean.ravel())

    if gibbs_ss_samples is not None:
        # Compute ROC based on mean value of W_effective in second half of samples
        Weff_samples = np.array([s.weight_model.W_effective for s in gibbs_ss_samples])
        N_samples    = Weff_samples.shape[0]
        offset       = N_samples // 2
        Weff_mean    = Weff_samples[offset:,:,:].mean(axis=0)

        aucs['gibbs_ss'] = roc_auc_score(A_true, Weff_mean.ravel())

    if vb_models is not None:
        # Compute ROC based on E[A] under variational posterior
        aucs['vb'] = roc_auc_score(A_true,
                                   vb_models[-1].weight_model.expected_A().ravel())

    if svi_models is not None:
        # Compute ROC based on E[A] under variational posterior
        aucs['svi'] = roc_auc_score(A_true,
                                    svi_models[-1].weight_model.expected_A().ravel())

    return aucs
Compute the AUC score for each of competing models
dataset/ETHPy150Open slinderman/pyhawkes/experiments/synthetic_comparison.py/compute_auc