示例#1
0
def task((repetition_i,p)):

    eps_stim = eps_stim_low+(eps_stim_high-eps_stim_low)*np.random.rand()

    learn = get_default("learn")
    learn["eta"] = [1e-7, 0.0]
    learn["eps"] = [p["eps_learn"],10**eps_stim]

    neuron = get_default("neuron")
    neuron["phi"]["alpha"] = -52.0
    neuron["phi"]["beta"] = 0.25
    neuron["phi"]["r_max"] = 0.35


    post_spikes = np.arange(40.0,2000.0,20.0)
    pre_spikes_learn = post_spikes - 10.0
    pre_spikes_stim = post_spikes - p["stim_delta"]

    my_s = {
        'start': 0.0,
        'end': 2000.0,
        'dt': 0.05,
        'pre_spikes': [pre_spikes_learn, pre_spikes_stim],
        'I_ext': lambda t: 0.0
        }

    prob = p["prob"]


    seed = int(int(time.time()*1e8)%1e9)
    accs = [PeriodicAccumulator(['weights'], interval=100)]
    accums = run(my_s, get_fixed_spiker(post_spikes), get_dendr_spike_det(p["thresh"]), accs, neuron=neuron, seed=seed, learn=learn, p_backprop=prob)


    dump((eps_stim,accums),p['ident'])
示例#2
0
def overfit((repetition_i, p)):

    neuron = get_default("neuron")
    neuron["phi"]['alpha'] = p["alpha"]
    neuron["phi"]['beta'] = p["beta"]
    neuron["phi"]['r_max'] = p["r_max"]

    learn = get_default("learn")
    learn["eta"] = 1e-7

    my_s = {
        'start': 0.0,
        'end': 4000.0,
        'dt': 0.05,
        'pre_spikes': [np.arange(50.0, 4000.0, 250.0)],
        'I_ext': lambda t: 0.0
    }

    seed = int(int(time.time() * 1e8) % 1e9)
    accs = [PeriodicAccumulator(['weights'], interval=10)]
    accums = run(my_s,
                 lambda **kwargs: False,
                 get_dendr_spike_det_dyn_ref(p["thresh"], p["tau_ref_0"],
                                             p["theta_0"]),
                 accs,
                 seed=seed,
                 neuron=neuron,
                 voltage_clamp=True,
                 U_clamp=p['Uclamp'])

    dump(accums, 'artola/' + p['ident'])
示例#3
0
def fit((repetition_i,p)):

    neuron = get_default("neuron")
    neuron["phi"]['alpha'] = p["alpha"]
    neuron["phi"]['beta'] = p["beta"]
    neuron["phi"]['r_max'] = p["r_max"]

    learn = get_default("learn")
    learn["eta"] = 4e-7

    my_s = {
        'start': 0.0,
        'end': 1000.0,
        'dt': 0.05,
        'pre_spikes': [np.arange(50.0,1000.0,250.0)],
        'I_ext': lambda t:0.0
        }

    seed = int(int(time.time()*1e8)%1e9)
    accs = [PeriodicAccumulator(['weights'], interval=10)]
    if p["h1"]:
        accums = run(my_s, lambda **kwargs:False, get_dendr_spike_det(p["thresh"]), accs, seed=seed, neuron=neuron, learn=learn, voltage_clamp=True, U_clamp=p['Uclamp'], h=1.0)
    else:
        accums = run(my_s, lambda **kwargs:False, get_dendr_spike_det(p["thresh"]), accs, seed=seed, neuron=neuron, learn=learn, voltage_clamp=True, U_clamp=p['Uclamp'])

    dump(accums,'artola/'+p['ident'])
示例#4
0
def task((repetition_i, p)):

    n_syn = p["n_syn"]

    learn = get_default("learn")
    learn["eps"] = 1e-1 / n_syn
    learn["eta"] = 1e-3 / n_syn

    neuron = get_default("neuron")
    neuron["phi"]["alpha"] = p["alpha"]
    neuron["phi"]["beta"] = p["beta"]
    neuron["phi"]["r_max"] = p["r_max"]
    neuron["g_S"] = p["g_S"]

    epochs = 4
    l_c = 6
    eval_c = 2
    cycles = epochs * l_c + (epochs + 1) * eval_c
    cycle_dur = p["cycle_dur"]
    t_end = cycles * cycle_dur

    def exc_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c:
            return 0.0
        else:
            return ((1 + np.sin(np.pi / 2 + t / t_end * cycles * 2 * np.pi)) * 2e-3 * 1 + 8e-3) * p["g_factor"]

    def inh_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c:
            return 0.0
        else:
            return 8e-2 * p["g_factor"]

    dt = 0.05
    f_r = 0.01  # 10Hz
    t_pts = np.arange(0, t_end / cycles, dt)

    poisson_spikes = [t_pts[np.random.rand(t_pts.shape[0]) < f_r * dt] for _ in range(n_syn)]
    poisson_spikes = [[] if spikes.shape[0] == 0 else np.concatenate(
        [np.arange(spike, t_end, cycle_dur) for spike in spikes]) for spikes in poisson_spikes]
    for train in poisson_spikes:
        train.sort()

    my_s = {
        'start': 0.0,
        'end': t_end,
        'dt': dt,
        'pre_spikes': poisson_spikes,
        'syn_cond_soma': {'E': exc_soma_cond, 'I': inh_soma_cond},
        'I_ext': lambda t: 0.0
    }

    seed = int(int(time.time() * 1e8) % 1e9)
    accs = [PeriodicAccumulator(get_all_save_keys(), interval=40)]
    accums = run(my_s, get_fixed_spiker(np.array([])), get_phi_U_learner(neuron, dt),
                 accs, neuron=neuron, seed=seed, learn=learn)

    dump((seed, accums), 'sine_task/' + p['ident'])
示例#5
0
def vary((repetition_i,p)):

    n_vary = 5

    values = {True: {"alpha":-55.0,
                     "beta":0.4,
                     "r_max":0.3},
              False: {"alpha":-59.0,
                      "beta":0.5,
                      "r_max":0.17}}

    vary = {"alpha":(-2.0,2.0),
              "beta":(-0.1,0.2),
              "r_max":(-0.05,0.15)}

    down = vary[p["vary"]][0]
    up = vary[p["vary"]][1]
    middle = values[p["h1"]][p["vary"]]
    vary_val = np.linspace(middle+down, middle+up, n_vary)[p["i"]]
    values[p["h1"]][p["vary"]] = vary_val
    values = values[p["h1"]]

    neuron = get_default("neuron")
    neuron["phi"]['r_max'] = values["r_max"]
    neuron["phi"]['alpha'] = values["alpha"]
    neuron["phi"]['beta'] = values["beta"]

    learn = get_default("learn")
    learn["eps"] = learn["eps"]*p["l_f"]
    learn["eta"] = learn["eta"]*p["l_f"]
    if not p["h1"]:
        learn["eta"] = learn["eta"]*2.5
    else:
        learn["eta"] = learn["eta"]*1.3


    spikes = np.array([61.0])

    my_s = {
        'start': 0.0,
        'end': 150.0,
        'dt': 0.05,
        'pre_spikes': [spikes + p["delta"]],
        'I_ext': lambda t: 0.0
        }


    seed = 1
    accs = [PeriodicAccumulator(['y','weights'], interval=10), BooleanAccumulator(['spike', 'dendr_spike', 'pre_spikes'])]
    if p["h1"]:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs, seed=seed, neuron=neuron, learn=learn, h=1.0)
    else:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs, seed=seed, neuron=neuron, learn=learn)

    dump((accums, values),'bi_poo/'+p['ident'])
示例#6
0
def fit((repetition_i, p)):

    learn = get_default("learn")
    if p["h1"]:
        learn['eta'] *= 0.125 / 8.0
    else:
        learn["eta"] *= 0.1

    neuron = get_default("neuron")
    neuron["phi"]['r_max'] = 0.2
    neuron["phi"]['alpha'] = -54.0
    neuron["phi"]['beta'] = 0.25

    p_backprop = 0.75

    freq = p["freq"]
    delta = p["delta"]

    n_spikes_in_burst = 10
    burst_pause = 200.0
    bursts = 50 / n_spikes_in_burst
    burst_dur = 1000.0 * n_spikes_in_burst / freq

    first_spike = 1000.0 / (2 * freq)
    isi = 1000.0 / freq
    t_end = bursts * (burst_dur + burst_pause)

    spikes_in_burst = np.arange(first_spike, burst_dur, isi)
    spikes = np.array([])
    for i in range(bursts):
        spikes = np.concatenate((spikes, spikes_in_burst + i * (burst_dur + burst_pause)))

    pre_spikes = spikes + delta

    my_s = {
        'start': 0.0,
        'end': t_end,
        'dt': 0.05,
        'pre_spikes': [pre_spikes],
        'I_ext': lambda t: 0.0
    }

    seed = int(int(time.time() * 1e8) % 1e9)
    accs = [PeriodicAccumulator(['weights'], interval=100)]
    if p["h1"]:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs,
                     seed=seed, learn=learn, neuron=neuron, h=1.0, p_backprop=p_backprop)
    else:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs,
                     seed=seed, learn=learn, neuron=neuron, p_backprop=p_backprop)

    dump(accums, 'sjostrom/' + p['ident'])
def vary((repetition_i,p)):
    
    etas = {True: 6e-8,
            False: 30e-8}
            
    varies = {"alpha": np.linspace(-52.0,-56.0,3),
              "beta": np.linspace(0.15,0.25,3),
              "r_max": np.linspace(0.1,0.3,3)}

    learn = get_default("learn")
    learn["eta"] = etas[p["h1"]]

    neuron = get_default("neuron")
    neuron["phi"]["alpha"] = -54.0
    neuron["phi"]["beta"] = 0.25
    neuron["phi"]["r_max"] = 0.2
    neuron["phi"][p["vary"]] = varies[p["vary"]][p["ivary"]]


    spikes = np.arange(20.0,301.0,20.0)

    my_s = {
        'start': 0.0,
        'end': 350.0,
        'dt': 0.05,
        'pre_spikes': [spikes-10.0],
        'I_ext': lambda t: 0.0
        }

    # 0.2 <= p <= 1.0
    prob = 0.2 + 0.8*np.random.rand()

    seed = int(int(time.time()*1e8)%1e9)
    accs = [PeriodicAccumulator(['weights'], interval=10)]
    if p["h1"]:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs, neuron=neuron, seed=seed, learn=learn, p_backprop=prob, h=1.0)
    else:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs, neuron=neuron, seed=seed, learn=learn, p_backprop=prob)


    dump((prob,accums),'sjostrom_switch/'+p['ident'])
示例#8
0
def fit((repetition_i,p)):

    values = {True: {"alpha":-55.0,
                     "beta":0.4,
                     "r_max":0.3},
              False: {"alpha":-59.0,
                      "beta":0.5,
                      "r_max":0.17}}

    neuron = get_default("neuron")
    neuron["phi"]['r_max'] = values[p["h1"]]["r_max"]
    neuron["phi"]['alpha'] = values[p["h1"]]["alpha"]
    neuron["phi"]['beta'] = values[p["h1"]]["beta"]

    learn = get_default("learn")
    if not p["h1"]:
        learn["eta"] = learn["eta"]*2.5
    else:
        learn["eta"] = learn["eta"]*1.3


    spikes = np.array([101.0])

    my_s = {
        'start': 0.0,
        'end': 300.0,
        'dt': 0.05,
        'pre_spikes': [spikes + p["delta"]],
        'I_ext': lambda t: 0.0
        }


    seed = 1
    accs = [PeriodicAccumulator(['y','weights'], interval=10), BooleanAccumulator(['spike', 'dendr_spike', 'pre_spikes'])]
    if p["h1"]:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs, seed=seed, neuron=neuron, learn=learn, h=1.0)
    else:
        accums = run(my_s, get_fixed_spiker(spikes), get_dendr_spike_det(-50.0), accs, seed=seed, neuron=neuron, learn=learn)

    dump((accums, values),'bi_poo/'+p['ident'])
