在协同进化的响应函数中使用的正确点数是多少?

2024-06-06 14:08:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个输入函数/数据-f(x),我想把它和一个响应函数-g(x)卷积起来,得到一个输出函数-h(x)。我已经验证了g(x)中使用的点的数量影响h(x)的形状。 图1比我所能描述的更好地展示了我的意思: Figure 1: Influence of the number of points used in the response function on the convoluted curves 那么,我的问题是:在g(x)中使用的正确点数是多少

我用python和numpy来做这项工作。我使用的代码是:

#!/usr/bin/python
# -*- coding: utf8 -*-

import numpy as np
import matplotlib.pyplot as plt
import csv

# Full Width at Half Maximum - also known as Instrumental Broadening
FWHM = 0.678

filename = "Input_Data_File.dat"
DataX,DataY = [],[]
with open(filename) as Data:
  reader = csv.reader(Data,delimiter=' ',skipinitialspace=True)
  for row in reader:
    DataX.append(float(row[0]))
    DataY.append(float(row[1]))

# The f(x) data:
DataX = np.array(DataX)
DataY = np.array(DataY)
lx = len(DataX)

x1 = np.linspace(-FWHM*2.0,FWHM*2.0,num=int(lx*(0.1))) #len(x) = 10% of len(DataX)
x2 = np.linspace(-FWHM*2.0,FWHM*2.0,num=int(lx*(0.02))) #len(x) = 2% of len(DataX)
x3 = np.linspace(-FWHM*2.0,FWHM*2.0,num=int(lx*(0.2))) #len(x) = 20% of len(DataX)

# Response function - Gaussian type
G1 = np.exp(-4*np.log(2)*((x1/FWHM)**2))
G2 = np.exp(-4*np.log(2)*((x2/FWHM)**2))
G3 = np.exp(-4*np.log(2)*((x3/FWHM)**2))

# Performing the convolutions
H1 = np.convolve(G1,DataY,'same')
H2 = np.convolve(G2,DataY,'same')
H3 = np.convolve(G3,DataY,'same')

# Normalizing convoluted functions
H1 = H1/max(H1)
H2 = H2/max(H2)
H3 = H3/max(H3)

# Normalizing DataY as Y
Y = DataY/max(DataY)

plt.plot(DataX,Y,'y--', label="Input function / f(x)")
plt.plot(DataX,H1,'r-', label="#points: {}".format(len(x1)))
plt.plot(DataX,H2,'g-', label="#points: {}".format(len(x2)))
plt.plot(DataX,H3,'b-', label="#points: {}".format(len(x3)))
plt.xlabel("x / DataXt")
plt.ylabel("Normalized intensity")
plt.ylim(-0.05,1.05)
plt.title("Influence of #points of 'Response\nfunction' in convoluted curves")
plt.legend(loc='upper left')
plt.savefig("Convoluted_curves.png")
plt.show()

我用作“Input\u data\u file.dat”的数据文件可以在here找到


Tags: oflenplotasnpplth2h1
1条回答
网友
1楼 · 发布于 2024-06-06 14:08:34

通过实验验证,我可以得出结论:响应函数g(x)中使用的正确点数是阶跃最接近输入函数f(x)阶跃的点数

因此,在问题的python代码中,最好的选择是使用numpy.arange和正确的步骤,而不是numpy.linspace

相关问题 更多 >