当前位置: 首页>>代码示例>>Python>>正文


Python UnivariateSpline.get_coeffs方法代码示例

本文整理汇总了Python中scipy.interpolate.UnivariateSpline.get_coeffs方法的典型用法代码示例。如果您正苦于以下问题:Python UnivariateSpline.get_coeffs方法的具体用法?Python UnivariateSpline.get_coeffs怎么用?Python UnivariateSpline.get_coeffs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.interpolate.UnivariateSpline的用法示例。


在下文中一共展示了UnivariateSpline.get_coeffs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
class ValueFunctionSpline:
    def __init__(self,X,y,k,sigma,beta):
        self.sigma = sigma
        self.beta = beta
        if sigma == 1.0:
            y = np.exp((1-beta)*y)
        else:
            y = ((1-beta)*(1.0-sigma)*y)**(1.0/(1.0-sigma))
        self.f = UnivariateSpline(X,y,k=k,s=0)

    def fit(self,X,y,k):
        if self.sigma == 1.0:
            y = np.exp((1-self.beta)*y)
        else:
            y = ((1-self.beta)*(1.0-self.sigma)*y)**(1.0/(1.0-self.sigma))
        self.f = UnivariateSpline(X,y,k=k,s=0)#.fit(X,y,k)

    def getCoeffs(self):
        return self.f.get_coeffs()

    def __call__(self,X,d = None):
        if d==None:
            if self.sigma == 1.0:
                return np.log(self.f(X))/(1-self.beta)
            else:
                return (self.f(X)**(1.0-self.sigma))/((1.0-self.sigma)*(1-self.beta))

        if d==1:
            return self.f(X)**(-self.sigma) * self.f(X,1)/(1-self.beta)
        raise Exception('Error: d must equal None or 1')
开发者ID:dgevans,项目名称:RMT_appendix,代码行数:32,代码来源:bellman.py

示例2: fit_and_plot_mpl_bspline

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
def fit_and_plot_mpl_bspline(x,y):
# Fit B-spline with matplotlib and plot it
    SPLINE_ORDER = 3
    spl = UnivariateSpline(x,y,k=SPLINE_ORDER)
    plt.plot(x,y,'r')
    plt.plot(x,spl(x),'g')

    knots  = spl.get_knots()
    coeffs = spl.get_coeffs()
    yr = plt.ylim()

    for knot in knots:
        plt.axvline(knot,color='g')
    #for coeff in coeffs:
        #plt.text(???,(yr[0]+yr[1])/2,"%f" % coeff)
    plt.show()
开发者ID:oparry,项目名称:python,代码行数:18,代码来源:scratch.test_splines.py

示例3: fit_trace

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
def fit_trace(trace, deg=5):
    spl = UnivariateSpline(trace.sample_f, trace.trace_f, k=deg)
    return [deg, spl.get_coeffs().tolist(), spl.get_knots().tolist()]
开发者ID:acasmor,项目名称:megaradrp,代码行数:5,代码来源:traces.py

示例4: draw

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
def draw(self,x_diag,y_diag,x_anti,y_anti,degree):
    s=UnivariateSpline(x_diag,y_diag,k=degree)
    coeffs_diag=s.get_coeffs()
开发者ID:domyang,项目名称:copulas,代码行数:5,代码来源:spline.py

