minuit给出了模糊的valueError

时间:2019-03-05 11:26:16

标签: python curve-fitting valueerror

我正在使用minuit拟合一条简单的曲线,但是由于某种原因,我得到了

  

ValueError:具有多个元素的数组的真值是   

使用a.any()a.all()

我不知道这是从哪里来的。我以前尝试过做类似的事情,但一直有效,我所更改的只是函数,所以这是错误,很奇怪,我不理解。

import numpy as np
from iminuit import Minuit

#some constants
hc = 197.3269788
mssph = 685.78 
#some data and errors to fit
muds = np.array([ 
    81.96100485,  64.96427609,  38.15520137,  45.75992993,
    27.38344029,  23.41742996,  18.73586921,  18.07486749,
     9.20589292,   4.83878931,  72.17070899,  71.08083681,
    39.57647386,  31.63373626,  30.65363538,  26.50584842,
    19.33150992,  13.45482499,   3.86943831,  68.76598171,
    66.7933219 ,  38.86139831,  38.61246743,  38.6500419 ,
    16.62670414,  16.24156579,   9.16347451,  52.48804692,
    51.95712296,  23.86333781,  23.81815279,  12.44282442
    ]) #xdata
Fr = np.array([ 
    127.31527434,  122.72790265,  110.26449558,  112.75717699,
    104.81830088,  104.35746903,  101.32016814,  100.54513274,
     96.87942478,   92.98330088,  124.9736053 ,  122.52414305,
    112.47114172,  108.74591788,  107.34258013,  108.00597616,
    102.18850331,  100.04522384,   91.47210596,  128.18641113,
    122.15516847,  108.23229985,  109.85263369,  107.69218856,
     99.14042658,   98.0902102 ,   99.1104204 ,  112.47678261,
    110.39126087,   98.373     ,   98.97391304,   95.01495652
    ])#ydata
Zsrgi = np.array([1.47, 1.5, 1.54, 1.58])

dzs = np.array([ 3.60555128,  3.60555128,  4.24264069,  1.41421356])
Za = np.array([ 0.9468,  0.9632,  0.9707,  0.9756])

Zaey = np.array([56.0, 53.0, 35.0, 15.0])

dmfel = np.array([ 
     2743.82452989,  1388.6310737 ,   689.77566743,   652.7213305 ,
     348.31861265,   309.31427565,   134.12993165,   157.95193019,
      60.83965035,    19.80905202,  3482.5565895 ,  3378.1685061 ,
     949.07161448,   570.68604168,   492.42222648,   801.32561084,
     362.30696375,   152.61749342,    26.39235787,  2733.32712033,
    2329.20044751,   788.45797536,   754.06472854,  1098.9552043 ,
     279.63806125,   213.46692781,   169.87677303,  2181.08350448,
    2018.45039786,   696.73902333,   763.51325268,   416.74304481
    ])
af = np.array([ 
    0.0575465 ,  0.05547301,  0.04983955,  0.05096624,  0.04737787,
    0.04716958,  0.04579672,  0.0454464 ,  0.0437895 ,  0.04202845,
    0.04717754,  0.04625286,  0.04245786,  0.04105158,  0.04052182,
    0.04077226,  0.03857616,  0.03776707,  0.03453072,  0.0414683 ,
    0.0395172 ,  0.03501315,  0.03553733,  0.03483842,  0.03207193,
    0.03173218,  0.03206222,  0.03104359,  0.03046799,  0.02715095,
    0.0273168 ,  0.02622413
    ])
afe = np.array([ 
    0.00039571,  0.00046823,  0.00034898,  0.00071523,  0.00052648,
    0.00051809,  0.00072373,  0.00059257,  0.00054912,  0.00065308,
    0.000283  ,  0.00028516,  0.00031909,  0.0003537 ,  0.00035294,
    0.0002573 ,  0.00034244,  0.00034139,  0.00055726,  0.00038002,
    0.00044435,  0.00050214,  0.00052077,  0.00037143,  0.00036278,
    0.00045654,  0.00039068,  0.00025011,  0.00024068,  0.00031897,
    0.00037707,  0.0003581
    ])