def task((repetition_i, p)):

    eps_stim = eps_stim_low + (eps_stim_high - eps_stim_low) * np.random.rand()

    learn = get_default("learn")
    learn["eta"] = [1e-7, 0.0]
    learn["eps"] = [p["eps_learn"], 10**eps_stim]

    neuron = get_default("neuron")
    neuron["phi"]["alpha"] = -52.0
    neuron["phi"]["beta"] = 0.25
    neuron["phi"]["r_max"] = 0.35

    post_spikes = np.arange(40.0, 2000.0, 20.0)
    pre_spikes_learn = post_spikes - 10.0
    pre_spikes_stim = post_spikes - p["stim_delta"]

    my_s = {
        'start': 0.0,
        'end': 2000.0,
        'dt': 0.05,
        'pre_spikes': [pre_spikes_learn, pre_spikes_stim],
        'I_ext': lambda t: 0.0
    }

    prob = p["prob"]

    seed = int(int(time.time() * 1e8) % 1e9)
    accs = [PeriodicAccumulator(['weights'], interval=100)]
    accums = run(my_s,
                 get_fixed_spiker(post_spikes),
                 get_dendr_spike_det(p["thresh"]),
                 accs,
                 neuron=neuron,
                 seed=seed,
                 learn=learn,
                 p_backprop=prob)

    dump((eps_stim, accums), p['ident'])
示例#10
0

def getWordEmbeddingDict(vocabSize = 10000):

	word_vec_dict = collections.defaultdict(int)

	with open("../../data/glove.42B.300d/glove.42B.300d.txt", 'r') as file:

		progress = 0
		for lineNum in range(vocabSize):

			# prints progress updates
			progress += 1
			if progress >= vocabSize/10:
				print("10% complete")
				progress = 0

			line = file.readline()
			lineList = [i for i in line.split()]

			key = lineList[0]
			val = [float(i) for i in lineList[1:]]
			word_vec_dict[key] = val

	return word_vec_dict 

# -------------------------------------------------------

word_vec_dict = getWordEmbeddingDict(100000)
helper.dump("embeddings_100k.pkl", word_vec_dict)
示例#11
0
def task(inputs):
    repetition_i = inputs[0]
    p = inputs[1]

    n_syn = p["n_syn"]

    learn = get_default("learn")
    learn["eps"] = 1e-1 / n_syn
    learn["eta"] = 1e-3 / n_syn

    neuron = get_default("neuron")

    neuron["phi"]["alpha"] = p["alpha"]
    neuron["phi"]["beta"] = p["beta"]
    neuron["phi"]["r_max"] = p["r_max"]
    neuron["g_S"] = p["g_S"]

    epochs = 4
    l_c = 6
    eval_c = 2
    cycles = epochs * l_c + (epochs + 1) * eval_c
    cycle_dur = p["cycle_dur"]
    t_end = cycles * cycle_dur

    def exc_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c:
            return 0.0
        else:
            return ((1 + np.sin(np.pi / 2 + t / t_end * cycles * 2 * np.pi)) \
                    * 2e-3 * 1 + 8e-3) * p["g_factor"]

    def inh_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c:
            return 0.0
        else:
            return 8e-2 * p["g_factor"]

    dt = 0.05
    f_r = 0.01  # 10Hz
    t_pts = np.arange(0, t_end / cycles, dt)

    poisson_spikes = [
        t_pts[np.random.rand(t_pts.shape[0]) < f_r * dt] for _ in range(n_syn)
    ]
    poisson_spikes = [[] if spikes.shape[0] == 0 else np.concatenate(
        [np.arange(spike, t_end, cycle_dur) for spike in spikes])
                      for spikes in poisson_spikes]

    for train in poisson_spikes:
        train.sort()

    my_s = {
        'start': 0.0,
        'end': t_end,
        'dt': dt,
        'pre_spikes': poisson_spikes,
        'syn_cond_soma': {
            'E': exc_soma_cond,
            'I': inh_soma_cond
        },
        'I_ext': lambda t: 0.0
    }

    seed = int(int(time.time() * 1e8) % 1e9)
    accs = [PeriodicAccumulator(get_all_save_keys(), interval=40)]

    accums = run(my_s,
                 get_fixed_spiker(np.array([])),
                 get_phi_U_learner(neuron, dt),
                 accs,
                 neuron=neuron,
                 seed=seed,
                 learn=learn)
    # TODO: create directrory if not exists
    dump((seed, accums), "results/" + p['ident'])
	if k % 10 != 0: continue
	
	helper.progressUpdate(k, len(dataset), 100)

	# returns a 320 dimension feature vector (300 features form GloVe + 20 features from Naive Bayes)
	commentVec = helper.getCommentVec(dataset[k], wordToVec, wordProbByClass)
	commentVec = array(commentVec)

	# X = [commentVec] if len(X) == 0 else numpy.concatenate((X, [commentVec]))
	# y = numpy.append(y, dataset[k][-1])

	X.append(commentVec)
	y.append(dataset[k][-1])