示例5: DualSplineSmoother

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
class DualSplineSmoother(object):
	'''
	claselfdocs
	'''


	def __init__(self, yp, workdir, scale, sm=200):
		'''
		Constructor
		'''
		yp = np.array(yp)
		self.l = len(yp)/2
		self.xPos = (self.l-2)/2 #fPos = (self.l-2)/2 + 2
		tnsc = 2/scale
		print tnsc
		plt.rcParams['font.size'] = 24
		plt.rcParams['lines.linewidth'] = 2.4
		self.workdir = workdir
		
		avProfilePoints = yp[:self.l]
		self.avx = np.append(np.append([0], np.sort(np.tanh(tnsc*avProfilePoints[:self.xPos]))),[1])
		self.av = avProfilePoints[self.xPos:]
		
		sigmaProfilePoints = yp[self.l:]
		self.sigmax = np.append(np.append([0], np.sort(np.tanh(tnsc*sigmaProfilePoints[:self.xPos]))),[1])
		self.sigma = sigmaProfilePoints[self.xPos:]
		
		self.m = UnivariateSpline(self.avx, self.av)
		print "Created spline with " + str(len(self.m.get_knots())) + " knots"

		self.s = UnivariateSpline(self.sigmax, self.sigma)
		print "Created spline with " + str(len(self.s.get_knots())) + " knots"

	def saveSpline(self, filename):
		tp = np.linspace(0, 1, 1000)
		with open(filename ,"w+") as f:
			for i in range(0, 1000):
				f.write( str(tp[i]) + " , " + str(self.m(tp[i])) )
				if i < 999:
					f.write("\n")
		f.close()
	
	def saveSigmaSpline(self, filename):
		tp = np.linspace(0, 1, 1000)
		with open(filename ,"w+") as f:
			for i in range(0, 1000):
				f.write( str(tp[i]) + " , " + str(self.s(tp[i])) )
				if i < 999:
					f.write("\n")
		f.close()
	
	def showSpline(self, order=0):
		plt.clf()
		print "Spline full information:"
		print self.m.get_knots()
		print self.m.get_coeffs()
		print self.m.get_residual()
		tp = np.linspace(0, 1, 1000)
		plt.subplot(211)
		plt.scatter(self.avx,self.av)
		plt.plot(tp,self.m(tp))
		plt.subplot(212)
		plt.scatter(self.sigmax,self.sigma)
		plt.plot(tp,self.s(tp))
		plt.savefig(self.workdir+"/splineFit.pdf")
		if order > 0:
			plt.clf()
			plt.subplot(211)
			plt.plot(tp,self.m(tp,1))
			plt.subplot(212)
			plt.plot(tp,self.s(tp,1))
			plt.savefig(self.workdir+"/splineDerivative.pdf")
	
	def plotSplineData(self, dataContainer, yscale):
		plt.clf()
		plt.xlim(0,1)
		plt.ylim(0,yscale)
		tp = np.linspace(0, 1, 100)
		plt.scatter(dataContainer.points[0],dataContainer.points[1]+dataContainer.background, c='b', marker='o', s=5)
		plt.plot(tp, self.m(tp)+dataContainer.background,'r', linewidth=2)
		plt.plot(tp, self.m(tp)+np.sqrt(self.s(tp))+dataContainer.background,'r--', linewidth=2)
		plt.plot(tp, self.m(tp)-np.sqrt(self.s(tp))+dataContainer.background,'r--', linewidth=2)
		plt.plot(tp, np.zeros(100) + dataContainer.background, '--', c='#BBBBBB', alpha=0.8)
		plt.savefig(self.workdir+"/splineVsData.pdf")
		
	def plotBinnedData(self, dataContainer):
		plt.clf()
		tp = np.linspace(0, 1, dataContainer.numBins)
		tpHD = np.linspace(0, 1, 500)
		plt.plot(self.m(tpHD), self.s(tpHD))
		plt.plot(dataContainer.avs, np.power(dataContainer.stds,2), 'o')
		plt.savefig(self.workdir+"/noiseVsBins.pdf")
		plt.clf()
		plt.plot(tpHD, self.m(tpHD),'r', linewidth=2)
		plt.plot(tp, dataContainer.avs, 'o')
		plt.savefig(self.workdir+"/splineVsBins.pdf")
		plt.clf()
		plt.plot(tpHD, self.s(tpHD),'r', linewidth=2)
		plt.plot(tp, np.power(dataContainer.stds,2), 'o')
		plt.savefig(self.workdir+"/spatialNoiseVsBins.pdf")
#.........这里部分代码省略.........
开发者ID:tmramalho,项目名称:inferProfiles,代码行数:103,代码来源:DualSplineSmoother.py

