最小化曲线之间的距离

时间:2020-09-07 17:41:52

标签: python-3.x matplotlib distribution normal-distribution

即使我随机生成数字,曲线之间还是存在间隙,并且我没有实现交点。

如何最小化曲线之间的距离?

这是我的代码:

import matplotlib.pyplot as plt
import pylab
import numpy as np 
from scipy.stats import norm
import scipy.stats
from math import sqrt

#parameters
Mu1=2
Sig_Faulty=2
N=100
Sig_healthy=Sig_Faulty/sqrt(N)

#100 Faulty samples
Faulty_rand=np.random.normal(Mu1,scale=Sig_healthy,size=100)
Faulty=np.sort(Faulty_rand)
PDF_Faulty=norm.pdf(Faulty,Mu1,scale=Sig_healthy)

#determaining the limits of the faulty samples to build the healthy samples
LimH=np.amax(Faulty)
LimL=np.amin(Faulty)

#100 healthy samples 

Healthy=np.sort(np.random.normal(0,scale=Sig_healthy,size=100))
PDF_Helthy=norm.pdf(Healthy,0,scale=Sig_healthy)
PDF_Helthy_maxlim=np.amax(PDF_Helthy)

#limits for the false alam, and the PDF for each limit
Healthy_low= norm.ppf(0.025,0,scale=Sig_healthy)
Healthy_high= norm.ppf(0.975,0,scale=Sig_healthy)
Healthypdf_low=norm.pdf(Healthy_low,0,scale=Sig_healthy)
Healthypdf_high=norm.pdf(Healthy_low,0,scale=Sig_healthy)


#plotting 
plot4=plt.figure(4)
plt.plot(Healthy,PDF_Helthy,label='Healthy')
plt.plot(Faulty,PDF_Faulty,label='Faulty')
plt.plot([Healthy_low,Healthy_low],[0,PDF_Helthy_maxlim],label='Lower false alarm limit')
plt.plot([Healthy_high,Healthy_high],[0,PDF_Helthy_maxlim],label='Upper false alarm limitm')
plt.xlabel('X')
plt.ylabel('PDF')
plt.legend()
plt.show()

这是实际的输出图像:

enter image description here

0 个答案:

没有答案