def learn(self, step, eta, run, rate, T=500, r0=.5, tm=20, ts=2, reset=0, trials=100, start_state=0): np.random.seed(run) # maybe put this outside function to continue learning instead of fresh start self.unlearn(r0) pi = np.zeros((trials, self.num_states), dtype=int) seq = [ [None] ] * trials # sequences might have differnt length -> list instead array W = np.zeros((trials, self.K, self.K), dtype=float) for t in xrange(trials): res = cfn.run(self.W, step, rate, T, tm, ts, reset, run) pi[t] = self.get_policy(step, res[0]) seq[t] = self.sample4Pi(pi[t], start_state) self.update_weights(seq[t], eta) W[t] = self.W return np.array([pi, seq, W])
import cfunctions as cfn from functions import simpleaxis, init_fig savefig = False if len(argv) == 1 else True net = Net() step = .1 init_fig() # colors for colorblind from http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/ col = ['#56B4E9', '#0072B2', '#F0E442', '#E69F00', '#CC79A7', '#D55E00', '#40e0d0', '#009E73'] # Voltage spikes, u = cfn.run(net.W, step, 400, 50, 20, 2, 20, 2) fig1, ax = pl.subplots(nrows=2, ncols=1) for i, j in enumerate([7, 1]): ax[i].plot(u[:, j] + 2 * spikes[:, j], color=col[j], zorder=5) ax[i].set_ylim(-1, 3.5) ax[i].axis('off') ax[-1].plot([0, 10 / step], [-1, -1], c='k', lw=7, clip_on=False, zorder=5) ax[-1].plot([0, 0], [1, 2], c='k', lw=7, clip_on=False, zorder=5) fig1.subplots_adjust(hspace=-.1) fig1.subplots_adjust(.04, .1, 1, 1) if savefig: pl.savefig('u.pdf', dpi=600, transparent=True) else: pl.show() # Spikes
from functions import simpleaxis, init_fig savefig = False if len(argv) == 1 else True net = Net() step = .1 init_fig() # colors for colorblind from http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/ col = [ '#56B4E9', '#0072B2', '#F0E442', '#E69F00', '#CC79A7', '#D55E00', '#40e0d0', '#009E73' ] # Voltage spikes, u = cfn.run(net.W, step, 400, 50, 20, 2, 20, 2) fig1, ax = pl.subplots(nrows=2, ncols=1) for i, j in enumerate([7, 1]): ax[i].plot(u[:, j] + 2 * spikes[:, j], color=col[j], zorder=5) ax[i].set_ylim(-1, 3.5) ax[i].axis('off') ax[-1].plot([0, 10 / step], [-1, -1], c='k', lw=7, clip_on=False, zorder=5) ax[-1].plot([0, 0], [1, 2], c='k', lw=7, clip_on=False, zorder=5) fig1.subplots_adjust(hspace=-.1) fig1.subplots_adjust(.04, .1, 1, 1) if savefig: pl.savefig('u.pdf', dpi=600, transparent=True) else: pl.show() # Spikes