#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np from bokeh.plotting import figure, output_file, show from bokeh.io import output_notebook # In[7]: b = 0.8 # 相関項 x = 10.0 y = 3.0 times = 200 output_notebook() p = figure() for i in range(1, times): x_old = x x = np.random.normal(b*y, 1.0) p.line([x_old, x], [y, y], color="blue",line_width=2) y_old = y y = np.random.normal(b*x, 1.0) p.line([x, x], [y_old, y], color="blue", line_width=2) show(p) # In[7]: # ボックスミューラー法による実装. b = 0.8 # 相関項 x = 10.0 y = 3.0 times = 150 output_notebook() p = figure() for i in range(1, times): u1 = np.random.rand() u2 = np.random.rand() x_old = x x = np.sqrt(-2*np.log(u1))*np.cos(2*np.pi*u2) + b*y p.line([x_old, x], [y, y], color="blue",line_width=2) y_old = y y = np.sqrt(-2*np.log(u1))*np.sin(2*np.pi*u2) + b*x p.line([x, x], [y_old, y], color="blue", line_width=2) show(p) # In[20]: p = figure() p.line([5, 4],[4,4]) show(p) # In[5]: p = figure() imax=400 for i in range(1, imax): u1 = np.random.rand() u2 = np.random.rand() p.scatter(u1, u2) show(p) # In[8]: np.random.rand() # In[23]: y=2 y_old =1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (bins - b*y)**2 / (2 * sigma**2)) y_old # In[17]: p = figure() mu, sigma = 0, 0.1 s = np.random.normal(mu, sigma, 100) p.scatter(s, s) show(p) # In[1]: import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # ボックスミューラー法による実装. b = 0.8 # 相関項 x = 10.0 y = 3.0 times = 200 im = [] ims = [] fig = plt.figure() for i in range(1, times): u1 = np.random.rand() u2 = np.random.rand() x_old = x x = np.sqrt(-2*np.log(u1))*np.cos(2*np.pi*u2) + b*y im = im + plt.plot([x_old, x], [y, y], color="blue") y_old = y y = np.sqrt(-2*np.log(u1))*np.sin(2*np.pi*u2) + b*x im = im + plt.plot([x, x], [y_old, y], color="blue") ims.append(im) ani = animation.ArtistAnimation(fig, ims, interval=400) ani.save("output.gif", writer="imagemagick") plt.show() # In[3]: import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation fig, ax = plt.subplots() xdata, ydata = [], [] ln, = plt.plot([], [], 'ro', animated=True) def init(): ax.set_xlim(0, 2*np.pi) ax.set_ylim(-1, 1) return ln, def update(frame): xdata.append(frame) ydata.append(np.sin(frame)) ln.set_data(xdata, ydata) return ln, ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128), init_func=init) plt.show() # In[ ]: