Happy Diwali 2025: Best 100 Diwali Wishes, Quotes, Messages, WhatsApp Status, Imagesdiwali 2025 diwali date
Happy Diwali 2025: Best 100 Diwali Wishes, Quotes, Messages, WhatsApp Status, Images
jain news jain mantra jain music stavan songs news facts astrology vastu shastra health treatment baby names india tourist place news ayurvedic upchar health disease best places to visit in india and world health blogging hosting domain wishing message blogging blogger tips free adsense friendly template theme for blogger blogspot.com blogger blogspot.com adsense blogging tips in english hindi blogging tips e cards wishing images
import numpy as np import matplotlib.pyplot as plt np.random.RandomState(10) N_points = 20 N_neurons = N_points*2 t = np.linspace(0, np.pi*2, N_points) x = np.cos(t)+(np.random.rand(N_points)-.5)*.3 y = np.sin(t)*.8+(np.random.rand(N_points)-.5)*.2 points = np.array([x,y]).T plt.scatter(x, y)
from minisom import MiniSom som = MiniSom(1, N_neurons*2, 2, sigma=10, neighborhood_function='gaussian', random_seed=50) max_iter = 2000 som.pca_weights_init(points) paths_x = [] paths_y = [] for i in np.arange(max_iter): i_point = i % len(points) som.update(points[i_point], som.winner(points[i_point]), i, max_iter) visit_order = np.argsort([som.winner(p)[1] for p in points]) visit_order = np.concatenate((visit_order, [visit_order[0]])) paths_x.append(points[visit_order][:,0]) paths_y.append(points[visit_order][:,1]) plt.scatter(x, y, label='point to visit') plt.plot(paths_x[-1], paths_y[-1], 'C3', linewidth=2, label='path')
from matplotlib.animation import FuncAnimation from IPython.display import HTML fig, ax = plt.subplots() plt.scatter(x, y, label='point to visit') ln, = plt.plot([], [], 'C3', linewidth=2, label='path') plt.legend() def update(frame): ln.set_data(paths_x[frame], paths_y[frame]) plt.title('iteration = %d' % frame) return ln, ani = FuncAnimation(fig, update, frames=np.arange(max_iter), interval=10, repeat=False, blit=False) HTML(ani.to_html5_video())
Comments
Post a Comment