def plot_2d_input_weights():
    name = 'XeAe'
    weights = get_2d_input_weights()
    fig = b2.figure(fig_num, figsize = (18, 18))
    im2 = b2.imshow(weights, interpolation = "nearest", vmin = 0, vmax = wmax_ee, cmap = cmap.get_cmap('hot_r'))
    b2.colorbar(im2)
    b2.title('weights of connection' + name)
    fig.canvas.draw()
    return im2, fig
Exemple #2
0
def plot_2d_input_weights():
    name = 'XeAe'
    weights = get_2d_input_weights()
    fig = b2.figure(fig_num, figsize = (18, 18))
    im2 = b2.imshow(weights, interpolation = "nearest", vmin = 0, vmax = wmax_ee, cmap = cmap.get_cmap('hot_r'))
    b2.colorbar(im2)
    b2.title('weights of connection' + name)
    fig.canvas.draw()
    return im2, fig
Exemple #3
0
def visualise_connectivity(S):
    Ns = len(S.source)
    Nt = len(S.target)
    b.figure(figsize=(10, 4))
    b.subplot(121)
    b.plot(b.zeros(Ns), b.arange(Ns), 'ok', ms=10)
    b.plot(b.ones(Nt), b.arange(Nt), 'ok', ms=10)
    for i, j in zip(S.i, S.j):
        b.plot([0, 1], [i, j], '-k')
    b.xticks([0, 1], ['Source', 'Target'])
    b.ylabel('Neuron index')
    b.xlim(-0.1, 1.1)
    b.ylim(-1, max(Ns, Nt))
    b.subplot(122)
    b.plot(S.i, S.j, 'ok')
    b.xlim(-1, Ns)
    b.ylim(-1, Nt)
    b.xlabel('Source neuron index')
    b.ylabel('Target neuron index')
Exemple #4
0
    def show_event_monitor(self,
                           monitor,
                           window='',
                           figure_title='',
                           xlab='Time (ms)',
                           ylab='Neuron Index',
                           marker='o',
                           use_grid=True,
                           is_figure=True):
        """
        Plots a cloud chart for a specific `EventMonitor`.

        Parameters
        ----------
        monitor : str
            Name of the `EventMonitor`.
        window : str, optional
            Name of the window. Defaults to ``monitor``.
        figure_title : str, optional
            Name of the figure.
            Defaults to 'Firing of ``event`` events during simulation'.
        ylab : str, optional
            Y-axis label.
        xlab : str, optional
            X-axis label.
        marker : str, optional
            Marker style.
        use_grid : bool, optional
            Is the grid activated?
        """
        if is_figure:
            figure(monitor if window == '' else window)
            title('Firing of {} events during simulation'.
                  format(self._event_monitors[monitor]) if figure_title ==
                  '' else figure_title)
        scatter(self[monitor].t / ms, self[monitor].i, marker=marker)
        xlabel(xlab)
        ylabel(ylab)
        if use_grid:
            grid()

        pause(0.001)
Exemple #5
0
def plot_performance(fig_num):
    num_evaluations = int(num_examples/update_interval)
    time_steps = range(0, num_evaluations)
    performance = np.zeros(num_evaluations)
    fig = b2.figure(fig_num, figsize = (5, 5))
    fig_num += 1
    ax = fig.add_subplot(111)
    im2, = ax.plot(time_steps, performance) #my_cmap
    b2.ylim(ymax = 100)
    b2.title('Classification performance')
    fig.canvas.draw()
    return im2, performance, fig_num, fig
def plot_performance(fig_num):
    num_evaluations = int(num_examples/update_interval)
    time_steps = range(0, num_evaluations)
    performance = np.zeros(num_evaluations)
    fig = b2.figure(fig_num, figsize = (5, 5))
    fig_num += 1
    ax = fig.add_subplot(111)
    im2, = ax.plot(time_steps, performance) #my_cmap
    b2.ylim(ymax = 100)
    b2.title('Classification performance')
    fig.canvas.draw()
    return im2, performance, fig_num, fig