print("X and y created")

print(X[0])
print(len(X[0]))
print(len(X))
print(len(y))

X = array(X)
y = array(y)

print(X)

helper.dump('X_mid+20.pkl', X)
helper.dump('y_mid+20.pkl', y)


示例#13
0
 def fetch_partition(self, uuid):
     if uuid not in self.partitions:
         print 'Missing partition', uuid, self.partitions
         return None
     print 'return result:' + uuid
     return dump(self.partitions[uuid].result)
示例#14
0
def task((repetition_i, p)):

    n_syn = p["n_syn"]

    learn = get_default("learn")
    learn["eps"] = 1e-1 / (1.0 * n_syn)
    learn["eta"] = learn["eps"]*p["eps_factor"]

    neuron = get_default("neuron")
    neuron["phi"]["alpha"] = p["alpha"]
    neuron["phi"]["beta"] = p["beta"]
    neuron["phi"]["r_max"] = 0.1
    neuron["g_S"] = p["g_S"]

    learn_epochs = 20
    test_epochs = 20
    epochs = learn_epochs + test_epochs
    l_c = 8
    eval_c = 2
    cycles = epochs * l_c + (epochs + 1) * eval_c
    cycle_dur = 100.0
    epoch_dur = (l_c + eval_c) * cycle_dur
    t_end = cycles * cycle_dur

    exc_level = p["exc_level"]
    g_factor = 50

    def exc_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c or t > learn_epochs*epoch_dur:
            return 0.0
        else:
            return ((1 + np.sin(-np.pi/2 + t / t_end * cycles * 2 * np.pi)) * exc_level + exc_level) * g_factor

    def inh_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c or t > learn_epochs*epoch_dur:
            return 0.0
        else:
            return 4e-2 * g_factor

    dt = 0.05
    f_r = 0.01 # 10Hz
    t_pts = np.arange(0, t_end / cycles, dt)

    seed = int(int(time.time() * 1e8) % 1e9)
    poisson_spikes = [t_pts[np.random.rand(t_pts.shape[0]) < f_r * dt] for _ in range(n_syn)]
    poisson_spikes = [[] if spikes.shape[0] == 0 else np.concatenate(
        [np.arange(spike, t_end, cycle_dur) for spike in spikes]) for spikes in poisson_spikes]
    for train in poisson_spikes:
        train.sort()

    my_s = {
        'start': 0.0,
        'end': t_end,
        'dt': dt,
        'pre_spikes': poisson_spikes,
        'syn_cond_soma': {'E': exc_soma_cond, 'I': inh_soma_cond},
        'I_ext': lambda t: 0.0
    }

    phi_spiker = get_phi_spiker(neuron)

    # deprecated
    def my_spiker(curr, dt, **kwargs):
        # we want no spikes in eval cycles
        if curr['t'] % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c:
            return False
        else:
            return phi_spiker(curr, dt, **kwargs)

    accs = [PeriodicAccumulator(get_all_save_keys(), interval=20, y_keep = 3), BooleanAccumulator(['spike'])]
    accums = run(my_s, phi_spiker, get_inst_backprop(),
                 accs, neuron=neuron, seed=seed, learn=learn)

    dump((seed, accums), 'sine_task_backprop/' + p['ident'])
