天文数据分析方法与计算

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
xi2 = np.r_[0.1:1.0:100j] yi2 = c[0]*np.exp(-xi2) + c[1]*xi2
plt.plot(xi,zi,'x',xi2,yi2) plt.axis([0,1.1,3.0,5.5]) plt.xlabel('$x_i$') plt.title('Data fitting with linalg天.l文st数sq据')分析方法和计算 plt.show()
from scipy.optimize import leastsq plsq = leastsq(residuals, p0, args=(y_meas, x)) print plsq[0] # [ 10.9437 33.3605 0.5834]
print array([A, k, theta]) # [ 10. 33.3333 0.5236]
import matplotlib.pyplot as plt
plt.plot(x,peval(x,plsq[0]),x,y_meas,'o',x,y_true)
plt.title('Least-squares fit to noisy data')
plt.legend(['Fit', 'Noisy', 'True'])
# use RBF rbf = Rbf(x, y, z, epsilon=2) ZI = rbf(XI, YI)
# plot the result n = plt.Normalize(-2., 2.) plt.subplot(1, 1, 1) plt.pcolor(XI, YI, ZI, cmap=cm.jet) plt.scatter(x, y, 100, z, cmap=cm.jet) plt.title('RBF interpolation - multiquadrics') plt.xlim(-2, 2) plt.ylim(-2, 2) plt.colorbar()
def residuals(p, y, x): A,k,theta = p err = y-A*sin(2*pi*k*x+theta) return err
def peval(x, p): return p[0]*sin(2*pi*p[1]*x+p[2])
p0 = [8, 1/2.3e-2, pi/3] print array(p0) # [ 8. 43.4783 1.0472]
• 线性1d插值 (interp1d) • 1d样条插值 (interpolate.splXXX) • 2d样条插值 (bisplrep) • RBF(radial basis function)插值/平滑
天文数据分析方法和计算
import numpy as np from scipy.interpolate import Rbf import matplotlib.pyplot as plt from matplotlib import cm
天文数据分析方法和计算
plt.show()
Maximum Likelihood Estimation (MLE)
天文数据分析方法和计算
最大似然估计
• 一致收敛 • 渐近于正态分布:有极值
天文数据分析方法和计算
等精度高斯分布
天文数据分析方法和计算
非等精度高斯分布
天文数据分析方法和计算
上下限分布
plt.show()
天文数据分析方法和计算
数据拟合
天文数据分析方法和计算
• O=T+e
拟合模型
天文数据分析方法和计算
最小二乘法
天文数据分析方法和计算
imBaidu Nhomakorabeaort numpy as np import scipy.linalg as splin import matplotlib.pyplot as plt
# 2-d tests - setup scattered data x = np.random.rand(100)*4.0-2.0 y = np.random.rand(100)*4.0-2.0 z = x*np.exp(-x**2-y**2) ti = np.linspace(-2.0, 2.0, 100) XI, YI = np.meshgrid(ti, ti)
c1,c2= 5.0,2.0 i = np.r_[1:11] xi = 0.1*i yi = c1*np.exp(-xi)+c2*xi zi = yi + 0.05*np.max(yi)*np.random.randn(len(yi))
A = np.c_[np.exp(-xi)[:,np.newaxis],xi[:,np.newaxis]] c,resid,rank,sigma = splin.lstsq(A,zi) print c,resid,rank,sigma
天文数据分析方法和计算
求极值scipy.optimize
A collection of general-purpose optimization routines. fmin -- Nelder-Mead Simplex algorithm (uses only function calls) fmin_powell -- Powell's (modified) level set method (uses only function calls) fmin_cg -- Non-linear (Polak-Ribiere) conjugate gradient algorithm (can use function and gradient). fmin_bfgs -- Quasi-Newton method (Broydon-Fletcher-Goldfarb-Shanno); (can use function and gradient) fmin_ncg -- Line-search Newton Conjugate Gradient (can use function, gradient and Hessian). leastsq -- Minimize the sum of squares of M equations in N unknowns given a starting estimate.
非线性拟合
• 拟合系数有非线性函数关系
天文数据分析方法和计算
from numpy import x = arange(0,6e-2,6e-2/30) A,k,theta = 10, 1.0/3e-2, pi/6 y_true = A*sin(2*pi*k*x+theta) y_meas = y_true + 2*random.randn(len(x))
天文数据分析方法和计算
天文数据分析方法和计算
数据分析方法
天文数据分析方法和计算
累积概率分布
天文数据分析方法和计算
任意分布的随机数
天文数据分析方法和计算
常用概率分布
天文数据分析方法和计算
数据插值
天文数据分析方法和计算
内插和外推
天文数据分析方法和计算
插值(scipy.interpolate)
相关文档
最新文档