def main(args): np.random.seed(args.seed) gens = data.instantiate_generators() X, t_phn, t_spk = data.generate(gens, 100) X_val, t_phn_val, t_spk_val = data.generate(gens, 100) plotter = plotting.Plotter(args.no_plot) plotter.plot(X, t_phn, t_spk, name="Raw data") raw_bl, raw_ur = plotter.plot(X_val, t_phn_val, t_spk_val, name="Raw validation data") torch.manual_seed(args.seed) bne, phn_dec, spk_dec = model.create_models(args.bne_width) print("\nTraining PHN network") training.train(bne, [phn_dec], itertools.chain(bne.parameters(), phn_dec.parameters()), (X, [t_phn]), (X_val, [t_phn_val]), args.nb_epochs) bl, ur = plotter.plot(X, t_phn, t_spk, name="BN features, PHN optimized", transform=bne) plotting.plot_preds(plotter, "PHN decoding in raw space", raw_bl, raw_ur, lambda x: phn_dec(bne(x))) plotting.plot_preds(plotter, "PHN decoding in BN space", bl, ur, phn_dec) print("\nTraining SPK decoder") training.train(bne, [spk_dec], spk_dec.parameters(), (X, [t_spk]), (X_val, [t_spk_val]), args.nb_epochs)
def plot_stuff(y, lam, step, err, figure, axis): fig, ax = figure, axis mpt = plotting.Plotter(fig, ax, A, R, ALPHA) # Plot circles defining the bubble boundary mpt.plot_bubble() # Plot trajectory and related stuff mpt.plot_trajectory(y, lam, step, err, colormap="step_size", solid=False, width=3) # Time arrows, light cones, etc (uncomment as needed). FOR PLOTTING EQUISPACED ARROWS, TURN EXPERIMENTAL OFF! mpt.plot_light_time(15, 6, lightcones=True, time_arrows=True, trajectory=y, param=lam) mpt.plot_light_time(14, 6, param_direction=True, tangents=False, trajectory=y, param=lam)
def main(args): np.random.seed(args.seed) gens = data.instantiate_generators() X, t_phn, t_spk = data.generate(gens, 100) X_val, t_phn_val, t_spk_val = data.generate(gens, 100) plotter = plotting.Plotter(args.no_plot) plotter.plot(X, t_phn, t_spk, name="Raw data") raw_bl, raw_ur = plotter.plot(X_val, t_phn_val, t_spk_val, name="Raw validation data") torch.manual_seed(args.seed) bn_extractor_init, phn_decoder_init, spk_decoder_init = model.create_models( args.bne_width) bn_extractor = copy.deepcopy(bn_extractor_init) spk_decoder = copy.deepcopy(spk_decoder_init) phn_decoder = copy.deepcopy(phn_decoder_init) print("\nTraining in disconcert, from same init:") adversary_train(bn_extractor, phn_decoder, spk_decoder, (X, [t_phn, t_spk]), (X_val, [t_phn_val, t_spk_val]), args.nb_epochs) bl, ur = plotter.plot(X, t_phn, t_spk, name="BN features, PHN-SPK optimized", transform=bn_extractor) plotting.plot_preds(plotter, "PHN decoding in disconcertly trained BN space", bl, ur, phn_decoder)
def plot(self): sel = self.symbolsList.selection() item = self.symbolsList.item(sel[0]) symbol = item.get('text') s = plotting.Symbol(self.datasource, symbol) p = plotting.Plotter("Drawing symbol {0}".format(symbol)) p.draw_simple(s) p.run()
def ctc(): # INITIAL CONDITIONS lam0 = 10 mod = -1 t0, x0, u1_0 = 0, 80, 0 u0_0, u1_0 = tools.get_initial_cond(t0, x0, -1, u1=u1_0, sign="minus") #print(u1_1/u0_1) y0 = [u0_0, u1_0, t0, x0] y, true_y, lam, step, err = rk.rk4(fun_rk_ctc, y0, x0=lam0, num=4000, h_start=0.02, h_max=10**1, h_min=10**-7, h_max_change=1.5, acc=10**-9, experimental=True) fig, ax = plt.subplots(figsize=(11, 9)) # PLOTTING mpt = plotting.Plotter(fig, ax, A, R, ALPHA) # Plot circles defining the bubble boundary mpt.plot_bubble() # Plot trajectory and related stuff mpt.plot_trajectory(y, lam, step, err, colormap="local_speed", colorbar="plot", solid=True, nature="ctc", width=5)
def __init__(self, data=None, datatype="image", stimshape=None, batch_size=100, niter=50, delay=0, buffer=20, ninput=256, nunits=256, p=0.05, alpha=1., beta=0.01, gamma=0.1, theta0=0.5, infrate=0.1, moving_avg_rate=0.001, paramfile='SAILnetparams.pickle', pca=None, store_every=1): """ Create SAILnet object with given parameters. Defaults are as used in Zylberberg et al. Args: data: numpy array of data for analysis datatype: (str) type of data stimshape: (array) hape of images/spectrograms (16,16) default batch_size: (int) size of each data batch niter: (int) number of inference time steps delay: (int) spikes before this time step don't count buffer: (int) buffer on image edges ninput: (int) number of inputs, e.g., pixels nunits: (int) number of SAILnet units / 'neurons' p: (float) target firing rate alpha: (float) learning rate for inhibitory weights beta: (float) learning rate for feedforward weights gamma: (float) learning rate for thresholds theta0: (float) initial value of thresholds infrate: (float) rate parameter for inference moving_avg_rate: (float) rate for averaging stats paramfile: (str) filename for saving parameters pca: (pca) PCA object used to create vector inputs store_every: (int) how many batches between storing stats Raises: ValueError when datatype is not one of the supported options. """ # Store instance variables self.alpha = alpha self.beta = beta self.gamma = gamma self.infrate = infrate self.moving_avg_rate = moving_avg_rate self.p = p self.batch_size = batch_size self.niter = niter self.delay = delay self.nunits = nunits # M in original MATLAB code self.paramfile = paramfile self.pca = pca self.plotter = plotting.Plotter(self) self.ninput = ninput # N in original MATLAB code self.stimshape = stimshape self.store_every = store_every self._load_stims(data, datatype, self.stimshape, self.pca) self.initialize(theta0)
def getPlotter(self): return plotting.Plotter(self.params['gridWidth'], self.params['gridHeight'], self.outputPath)
import plotting from settings import options from boids import World, Boids # ----------------------------------------------------------------------------- # Setup world num_boids = 1000 WORLD_SIZE = [0, options['world_width'], 0, options['world_height']] world = World(WORLD_SIZE) filename = f"{num_boids}_plot.png" # Setup plot NUM_COLOURS = options['num_colours'] cmap = plotting.ColourMap(options) plot = plotting.Plotter(options, world) # Setup Boids boids = Boids(num_boids, world, options) boids.generate_boids(options, distribution='random') # ----------------------------------------------------------------------------- def triang_ver(): boids.triangulate_boids() boids.make_neighbourhoods() # ----------------------------------- Main ------------------------------------
def sweep(t_range, x_range, steps, num, modulus, u1=np.inf, three_velocity=np.inf, radius=None, angle_range=None, sign="minus", nature="geodesic", plotter=None): # The initial parameter is chosen to be != 0 to avoid strange integration errors due to very small numbers. lam0 = 10 div = steps - 1 if steps != 1 else 1 if not radius: t_step = (t_range[1] - t_range[0]) / div x_step = (x_range[1] - x_range[0]) / div else: angle_step = (angle_range[1] - angle_range[0]) / div if plotter: fig, ax = plotter.fig, plotter.ax else: fig, ax = plt.subplots(figsize=(11, 9)) fun = fun_rk if nature == "geodesic" else fun_rk_ctc # Store all the integrations solutions = [] for i in range(steps): print(i) if not radius: t0 = t_range[0] + t_step * i x0 = x_range[0] + x_step * i else: t0 = radius * np.sin(angle_range[0] + angle_step * i) x0 = radius * np.cos(angle_range[0] + angle_step * i) if u1 != np.inf: u0_0, u1_0 = tools.get_initial_cond(t0, x0, modulus, u1=u1, sign=sign) else: u0_0, u1_0 = tools.get_initial_cond(t0, x0, modulus, three_velocity=three_velocity, sign=sign) y0 = [u0_0, u1_0, t0, x0] y, true_y, lam, step, err = rk.rk4(fun, y0, x0=lam0, num=num, h_start=0.02, h_max=10**1, h_min=10**-10, h_max_change=1.5, acc=10**-9, experimental=True, cutoff=False) solutions.append((y, true_y, lam, step, err)) # PLOTTING if plotter: mpt = plotter else: mpt = plotting.Plotter(fig, ax, A, R, ALPHA) # Plot circles defining the bubble boundary if not mpt.has_bubble: mpt.plot_bubble() # Plot trajectory and related stuff #colormap=[0,0,1,1,1] for sol in solutions: y, true_y, lam, step, err = sol mpt.plot_trajectory(true_y, lam, step, err, colormap=[0, 1, 1, 0, 1], limits=[0, 4], colorbar="once", solid=True, width=2, nature=nature)
lam, step, err, colormap="local_speed", colorbar="plot", solid=True, nature="ctc", width=5) if __name__ == '__main__': #CTCs #sweep((0,0), (80,121), 5, 5000, -1, u1=0, nature="ctc") fig, ax = plt.subplots(figsize=(11, 9)) aplotter = plotting.Plotter(fig, ax, A, R, ALPHA) aplotter.plot_bubble() # Null sweeping sweep((-150, -150), (-450, 145), 60, 6000, 0, u1=1, plotter=aplotter, sign='minus') # sweep((-150, -150), (-145, 450), 65, 6000, 0, u1=-1, sign='minus', plotter=aplotter) #sweep((-120, +170), (297, -154), 57, 6000, 0, u1=1, plotter=aplotter, sign='plus') #sweep((+150, +150), (-150, 440), 70, 6000, 0, u1=-1, plotter=aplotter, sign='plus')