Exemple #7
0
        rI = b2.PopulationRateMonitor(P_I, name='rI')
        net = b2.Network(b2.collect())
        net.store('initialised')

    net.restore('initialised')
    net.run(duration=runtime, report='stdout', namespace=namespace)
    return net


if __name__ == '__main__':
    net = None
    N_traces = 5
    conv_width = 10 * b2.ms
    leaveout_steps = int(conv_width / b2.defaultclock.dt)
    # leaveout_steps = 10
    b2.figure()
    for trace in range(N_traces):
        net = run_model(net=net)
        r1 = net['r1']
        r2 = net['r2']
        r0 = net['r0']
        rI = net['rI']
        # ri1 = net['ri1']
        # ri2 = net['ri2']

        b2.plot(
            r1.smooth_rate(width=conv_width)[:-leaveout_steps] / b2.Hz,
            r2.smooth_rate(width=conv_width)[:-leaveout_steps] / b2.Hz)
    ymin, ymax = b2.ylim()
    xmin, xmax = b2.xlim()
    b2.ylim([min(xmin, ymin), max(xmax, ymax)])
Exemple #8
0
#------------------------------------------------------------------------------
print('save results')
if not test_mode:
    save_theta()
if not test_mode:
    save_connections()
else:
    np.save(data_path + 'activity/resultPopVecs' + str(num_examples), result_monitor)
    np.save(data_path + 'activity/inputNumbers' + str(num_examples), input_numbers)


#------------------------------------------------------------------------------
# plot results
#------------------------------------------------------------------------------
if rate_monitors:
    b2.figure(fig_num)
    fig_num += 1
    for i, name in enumerate(rate_monitors):
        b2.subplot(len(rate_monitors), 1, 1+i)
        b2.plot(rate_monitors[name].t/b2.second, rate_monitors[name].rate, '.')
        b2.title('Rates of population ' + name)

if spike_monitors:
    b2.figure(fig_num)
    fig_num += 1
    for i, name in enumerate(spike_monitors):
        b2.subplot(len(spike_monitors), 1, 1+i)
        b2.plot(spike_monitors[name].t/b2.ms, spike_monitors[name].i, '.')
        b2.title('Spikes of population ' + name)

if spike_counters:
                                i] = np.histogram(weights_rates[mask] / w_max,
                                                  bins=N_bins,
                                                  density=True,
                                                  range=(0., 1.))[0]

    weights_mu = b2.array(synapse_mu.w)
    mu_weight_histograms = b2.empty((N_bins, N_out))
    for i in range(N_out):
        # brian2 uses i->j synapse syntax, while I use j->i
        mask = synapse_mu.j == i
        mu_weight_histograms[:, i] = np.histogram(weights_mu[mask] / w_max,
                                                  bins=N_bins,
                                                  density=True,
                                                  range=(0., 1.))[0]

    b2.figure(figsize=(4, 4))
    im = b2.imshow(
        rates_weight_histograms,
        origin='lower',
        extent=[postsyn_rates[0] / b2.Hz, postsyn_rates[-1] / b2.Hz, 0, 1],
        aspect='auto',
        cmap=b2.plt.cm.gray_r)
    # b2.colorbar(label='probability density')
    b2.xlabel("Postsynaptic Firing Rate (Hz)")
    # b2.ylabel(r"$\frac{w}{w_{max}}$", rotation=0)
    b2.ylabel("$w/w_{max}$")
    b2.title(
        'Synaptic Strength Distributions\nas function of postsynaptic firing rate'
    )
    b2.savefig('images_and_animations/synaptic_strengths_vs_firing_rates.png')
    # b2.show()
#------------------------------------------------------------------------------
print ('save results')
if not test_mode:
    save_theta()
if not test_mode:
    save_connections()
