Koide numpy

He añadido ultimamente un par de recetas de Python3 al hilo https://www.physicsforums.com/threads/what-is-new-with-koide-sum-rules.551549/post-6502716 pero tambien he hecho un par de reponderaciones y por no sobrecargar el foro mejor las añado aqui en el blog de notas

import numpy as np
def rmass(mass,errors):
    scale = - errors[1]/errors[0]
    base  = np.random.normal(mass, errors[0], 1000)
    if scale==1:
        calc = base 
    else:
        calc = np.where(base < mass, base*scale, base)
    return  np.where(calc < 0, 0, calc)
        
def rkoide(triplet,signs):
    if signs[0]=="0":
        a=0
        mb,mc = map(m.get,triplet)
        eb,ec = map(e.get,triplet)
        b,c = rmass(mb,eb), rmass(mc,ec)
        sign = 0
    else:
        ma,mb,mc = map(m.get,triplet)
        ea,eb,ec = map(e.get,triplet)
        a,b,c = rmass(ma,ea), rmass(mb,eb), rmass(mc,ec)
        sign = +1 if signs[0]=="+" else -1
    koide=(a+b+c)/np.square(sign*np.sqrt(a)+np.sqrt(b)+np.sqrt(c))
    return np.mean(koide), np.std(koide ) #, np.std(koide, ddof=1)
e=dict()
for line in p.split("\n")[1:-1]:
    d=line[32:].split()
    e[d[-2]+d[-1]]=[float(d[1]),float(d[2])]
%%time
for x in result:
    k,std=rkoide(x[1],x[3])
    x[0]=max(abs(k+std-2/3),abs(max(k-std,0)-2/3))
#print(f'{"|".join(x[1]):<40}',"\t{:.8f} +- {:.8f}".format(abs(k-2/3),std))

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.