amssr = np.array([ 
        0.35006,  0.34592,  0.33967,  0.3175 ,  0.31341,  0.34965,
        0.33393,  0.31033,  0.30807,  0.32813,  0.29895,  0.26546,
        0.29559,  0.29298,  0.26026,  0.29264,  0.29094,  0.29074,
        0.25928,  0.3888 ,  0.23213,  0.23284,  0.22768,  0.20825,
        0.22591,  0.20437,  0.22353,  0.2036 ,  0.18987,  0.20088,
        0.18743,  0.18801
        ])
amudr = np.array([
    0.01737619,  0.01377279,  0.00808912,  0.00970136,  0.00580544,
    0.00496463,  0.00397211,  0.00383197,  0.0019517 ,  0.00102585,
    0.01227267,  0.01208733,  0.00673   ,  0.00537933,  0.00521267,
    0.00450733,  0.00328733,  0.002288  ,  0.000658  ,  0.00950714,
    0.00923442,  0.00537273,  0.00533831,  0.00534351,  0.0022987 ,
    0.00224545,  0.00126688,  0.00588165,  0.00582215,  0.00267405,
    0.00266899,  0.0013943
    ])
amudre = np.array([
     8.75479519e-04,   7.34296720e-04,   4.51927448e-04,
     5.98343236e-04,   3.81187530e-04,   3.18993055e-04,
     4.05218892e-04,   3.28835732e-04,   2.14302222e-04,
     1.80198850e-04,   6.27776371e-04,   6.18193827e-04,
     3.56742512e-04,   3.04857443e-04,   3.08046099e-04,
     2.32852126e-04,   1.84120801e-04,   1.62566426e-04,
     7.02801597e-05,   5.87470469e-04,   5.70265978e-04,
     3.42904960e-04,   3.42757519e-04,   3.31231953e-04,
     1.52175013e-04,   1.61067797e-04,   8.21035930e-05,
     1.40038557e-04,   1.42199518e-04,   7.54950814e-05,
     7.13899224e-05,   3.64415759e-05
     ])


a = np.array([ 0.0904,  0.0755,  0.0647,  0.0552])

B = 2.61
Fc = 92.8
#functions to fit
def Fpapper(X,s,pp,k,l1,B=2.61,Fc=92.8,mu=770,Za=0.9468):
    temp1 = (2*B*X)/(4*pi*Fc)**2
    return Fc*pp*(1+k*s)*(1+l1*temp1)
def Bpapper(X,s,fa,pp,y1,y1s,l2,B=2.61,Fc=92.8,mu=770,Za=0.9468):
    temp1 = (2*B*X)/(4*pi*Fc)**2
    return pp*(1-fa**2*y1+y1s*s)*B*(1-l2)

#parameters initial values and errors
paramfelp=np.array([  1.01980390e-03,   1.14017543e-03,   1.14017543e-03,
     8.06225775e-04,   4.93659802e-04,   6.41248782e-04,
     4.57055795e-04,   9.40212742e-04,   9.00499861e-04,
     7.40270221e-04,   9.39840412e-04,   6.82641927e-04,
     8.63712915e-04,   8.39344983e-04,   4.66904701e-04,
     4.31740663e-04,   5.75673519e-04,   5.99082632e-04,
     6.49384324e-04,   5.02195181e-04,   8.20000000e-04,
     9.05207159e-04,   1.06901824e-03,   7.32461603e-04,
     7.50066664e-04,   9.83259884e-04,   1.19339851e-03,
     6.22896460e-04,   8.12157620e-04,   5.88727441e-04,
     5.20384473e-04,   5.53263048e-04,   5.31601354e-04,
     8.80511215e-04,   1.05233075e-03,   5.32353266e-04,
     1.30000000e-03,   1.30000000e-03,   1.80000000e-03,
     2.00000000e-04,   5.60000000e-03,   5.30000000e-03,
     3.50000000e-03,   1.50000000e-03,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
     1.00000000e+00,   1.00000000e-08,   1.00000000e-01,
     1.00000000e-03,   1.00000000e-05,   2.00000000e-03,
     4.00000000e-01,   5.00000000e-01]) #parameters error

