flav-io / flavio

A Python package for flavour physics phenomenology in the Standard model and beyond
http://flav-io.github.io/
MIT License
71 stars 62 forks source link

Fastlikelihood fitting and inconsistent Chi square value #233

Open Md-Isha-Ali opened 1 year ago

Md-Isha-Ali commented 1 year ago

Dear Experts,

Theoretically chi square cannot have negative value . But When I tried to minimize the chi square function defined as -2*log_likelihood_function , I got negative value. I have used the available code in the website which I am writing below for better understanding . I am confused why chi square is negative ? ------------------------------------------------------------------------code--------------------------------------------------- FL = FastLikelihood(name='My fast likelihood', observables=['BR(B->Xsgamma)', 'BR(Bs->mumu)', 'BR(B0->mumu)'], include_measurements=['AS combination Bs->mumu 2021', 'B->Xgamma WA 2017'])

FL.make_measurement(N=1000, threads=8, force=True)

from wilson import Wilson

par = flavio.parameters.default_parameters.get_central_all()

def FLL(x): Re_C7, Re_C10 = x w = Wilson({'C10_bsmumu': Re_C10, 'C7_bs': Re_C7}, scale=4.8, eft='WET', basis='flavio') return FL.log_likelihood(par, w)

print(FLL([0.0023,0.48]))

from flavio.math.optimize import minimize

def chi2(x): return -2*FLL(x)

chi2_min = minimize(chi2,[0,0]) chi2_min

Results: message: Optimization terminated successfully. success: True status: 0 fun: -105.37189937874699 x: [ 2.361e-03 4.813e-01] nit: 7 jac: [-9.537e-07 -2.861e-06] hess_inv: [[ 1.544e-04 -3.627e-05] [-3.627e-05 2.791e-02]] nfev: 33 njev: 11


Also likelihood is a multiplication of probability density function where each density function integral value can be maximum 1 . So any likelihood function would have value in range [0,1] and hence log_likelihood have values [-infinity,0] . I have no clue what is happening . The 'fun' value is chi2_min value and to mention at minimum FLL value is 52 which is inconsistent with my theoretical understanding

Please guide me regarding this .

regards, Md Ali

DavidMStraub commented 1 year ago

Well,

def chi2(x):
    return -2*FLL(x)

is just wrong.

Try what -2 * log(scipy.stats.norm.pdf(0)) yields – not zero.

Twice the negative log likelihood and the chi-square are only equal up to a constant.