示例6: SplineSmoother

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
class SplineSmoother(object):
	'''
	claselfdocs
	'''


	def __init__(self, yp, workdir, scale, sm=200):
		'''
		Constructor
		'''
		
		self.workdir = workdir
		yp = np.array(yp)
		self.l = len(yp)
		self.xPos = (self.l-2)/2 #fPos = (self.l-2)/2 + 2
		tnsc = 2/scale
		print tnsc
		plt.rcParams['font.size'] = 24
		plt.rcParams['lines.linewidth'] = 2.4
		self.workdir = workdir
		
		self.avx = np.append(np.append([0], np.sort(np.tanh(tnsc*yp[:self.xPos]))),[1])
		self.av = yp[self.xPos:]
		self.m = UnivariateSpline(self.avx, self.av)
		
		plt.rcParams['font.size'] = 24
		plt.rcParams['lines.linewidth'] = 2.4

		print "Created spline with " + str(len(self.m.get_knots())) + " knots"

	def saveSpline(self, filename):
		tp = np.linspace(0, 1, 1000)
		with open(filename ,"w+") as f:
			for i in range(0, 1000):
				f.write( str(tp[i]) + " , " + str(self.m(tp[i])) )
				if i < 999:
					f.write("\n")
		f.close()
	
	def showSpline(self, order=0):
		plt.clf()
		print "Spline full information:"
		print self.m.get_knots()
		print self.m.get_coeffs()
		print self.m.get_residual()
		tp = np.linspace(0, 1, 1000)
		plt.scatter(self.avx, self.av)
		plt.plot(tp,self.m(tp))
		plt.savefig(self.workdir+"/splineFit.pdf")
		if order > 0:
			plt.plot(tp,self.m(tp,1))
			if order > 1:
				plt.plot(tp,self.m(tp,2))
			plt.savefig(self.workdir+"/splineDerivative.pdf")
	
	def plotSplineData(self, dataContainer, s, p, se, yscale):
		plt.clf()
		plt.xlim(0,1)
		plt.ylim(0,yscale)
		tp = np.linspace(0, 1, 500)
		plt.scatter(dataContainer.points[0],dataContainer.points[1]+dataContainer.background, c='b', marker='o', s=5)
		plt.plot(tp, self.m(tp)+dataContainer.background,'r', linewidth=2)
		plt.plot(tp, self.m(tp)+np.sqrt(s*(p*self.m(tp)*self.m(tp)+self.m(tp)+se))+dataContainer.background,'r--', linewidth=2)
		plt.plot(tp, self.m(tp)-np.sqrt(s*(p*self.m(tp)*self.m(tp)+self.m(tp)+se))+dataContainer.background,'r--', linewidth=2)
		plt.plot(tp, np.zeros(500) + dataContainer.background, '--', c='#BBBBBB', alpha=0.8)
		plt.savefig(self.workdir+"/splineVsData.pdf")
		
	def plotBinnedData(self, dataContainer, s, p, se, xmin, xmax):
		plt.clf()
		sigma = lambda x: s * (p*x*x + x + se)
		t = np.linspace(xmin, xmax, 500)
		plt.xlim(xmin, xmax)
		plt.plot(t, sigma(t))
		plt.plot(dataContainer.avs, np.power(dataContainer.stds,2), 'o')
		plt.savefig(self.workdir+"/noiseVsBins.pdf")
		plt.clf()
		tp = np.linspace(0, 1, dataContainer.numBins)
		plt.plot(tp, self.m(tp),'r', linewidth=2)
		plt.plot(tp, dataContainer.avs, 'o')
		plt.savefig(self.workdir+"/splineVsBins.pdf")
	
	def plotFisherInfo(self, dataContainer, s, p, se, ymax, ymaxsq):
		plt.clf()
		t = np.linspace(0, 1, 1000)
		
		minf = lambda x: -1 * self.m(x)
		minx = fminbound(minf, 0, 1)
		fval = self.m(minx)
		s = s/fval
		se = se/fval
		p = p*fval
		print fval, s, p, se
		fi = lambda m, mp: 2*np.power(s * (p * np.power(m,2) + m),2)/(np.power(mp,2) * 
		(2 * s * (p * np.power(m,2) + m) + np.power(s * (2 * p * m + 1), 2)))
		fiapp = lambda m, mp: s * (p * np.power(m,2) + m) / np.power(mp,2)
		plt.xlim(0, 1)
		plt.ylim(0, ymaxsq)
		plt.plot(t, fi(self.m(t)/fval, self.m(t, 1)/fval))
		plt.plot(t, fiapp(self.m(t)/fval, self.m(t, 1)/fval), 'r')
		plt.savefig(self.workdir+"/variance.pdf")