parametersp=np.array([  9.04000000e-02,   7.55000000e-02,   6.47000000e-02,
     5.52000000e-02,   7.64118166e+02,   7.55081289e+02,
     7.41438660e+02,   6.93045528e+02,   6.84117792e+02,
     7.63223209e+02,   7.28909270e+02,   6.77394705e+02,
     6.72461531e+02,   7.16248911e+02,   7.81336428e+02,
     6.93806885e+02,   7.72554724e+02,   7.65733222e+02,
     6.80216152e+02,   7.64844597e+02,   7.60401473e+02,
     7.59878753e+02,   6.77654822e+02,   1.18579180e+03,
     7.07967722e+02,   7.10133134e+02,   6.94395773e+02,
     6.35136682e+02,   6.88997493e+02,   6.23303163e+02,
     6.81738788e+02,   7.27821973e+02,   6.78740461e+02,
     7.18098614e+02,   6.70018037e+02,   6.72091400e+02,
     6.80272109e-01,   6.66666667e-01,   6.49350649e-01,
     6.32911392e-01,   9.46800000e-01,   9.63200000e-01,
     9.70700000e-01,   9.75600000e-01,   8.19610049e+01,
     6.49642761e+01,   3.81552014e+01,   4.57599299e+01,
     2.73834403e+01,   2.34174300e+01,   1.87358692e+01,
     1.80748675e+01,   9.20589292e+00,   4.83878931e+00,
     7.21707090e+01,   7.10808368e+01,   3.95764739e+01,
     3.16337363e+01,   3.06536354e+01,   2.65058484e+01,
     1.93315099e+01,   1.34548250e+01,   3.86943831e+00,
     6.87659817e+01,   6.67933219e+01,   3.88613983e+01,
     3.86124674e+01,   3.86500419e+01,   1.66267041e+01,
     1.62415658e+01,   9.16347451e+00,   5.24880469e+01,
     5.19571230e+01,   2.38633378e+01,   2.38181528e+01,
     1.24428244e+01,   3.23442596e-07,   1.42713877e+01,
     9.00000000e-02,   1.12143829e-04,   9.00000000e-02,
     3.70000000e+00,   4.00000000e+00]) #parameters initial value

 #chisquare
def chiworkp(paras):
    B=2.61
    Fc=92.8
    hc=197.3269788
    mu=770
    betalat=[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3]
    #chia=sum(((paras[0:4]-a)/(ast*10**(-4)))**2)+sum(((paras[4:36]*(paras[0:4][betalat])/hc-amssr)/(mse))**2)
    chiz=sum(((paras[36:40]-1/Zsrgi)/(dzs*10**(-2)))**2)+sum(((paras[40:44]-Za)/(Zaey*10**(-4)))**2)
    chiamd=sum(((amudr-(1+paras[77:78]*paras[0:4][betalat]**2)*paras[0:4][betalat]*paras[44:76]*paras[36:40][betalat]/hc)/amudre)**2)
    chiaf=sum(((af-Fpapper(paras[44:76],paras[4:36]**2-mssph**2,paras[0:4][betalat]/paras[40:44][betalat],paras[76:77],paras[77:78])/hc)/afe)**2)
    chiaB=sum((((ampir**2/(2*amudr))-Bpapper(paras[44:76],paras[4:36]**2-mssph**2,paras[0:4][betalat],paras[0:4][betalat]/paras[36:40][betalat],paras[77:78],paras[80:81])/hc)/Bfel)**2)
    return chia+chiz+chiamd+chiaf+chiaB

#minuit part
mc=minuit.Minuit(chiworkp,parametersp[:],paramfelp[:],errordef=1)

fminc, paramc = mc.migrad()

print(mc.values)

0 个答案:

没有答案