首页 > 其他 > 详细

Simulating noise-free and noise-corrupted data

时间:2019-08-17 12:51:28      阅读:100      评论:0      收藏:0      [点我收藏+]
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

# number of data
N = 31

# coordinates of the data
x = np.linspace(0., 30., N)

xmax = np.max(x)
xmin = np.min(x)
Dx = xmax - xmin

# true constants a and b
a = -5.
b = 0.1

# noise-free data vector
d_free = a + b*x

# Gaussian noise with null mean and standard deviation defined 
#by the variable stdev
stdev = 0.3
noise = np.random.normal(loc = 0., scale=stdev, size=N)

# noise-corrupted data
d_noise = d_free + noise

dmin = np.min(d_noise)
dmax = np.max(d_noise)
Dd = dmax - dmin

plt.close(‘all‘)
plt.figure(figsize=(10,8))
plt.plot(x, d_free, ‘ko‘, label=‘noise-free data‘)
plt.plot(x, d_noise, ‘ro‘, label=‘noise-corrupted data‘)
plt.xlim(xmin - 0.05*Dx, xmax + 0.05*Dx)
plt.ylim(dmin - 0.05*Dd, dmax + 0.05*Dd)
plt.xlabel(‘x‘, fontsize=14)
plt.ylabel(‘data‘, fontsize=14)
plt.grid()
plt.legend(loc=‘best‘, fontsize=12)
plt.show()

  https://github.com/birocoles/Disciplina-metodos-computacionais/blob/master/Content/least_squares.ipynb

Simulating noise-free and noise-corrupted data

原文:https://www.cnblogs.com/gisalameda/p/11367849.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!