示例#15
0
def task((repetition_i, p)):

    n_syn = p["n_syn"]

    learn = get_default("learn")
    learn["eps"] = 1e-1 / (1.0 * n_syn)
    learn["eta"] = learn["eps"] * p["eps_factor"]

    neuron = get_default("neuron")
    neuron["phi"]["alpha"] = p["alpha"]
    neuron["phi"]["beta"] = p["beta"]
    neuron["phi"]["r_max"] = 0.1
    neuron["g_S"] = p["g_S"]

    learn_epochs = 2
    test_epochs = 1
    epochs = learn_epochs + test_epochs
    l_c = 4
    eval_c = 2
    cycles = epochs * l_c + (epochs + 1) * eval_c
    cycle_dur = p["cycle_dur"]
    epoch_dur = (l_c + eval_c) * cycle_dur
    t_end = cycles * cycle_dur

    g_factor = p["g_factor"]

    def exc_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c or t > learn_epochs * epoch_dur:
            return 0.0
        return p["exc_level"] * p["g_factor"]

    def inh_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c or t > learn_epochs * epoch_dur:
            return 0.0
        return 1e-1 * p["g_factor"]

    dt = 0.05
    f_r = 1.0 / cycle_dur
    t_pts = np.arange(0, t_end / cycles, dt)

    seed = int(int(time.time() * 1e8) % 1e9)

    reg_spikes = [np.arange(i+1,t_end+1,10) for i in range(n_syn)]

    poisson_spikes = [t_pts[np.random.rand(t_pts.shape[0]) < f_r * dt] for _ in range(n_syn)]
    poisson_spikes = [[] if spikes.shape[0] == 0 else np.concatenate(
        [np.arange(spike, t_end, cycle_dur) for spike in spikes]) for spikes in poisson_spikes]
    for train in poisson_spikes:
        train.sort()

    my_s = {
        'start': 0.0,
        'end': t_end,
        'dt': dt,
        'pre_spikes': reg_spikes,
        'syn_cond_soma': {'E': exc_soma_cond, 'I': inh_soma_cond},
        'I_ext': lambda t: 0.0
    }

    phi_spiker = get_phi_spiker(neuron)

    # deprecated
    def my_spiker(curr, dt, **kwargs):
        # we want no spikes in eval cycles
        if curr['t'] % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c:
            return False
        else:
            return phi_spiker(curr, dt, **kwargs)

    if p["wiggle"] is None:
        dendr_predictor = phi
    else:
        us = np.linspace(-100,20,1000)
        ampl = neuron["phi"]["r_max"]
        phis = phi(us, neuron)
        alphas = []
        for i in range(p["wiggle"]):
            alphas.append(us[phis > (i+0.5)*ampl/p["wiggle"]][0])
        r_m = neuron['phi']['r_max']/p["wiggle"]
        def dendr_predictor(V, neuron):
            return np.sum([phi(V,{'phi':{'alpha': al, 'beta':p["beta_wiggle"], 'r_max': r_m}}) for al in alphas])


    accs = [PeriodicAccumulator(get_all_save_keys(), interval=20,
                                y_keep=3), BooleanAccumulator(['spike'])]
    accums = run(my_s, get_fixed_spiker(np.array([])), get_phi_U_learner(neuron, dt, p["exc_decrease"]),
                 accs, neuron=neuron, seed=seed, learn=learn, dendr_predictor=dendr_predictor)

    dump((seed, accums), 'wiggle_test/' + p['ident'])
