import matplotlib.pyplot as plt
import numpy as np
from sage.misc.prandom import gauss
import pandas as pd
f, t = var('f t')
delay = 3
f(t) = (1 - e^(-t) ) * unit_step(t) + (unit_step(t - delay) + -unit_step(t - delay - pi/2) ) * - sin((t - delay) *2 ) * 0.3
x_arr = np.linspace(0, 10, 200)
y_arr = np.array([ f(x).n() for x in x_arr] )
y_gauss_arr = np.array( [y + gauss(0, 0.2) for y in y_arr] )
df = pd.DataFrame({'x':x_arr, 'y':y_arr, 'y_gauss': y_gauss_arr})
df.head()
df.to_csv('data.csv', index = False)
plt.plot(x_arr, y_arr, 'r-', label = 'Equation' )
plt.plot(x_arr, y_gauss_arr, 'bo', label = 'With Gaussian noise' )
plt.ylim(-0.2, 1.3)
plt.xlim(0, 8 )
plt.title('Exponential dataset with minor hub')
plt.xlabel('t')
plt.ylabel('f')
plt.legend(loc = 'lower right')
plt.savefig('Graph.png')
plt.show()
x y y_gauss
0 0.000000 0.000000000000000 -0.242034190448092
1 0.050251 0.0490095478443424 -0.305477333152103
2 0.100503 0.0956171599087779 0.223260498701876
3 0.150754 0.139940553979831 -0.266497339883467
4 0.201005 0.182091678548535 0.152274874333325
[<matplotlib.lines.Line2D object at 0x7ff459a24290>]
[<matplotlib.lines.Line2D object at 0x7ff459a24710>]
(-0.200000000000000, 1.30000000000000)
(0, 8)
<matplotlib.text.Text object at 0x7ff459ac0790>
<matplotlib.text.Text object at 0x7ff459c860d0>
<matplotlib.text.Text object at 0x7ff459c20b90>
<matplotlib.legend.Legend object at 0x7ff459a24b50>