本文整理汇总了Python中lmfit.Model.eval方法的典型用法代码示例。如果您正苦于以下问题:Python Model.eval方法的具体用法?Python Model.eval怎么用?Python Model.eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lmfit.Model
的用法示例。
在下文中一共展示了Model.eval方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lmDDOPhaseFit
# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import eval [as 别名]
def lmDDOPhaseFit(xdata, ydata, params, f0_range = 1.2, Q_range = 3):
f0= params[0]
Q=1/(2*params[2])
x = xdata
y = ydata
#Define a linear model and a Damped Oscillator Model
# ddophase_mod = ExpressionModel('off + m*x- arctan(1/Q * 1/(f0/x - x/f0))-')
ddophase_mod = Model(phase)
#Initial Pars for Linear Model
pars = ddophase_mod.make_params(off=0, m=0, f0=f0, Q=Q)
#Add fit parameters, Center, Amplitude, and Sigma
pars['f0'].set(min=f0/f0_range, max=f0*f0_range)
pars['Q'].set(min=Q/Q_range, max=Q*Q_range)
#Create full model. Add linear model and all peaks
#Initialize fit
init = ddophase_mod.eval(pars, x=x)
#Do the fit. The weight exponential can weight the points porportional to the
#amplitude of y point. In this way, points on peak can be given more weight.
out=ddophase_mod.fit(y, pars,x=x)
#Get the fit parameters
fittedf0= out.params['f0'].value
fittedQ = out.params['Q'].value
#Returns the output fit as well as an array of the fit parameters
"""Returns output fit as will as list of important fitting parameters"""
return out, [fittedf0, np.nan, np.nan, fittedQ]
示例2: prueba
# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import eval [as 别名]
def prueba():
y2 = [49.0, 49.0, 101.0, 67.0, 65.0, 52.0, 49.0, 49.0, 54.0, 49.0, 48.0, 49.0]
y = [i-50 for i in y2]
x = linspace(0.0, 11.0, num=12) #variable ind para evento
x2 = linspace(0.0, 11.0, num=400) #variable ind para fit
gmod = Model(gaussian) #Generar un Modelo Gaussiano
peak = max(y)
result = gmod.fit(y, x=x, amp=peak, cen=5, wid=1)
final = gmod.eval(x=x2, amp=result.best_values['amp'], cen=result.best_values['cen'], wid=result.best_values['wid'])
plt.plot(x, y, 'bo')
plt.plot(x, result.init_fit, 'k--')
#plt.plot(x, result.best_fit, 'r-')
plt.plot(x2, final, 'r-')
plt.show()
示例3: linspace
# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import eval [as 别名]
x2 = linspace(0.0, 11.0, num=300) #variable ind para fit, 300 asi el eje x esta en 1ns
gmod = Model(gaussian) #Generar un Modelo Gaussiano
#Iterar el Corpus de datos para realizar un archivo con los features en tuplas
#sampled_data = []
with open("C:\Users\Anai\Desktop\Miguel\LAGO\LAGO-AI\src\cosmicfilter\CosmicTrain.txt", "r") as f:
with open("OutputClusterReduced.txt", "w") as output:
for l in f:
data = l.split("-")
raw_data = data[0].strip().split(" ")
#print(raw_data)
y = [int(i)-47 for i in raw_data]
peak = max(y)
result = gmod.fit(y, x=x, amp=peak, cen=3, wid=1)
final = gmod.eval(x=x2, amp=result.best_values['amp'], cen=result.best_values['cen'], wid=result.best_values['wid'])
rtime = argmax(final)
dummy = str(rtime)+"-"+str(peak)
#if dummy not in sampled_data:
output.write("["+str(rtime)+","+str(float(peak))+"]\n")
#sampled_data.append(str(rtime)+"-"+str(peak))
print("Finished...")
#amp_result = result.best_values['amp']
#cen_result = result.best_values['cen']
#wid_result = result.best_values['wid']
#print(result.fit_report())
#print(final)
示例4: main
# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import eval [as 别名]
#.........这里部分代码省略.........
# Goal: take our x positions, step along the y positions, and get the
# values from the image.
# Plot everything
# Resample image to standard grid
alignedimg.append(get_image_values_2(img, markerPos, DeltaMarker, fname))
'''
# My sheep model data from images, video
model_days = np.array([30., 40., 50., 60., 70., 80., 90., 100., 110., 120., 130., 140., 150., 160., 170., 180., 190., 200., 210., 220., 230., 240., 250., 260., 270., 280., 290., 300.])
model_completion = np.array([2.3, 2.3, 2.76, 2.76, 4.6, 9.2, 11.96, 11.96, 13.8, 13.8, 15.64, 16.56, 16.56, 20.7, 20.7, 22.08, 23.46, 23.46, 23.46, 23.46, 23.46, 24.38, 24.84, 24.84, 27.6, 27.6, np.nan, 30.36])
model_initiation = np.array([14.72, 15.64, 16.56, 17.48, 18.4, 24.84, 26.68, 26.68, 28.52, 28.52, 29.44, 30.36, 30.36, 31.28, 31.28, 31.74, 33.12, 33.12, 33.12, 33.12, 33.12, 33.58, 34.04, 34.04, 34.96, 34.96, np.nan, 34.96])
model_min_length = model_initiation - model_completion
model_length_percent = model_min_length / 39.
model_increase_per_day = np.array([1.104, 0.552, 1.564, 1.932, 0.092, 0., 0.16866667, 0.16866667, 0.16866667, 0.16866667, 0.16866667, 0.16866667, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.10514286, 0.092, 0.15333333, 0.15333333, 0.15333333, 0.138, 0.138, 0.184, 0.276, 0.21466667, 0.21466667, 0.21466667, 0., 0.552, 0.70533333, 0.70533333, 0.70533333, 1.104, 0.598, 0.598, 0., 0.299, 0.299, 0.299, 0.299, 0.1472, 0.1472, 0.1472, 0.1472, 0.1472, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.0736, 0.0736, 0.0736, 0.0736, 0.0736, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0.05952941, 0., 0.092, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.05366667, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.04293333, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.03942857, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0.0368, 0., 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.03504762, 0.046, 0.046, 0.0345, 0.0345, 0.0345, 0.0345, 0.0345, 0.0345, 0.0345, 0.0345, 0., 0.046, 0.046, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.036, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.04025, 0.046, 0.046, 0.046, 0.046, 0.046, 0.046, 0.046, 0.046, 0.046, 0.046, 0.046, 0.046, 0.0644, 0.0644, 0.0644, 0.0644, 0.0644, 0.0644, 0.0644, 0.0644, 0.0644, 0.0644])
for i in xrange(np.size(model_increase_per_day)):
if model_increase_per_day[i] > 0.4:
model_increase_per_day[i] = 0.40
model_pct_increase_per_day = model_increase_per_day / np.max(model_increase_per_day)
# Kierdorf 2013 data
kday = np.array([7.5, 21.5, 49.5, 63.3, 73., 154., 168., 185.5, 199., 212.5, 230., 247.5])
kext = np.array([177.6, 168.4, 180., 131.7, 109.9, 40.4, 35.5, 35.0, 33.2, 27.1, 28.0, 29.3])
tooth_days = np.array([1., 9., 11., 19., 21., 30., 31., 31., 38., 42., 54., 56., 56., 58., 61., 66., 68., 73., 78., 84., 88., 92., 97., 100., 101., 101., 104., 105., 124., 127., 140., 140., 157., 167., 173., 174., 179., 202., 222., 235., 238., 251., 259., 274.])
tooth_extension = np.array([9.38, 8.05, 11.32, 9.43, 13.34, 16.19, 13.85, 15.96, 15.32, 14.21, 17.99, 19.32, 19.32, 18.31, 17.53, 18.68, 18.49, 22.08, 23.14, 19.92, 27.97, 24.38, 25.53, 29.07, 27.65, 26.27, 27.55, 24.33, 29.03, 29.07, 30.36, 31.79, 31.37, 31.28, 35.79, 29.81, 31.79, 34.04, 33.21, 34.50, 33.76, 33.40, 36.34, 33.63])
tooth_35p = np.array([2.07, 1.52, 2.39, 2.67, 4.60, 7.04, 4.55, 5.47, 5.47, 4.83, 8.19, 9.98, 9.75, 9.89, 9.29, 10.40, 8.88, 12.88, 14.49, 11.96, 19.04, 17.48, 16.74, 20.61, 18.86, 17.34, 19.92, 14.67, 22.03, 22.91, 24.47, 26.08, 26.13, 25.94, 34.45, 25.35, 26.91, 30.08, 30.68, 33.49, 28.29, 28.34, 35.83, 33.63])
tooth_70p = np.array([np.nan, np.nan, np.nan, np.nan, np.nan, 2.76, np.nan, np.nan, np.nan, np.nan, 3.68, 4.60, 4.69, 5.11, 4.88, 5.75, 4.74, 7.36, 8.97, 5.15, 13.62, 12.33, 11.13, 14.54, 13.25, 10.81, 13.25, 8.69, 15.78, 17.16, 19.27, 20.56, 19.87, 21.48, 30.27, 20.01, 22.17, 24.56, 26.27, 28.11, 23.55, 23.83, 36.34, 29.49])
tooth_mat_length = tooth_extension - tooth_70p / np.percentile(tooth_extension, 95)
tooth_70p_days = np.array([30., 54., 56., 56., 58., 61., 66., 68., 73., 78., 84., 88., 92., 97., 100., 101., 101., 104., 105., 124., 127., 140., 140., 157., 167., 173., 174., 179., 202., 222., 235., 238., 251., 259., 274.])
tooth_70p_b = np.array([2.76, 3.68, 4.60, 4.69, 5.11, 4.88, 5.75, 4.74, 7.36, 8.97, 5.15, 13.62, 12.33, 11.13, 14.54, 13.25, 10.81, 13.25, 8.69, 15.78, 17.16, 19.27, 20.56, 19.87, 21.48, 30.27, 20.01, 22.17, 24.56, 26.27, 28.11, 23.55, 23.83, 36.34, 29.49])
p0_var_ext = np.array([30.34, .006102, -10.54])
p0_var_p35 = np.array([23., .008, 13.])
p0_var_p70 = np.array([25., .006, 110.])
days = np.linspace(-50, 350, 401)
ext_variables, ext_pcov = curve_fit(est_tooth_extension, tooth_days, tooth_extension, p0_var_ext)
p35_variables, p35_pcov = curve_fit(est_tooth_extension, tooth_days, tooth_35p, p0_var_p35)
p70_variables, p70_pcov = curve_fit(est_tooth_extension, tooth_70p_days, tooth_70p_b, p0_var_p70)
p70_variables2, p70_pcov2 = leastsq(func=curve_residuals, x0=p70_variables, args=(p0_var_p70, tooth_70p_days, tooth_70p_b))
print ext_variables
print p35_variables
print p70_variables
print p70_variables2
extension_erf = est_tooth_extension(days, ext_variables[0], ext_variables[1], ext_variables[2])
p35_erf = est_tooth_extension(days, p35_variables[0], p35_variables[1], p35_variables[2])
p70_erf = est_tooth_extension(days, p70_variables2[0], p70_variables2[1], p70_variables2[2])
diff_extension_erf = np.diff(extension_erf) * 1000
diff_p35_erf = np.diff(p35_erf) * 1000
diff_p70_erf = np.diff(p70_erf) * 1000
ext_zero = ext_variables[1] - ext_variables[2]*spec.erfinv((36. - ext_variables[0])/ext_variables[0])
p35_zero = p35_variables[1] - p35_variables[2]*spec.erfinv((36. - p35_variables[0])/p35_variables[0])
p70_zero = p70_variables2[1] - p70_variables2[2]*spec.erfinv((36. - p70_variables2[0])/p70_variables2[0])
print ext_zero, p35_zero, p70_zero
gmod = Model(est_tooth_extension)
print gmod.eval(x=tooth_70p_b, amplitude=25., slope=.006, offset=110.)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax2 = ax.twinx()
ax2.plot(days[1::4], diff_extension_erf[::4], 'b.', label=r'$ \mathrm{extension} \ \Delta $')
ax2.plot(days[1::4], diff_p35_erf[::4], 'm.', label=r'$ \mathrm{maturation} \ \Delta $')
ax2.plot(days[1::4], diff_p70_erf[::4], 'r.', label=r'$ \mathrm{completion} \ \Delta $')
ax2.set_ylim([0,300])
ax2.set_xlim([-60,350])
ax.plot(tooth_days, tooth_extension, marker='o', linestyle='none', color='b', label=r'$ \mathrm{extension}$')
ax.plot(tooth_days, tooth_35p, marker='o', linestyle='none', color='m', label=r'$ \mathrm{maturation}$')
ax.plot(tooth_days, tooth_70p, marker='o', linestyle='none', color='r', label=r'$ \mathrm{completion}$')
ax.plot(days, extension_erf, linestyle='-', color='b', label=r'$ \mathrm{extension,} \ \mathrm{optimized} $')
ax.plot(days, p35_erf, linestyle='-', color='m', label=r'$ \mathrm{maturation,} \ \mathrm{optimized} $')
ax.plot(days, p70_erf, linestyle='-', color='r', label=r'$ \mathrm{completion,} \ \mathrm{optimized} $')
ax.set_ylim([0,40])
ax.set_xlim([-60,350])
plt.title('Enamel secretion and maturation progress over time')
ax.set_xlabel('Days after birth')
ax.set_ylabel('Progress from cusp tip in mm')
ax2.set_ylabel('Secretion or maturation speed in um/day')
ax2.legend(loc='lower right', fancybox=True, framealpha=0.8)
ax.legend(loc='upper left', fancybox=True, framealpha=0.8)
plt.show()
'''
ax2 = ax.twinx()
ax2.plot(xs, ys, color='g', label='radiograph extension, smooth')
ax2.plot(days, increase_per_day, color='y', label='radiograph extension, raw')
ax2.plot(kday, kext, color='k', mfc='none', marker='o', linestyle='none', label='histology extension')
plt.show()
'''
return 0
示例5: print
# 需要导入模块: from lmfit import Model [as 别名]
# 或者: from lmfit.Model import eval [as 别名]
#fitResult = cellModel.fit(ii, V=vv)
#resultParams = fitResult.params
#print(fitResult.fit_report())
#print(fitResult.message)
fitResult = cellModelV.fit(vv, I=ii,method='nelder')
resultParams = fitResult.params
print(fitResult.fit_report())
print(fitResult.message)
exit(code=0)
#resultParams['Rsh'].value = resultParams['Rsh'].value + 1000
#resultParams['Iph'].value = resultParams['Iph'].value - 0.09e-3
#resultParams['n'].value = resultParams['n'].value + 0.2
fig, ax = plt.subplots()
fitVals = cellModel.eval(params=resultParams,V=vv)
ax.plot(vv,fitVals,label='Fit')
ax.plot(vv,ii,'.',label='Data')
ax.legend()
fig.tight_layout()
print("SSE={:}".format(SSE(fitVals,ii)))
plt.show()
#cellModelInv = Model(cellEqnV)
#print(f.name)