#.........这里部分代码省略.........
开发者ID:tmramalho,项目名称:inferProfiles,代码行数:103,代码来源:SplineSmoother.py

示例7: enumerate

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
pl.figure()
#Plot experimental data points and interpolated curve
for k,perc in enumerate(percs):
	partition = [g(a,b) for a,b in zip(gs_PEG1k_add,gs_PEG200)]
	print perc,partition[k]
	pl.plot(0.01*perc,partition[k],'b',marker= 's',linestyle = '--', linewidth= 2.5, markersize= 4, markevery= 1)
	y=[.03,.06,.09,.12,.15]
	z=[2.106,1.70,1.367,1.209,1.231]
	x = interpolate.UnivariateSpline(y,z,k=3)
	xx = interpolate.UnivariateSpline(y,z,k=2)
	#xxx = interpolate.UnivariateSpline(y,z,k=1)
	yy=np.arange(0,.16,.01)
	zz=x(yy)
	zzz=xx(yy)
	#zzzz=xxx(yy)
	coeff = UnivariateSpline.get_coeffs(xx)
	print coeff
#	pl.plot(yy,zzz+1.0,'b',linestyle=':', linewidth=0.2)#label= labelss) 
#	pl.plot(yy,zzz+0.6,'b',linestyle=':', linewidth=0.2)#label= labelss) 
#	pl.plot(yy,zzz+0.2,'b',linestyle=':', linewidth=0.2)#label= labelss) 
	pl.plot(yy,zzz,'b',linestyle=':', linewidth=0.2)#label= labelss) 
#Plot theory partition coeff curves for different fixed vals of deltaF and big polymer vol frac
for i,phi_b in enumerate(phi_bs):
	phis = np.linspace(0.0, 1.0-phi_b-phi_water_min, 100)
#	for df in dfs:
	for j,df in enumerate(dfs):
		try: ps = [P(phi,phi_b,df) for phi in phis]
	       	except: continue
		resids = [abs(f(p,phi,phi_b,df)) for p,phi in zip(ps, phis)]
		max_resid = max(resids)
		print 'Largest residual for df=%f: %e' % (df, max_resid)
开发者ID:JJHopkins,项目名称:PPP_two_polymer,代码行数:33,代码来源:philip_data_1k_10k_PC_spline2.py

示例8: float

# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import get_coeffs [as 别名]
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import UnivariateSpline
nItems = 500
x = np.linspace(-3, 3, nItems)
y = np.exp(-x**2) + 0.1 * np.random.randn(nItems)
plt.plot(x, y, 'ro', ms=5)

smoothFactor = float(nItems) / 50.0

spl = UnivariateSpline(x, y, k = 2, s = smoothFactor)
xs = np.linspace(-3, 3, 1000)
plt.plot(xs, spl(xs), 'g', lw=3)

coeffs = spl.get_coeffs()
knots  = spl.get_knots()

print 'coeffs', coeffs
print 'knots', knots

knotsY = spl(knots)
plt.plot(knots, knotsY, 'bo')

#spl.set_smoothing_factor(0.5)
#print 'coeffs', spl.get_coeffs()
#print 'knots', spl.get_knots()
#plt.plot(xs, spl(xs), 'b', lw=3)
plt.show()

开发者ID:Daiver,项目名称:jff,代码行数:30,代码来源:main.py


注:本文中的scipy.interpolate.UnivariateSpline.get_coeffs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。