示例#16
0
def task((repetition_i, p)):

    n_syn = p["n_syn"]

    learn = get_default("learn")
    learn["eps"] = 1e-1 / (1.0 * n_syn)
    learn["eta"] = learn["eps"] * p["eps_factor"]

    neuron = get_default("neuron")
    neuron["phi"]["alpha"] = p["alpha"]
    neuron["phi"]["beta"] = p["beta"]
    neuron["phi"]["r_max"] = 0.1
    neuron["g_S"] = p["g_S"]

    learn_epochs = 20
    test_epochs = 20
    epochs = learn_epochs + test_epochs
    l_c = 8
    eval_c = 2
    cycles = epochs * l_c + (epochs + 1) * eval_c
    cycle_dur = 100.0
    epoch_dur = (l_c + eval_c) * cycle_dur
    t_end = cycles * cycle_dur

    exc_level = p["exc_level"]
    g_factor = 50

    def exc_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)
                ) < cycle_dur * eval_c or t > learn_epochs * epoch_dur:
            return 0.0
        else:
            return ((1 + np.sin(-np.pi / 2 + t / t_end * cycles * 2 * np.pi)) *
                    exc_level + exc_level) * g_factor

    def inh_soma_cond(t):
        if t % (cycle_dur * (l_c + eval_c)
                ) < cycle_dur * eval_c or t > learn_epochs * epoch_dur:
            return 0.0
        else:
            return 4e-2 * g_factor

    dt = 0.05
    f_r = 0.01  # 10Hz
    t_pts = np.arange(0, t_end / cycles, dt)

    seed = int(int(time.time() * 1e8) % 1e9)
    poisson_spikes = [
        t_pts[np.random.rand(t_pts.shape[0]) < f_r * dt] for _ in range(n_syn)
    ]
    poisson_spikes = [[] if spikes.shape[0] == 0 else np.concatenate(
        [np.arange(spike, t_end, cycle_dur) for spike in spikes])
                      for spikes in poisson_spikes]
    for train in poisson_spikes:
        train.sort()

    my_s = {
        'start': 0.0,
        'end': t_end,
        'dt': dt,
        'pre_spikes': poisson_spikes,
        'syn_cond_soma': {
            'E': exc_soma_cond,
            'I': inh_soma_cond
        },
        'I_ext': lambda t: 0.0
    }

    phi_spiker = get_phi_spiker(neuron)

    # deprecated
    def my_spiker(curr, dt, **kwargs):
        # we want no spikes in eval cycles
        if curr['t'] % (cycle_dur * (l_c + eval_c)) < cycle_dur * eval_c:
            return False
        else:
            return phi_spiker(curr, dt, **kwargs)

    accs = [
        PeriodicAccumulator(get_all_save_keys(), interval=20, y_keep=3),
        BooleanAccumulator(['spike'])
    ]
    accums = run(my_s,
                 phi_spiker,
                 get_inst_backprop(),
                 accs,
                 neuron=neuron,
                 seed=seed,
                 learn=learn)

    dump((seed, accums), 'sine_task_backprop/' + p['ident'])
示例#17
0
def fit((repetition_i, p)):

    learn = get_default("learn")
    if p["h1"]:
        learn['eta'] *= 0.125 / 8.0
    else:
        learn["eta"] *= 0.1

    neuron = get_default("neuron")
    neuron["phi"]['r_max'] = 0.2
    neuron["phi"]['alpha'] = -54.0
    neuron["phi"]['beta'] = 0.25

    p_backprop = 0.75

    freq = p["freq"]
    delta = p["delta"]

    n_spikes_in_burst = 10
    burst_pause = 200.0
    bursts = 50 / n_spikes_in_burst
    burst_dur = 1000.0 * n_spikes_in_burst / freq

    first_spike = 1000.0 / (2 * freq)
    isi = 1000.0 / freq
    t_end = bursts * (burst_dur + burst_pause)

    spikes_in_burst = np.arange(first_spike, burst_dur, isi)
    spikes = np.array([])
    for i in range(bursts):
        spikes = np.concatenate(
            (spikes, spikes_in_burst + i * (burst_dur + burst_pause)))

    pre_spikes = spikes + delta

    my_s = {
        'start': 0.0,
        'end': t_end,
        'dt': 0.05,
        'pre_spikes': [pre_spikes],
        'I_ext': lambda t: 0.0
    }

    seed = int(int(time.time() * 1e8) % 1e9)
    accs = [PeriodicAccumulator(['weights'], interval=100)]
    if p["h1"]:
        accums = run(my_s,
                     get_fixed_spiker(spikes),
                     get_dendr_spike_det(-50.0),
                     accs,
                     seed=seed,
                     learn=learn,
                     neuron=neuron,
                     h=1.0,
                     p_backprop=p_backprop)
    else:
        accums = run(my_s,
                     get_fixed_spiker(spikes),
                     get_dendr_spike_det(-50.0),
                     accs,
                     seed=seed,
                     learn=learn,
                     neuron=neuron,
                     p_backprop=p_backprop)

    dump(accums, 'sjostrom/' + p['ident'])
示例#18
0
 def dump(self):
     return dump(self)
示例#19
0
 def __init__(self, part_id=None, func=None):
     self.part_id = part_id
     self.uuid = str(hash(dump(func))) + ":" + str(part_id)
     self.func = func
     self.evaluated = False
     self.parent_list = []