日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python连接高斯数据库_Python加载数据并执行多高斯fi

發(fā)布時間:2025/3/15 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python连接高斯数据库_Python加载数据并执行多高斯fi 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

簡單制作單高斯和的參數(shù)化模型函數(shù)。為最初的猜測選擇一個好的值(這是一個非常關(guān)鍵的步驟),然后讓scipy.optimize稍微調(diào)整一下這些數(shù)字。

你可以這樣做:import numpy as np

import matplotlib.pyplot as plt

from scipy import optimize

data = np.genfromtxt('data.txt')

def gaussian(x, height, center, width, offset):

return height*np.exp(-(x - center)**2/(2*width**2)) + offset

def three_gaussians(x, h1, c1, w1, h2, c2, w2, h3, c3, w3, offset):

return (gaussian(x, h1, c1, w1, offset=0) +

gaussian(x, h2, c2, w2, offset=0) +

gaussian(x, h3, c3, w3, offset=0) + offset)

def two_gaussians(x, h1, c1, w1, h2, c2, w2, offset):

return three_gaussians(x, h1, c1, w1, h2, c2, w2, 0,0,1, offset)

errfunc3 = lambda p, x, y: (three_gaussians(x, *p) - y)**2

errfunc2 = lambda p, x, y: (two_gaussians(x, *p) - y)**2

guess3 = [0.49, 0.55, 0.01, 0.6, 0.61, 0.01, 1, 0.64, 0.01, 0] # I guess there are 3 peaks, 2 are clear, but between them there seems to be another one, based on the change in slope smoothness there

guess2 = [0.49, 0.55, 0.01, 1, 0.64, 0.01, 0] # I removed the peak I'm not too sure about

optim3, success = optimize.leastsq(errfunc3, guess3[:], args=(data[:,0], data[:,1]))

optim2, success = optimize.leastsq(errfunc2, guess2[:], args=(data[:,0], data[:,1]))

optim3

plt.plot(data[:,0], data[:,1], lw=5, c='g', label='measurement')

plt.plot(data[:,0], three_gaussians(data[:,0], *optim3),

lw=3, c='b', label='fit of 3 Gaussians')

plt.plot(data[:,0], two_gaussians(data[:,0], *optim2),

lw=1, c='r', ls='--', label='fit of 2 Gaussians')

plt.legend(loc='best')

plt.savefig('result.png')

如您所見,這兩種配合(視覺上)幾乎沒有區(qū)別。所以你不能確定源中是否有3個高斯子,或者只有2個高斯子。但是,如果您必須進(jìn)行猜測,請檢查最小的殘差:err3 = np.sqrt(errfunc3(optim3, data[:,0], data[:,1])).sum()

err2 = np.sqrt(errfunc2(optim2, data[:,0], data[:,1])).sum()

print('Residual error when fitting 3 Gaussians: {}\n'

'Residual error when fitting 2 Gaussians: {}'.format(err3, err2))

# Residual error when fitting 3 Gaussians: 3.52000910965

# Residual error when fitting 2 Gaussians: 3.82054499044

在這種情況下,3高斯給出了一個更好的結(jié)果,但我也使我的初步猜測相當(dāng)準(zhǔn)確。

總結(jié)

以上是生活随笔為你收集整理的python连接高斯数据库_Python加载数据并执行多高斯fi的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。