else:
    np.save(data_path + 'activity/resultPopVecs' + str(num_examples), result_monitor)
    np.save(data_path + 'activity/inputNumbers' + str(num_examples), input_numbers)


#------------------------------------------------------------------------------
# plot results
#------------------------------------------------------------------------------
if rate_monitors:
    b2.figure(fig_num)
    fig_num += 1
    for i, name in enumerate(rate_monitors):
        b2.subplot(len(rate_monitors), 1, 1+i)
        b2.plot(rate_monitors[name].t/b2.second, rate_monitors[name].rate, '.')
        b2.title('Rates of population ' + name)

if spike_monitors:
    b2.figure(fig_num)
    fig_num += 1
    for i, name in enumerate(spike_monitors):
        b2.subplot(len(spike_monitors), 1, 1+i)
        b2.plot(spike_monitors[name].t/b2.ms, spike_monitors[name].i, '.')
        b2.title('Spikes of population ' + name)

if spike_counters:
Exemple #11
0
syn_oa = Activator(tau_e, nu_e)
oa_group = b.Synapses(op_group, act_group, model=syn_oa.model, on_pre=syn_oa.on_pre)
oa_group.connect(j='i')

# spikemon = b.SpikeMonitor(inp_group)
# spikemon1 = b.SpikeMonitor(neuron_group)
# M = b.StateMonitor(hh_group, ['z', 'zeta'], record=True)
# M1 = b.StateMonitor(ih_group, 'w', record=True)
# M2 = b.StateMonitor(hh_group, 'w', record=True)
# Ma = b.StateMonitor(oa_group, 'a', record=True)

print e.disToFood
b.run(1 * b.second)
print e.disToFood
e.plot()
b.figure()
b.plot(e.d_history)

# b.figure()
# b.plot(spikemon.t / b.ms, spikemon.i, '.k')
# b.xlabel('Time (in ms)')
# b.ylabel('Neuron index')
#
# b.figure()
# b.plot(spikemon1.t / b.ms, spikemon1.i, '.k')
# b.xlabel('Time (in ms)')
# b.ylabel('Neuron index')
#
# b.figure()
# for ai in Ma.a[:5]:
#     b.plot(Ma.t / b.ms, ai)
Exemple #12
0
    def show_state_monitor(self,
                           monitor,
                           window='',
                           figure_title='',
                           name='Element {}',
                           name_values=None,
                           linestyle='-',
                           xlab='Time (ms)',
                           ylab='',
                           use_grid=True,
                           is_figure=True):
        """
        Plots a line chart for a specific `StateMonitor`.

        Parameters
        ----------
        monitor : str
            Name of the `StateMonitor`.
        window : str, optional
            Name of the window. Default value is ``monitor``.
        figure_title : str, optional
            Name of the figure.
            Default value 'Evolution of ``variable`` over time'.
        name : str, optional
            Name of each set. `{}` is replaced by the set ID.
        name_values list of str, optional
            Values replacing the set IDs for ``name``.
        linestyle : str, optional
            Line style.
        xlab : str, optional
            X-axis label.
        ylab : str, optional
            Y-axis label. Default value is '``variable`` (`dimension`)'.
        use_grid : bool, optional
            Is the grid activated?

        Warnings
        --------
        `dimension` of Volt is "m^2 kg s^-3 A^-1"!
        """
        var = self._state_monitors[monitor]
        values = getattr(self[monitor], var)

        try:
            dim = values.dim
        except AttributeError:
            dim = '1'
        if is_figure:
            figure(monitor if window == '' else window)
            title('Evolution of {} over time'.format(var) if figure_title ==
                  '' else figure_title)
        i = 0
        for v in values:
            plot(
                self[monitor].t / ms,
                v,
                linestyle=linestyle,
                label=(
                    name.format(i if name_values is None else name_values[i])))
            i += 1
        xlabel(xlab)
        ylabel('{} ({})'.format(var, dim) if ylab == '' else ylab)
        if use_grid:
            grid()
        if name != '':
            legend()