Exemple #1
0
    def test_give_train(self):
        t, i = datas.give_train(dt=0.2, nb_neuron_zero=None, max_t=1200.)
        self.assertEqual(t[-1], 1200. - 0.2)
        self.assertEqual(t[1] - t[0], 0.2)
        self.assertEqual(i.shape[0], 1200. / 0.2)
        self.assertEqual(i.ndim, 2)

        t, i = datas.give_train(dt=0.5, nb_neuron_zero=3, max_t=800.)
        self.assertEqual(t[-1], 800. - 0.5)
        self.assertEqual(t[1] - t[0], 0.5)
        self.assertEqual(i.shape[0], 800. / 0.5)
        self.assertEqual(i.shape[2], 4)
        self.assertEqual(i.ndim, 3)
Exemple #2
0
def with_LSTM():
    dir = utils.set_dir('withLSTM')
    conns = {(0, 1): circuit.SYNAPSE}
    conns_opt = {(0, 1): circuit.get_syn_rand(True)}

    dt = 0.5
    t, i = datas.give_train(dt=dt)
    i_1 = np.zeros(i.shape)
    i_injs = np.stack([i, i_1], axis=2)
    train = sim.simul(t, i_injs, [p, p], conns, n_out=[0, 1], show=False)

    neurons = nr.Neurons([nr.BioNeuronTf(PyBioNeuron.get_random(), fixed=[], dt=dt), nr.BioNeuronTf(p, fixed='all', dt=dt)])
    c = CircuitTf(neurons=neurons, synapses=conns_opt)
    co = CircuitOpt(circuit=c)
    co.optimize(dir, train=train, n_out=[0, 1], l_rate=(0.01, 9, 0.95))
Exemple #3
0
class TestNeuronSimul(TestCase):

    pars = PyBioNeuron.default_params
    pars5 = [PyBioNeuron.default_params for _ in range(5)]
    dt = 0.5
    t, i = datas.give_train(dt=dt, max_t=5.)
    i = i[:, 4]

    def test_comp(self):
        sim.comp_pars(self.pars5, dt=self.dt, i_inj=self.i, show=False)
        sim.comp_pars(self.pars5, t=self.t, i_inj=self.i, show=False)

    def test_comp_targ(self):
        sim.comp_pars_targ(self.pars5,
                           self.pars,
                           dt=self.dt,
                           i_inj=self.i,
                           show=False)
        sim.comp_pars_targ(self.pars,
                           self.pars,
                           t=self.t,
                           i_inj=self.i,
                           show=False)

    def test_comp_neurons(self):
        sim.comp_neurons([PyBioNeuron(self.pars) for _ in range(3)],
                         i_inj=self.i,
                         show=False)

    def test_comp_neur_trqce(self):
        sim.comp_neuron_trace(PyBioNeuron(self.pars),
                              i_inj=self.i,
                              trace=np.zeros(
                                  (len(PyBioNeuron.default_init_state),
                                   len(self.i))),
                              show=False)
        sim.comp_neuron_trace(PyBioNeuron(self.pars),
                              i_inj=self.i,
                              scale=True,
                              trace=np.zeros(
                                  (len(PyBioNeuron.default_init_state),
                                   len(self.i))),
                              show=False)

    def test_Sim(self):
        nfix = PyBioNeuron(self.pars)
        sim.simul(neuron=nfix, dt=self.dt, i_inj=self.i)
Exemple #4
0
from unittest import TestCase
from odynn import utils, datas
from odynn.neuron import NeuronLSTM, BioNeuronTf, PyBioNeuron
from odynn.noptim import NeuronOpt
from odynn.nsimul import simul
from odynn import optim
import tensorflow as tf
import numpy as np

dir = utils.set_dir('unittest')
dt = 0.5
t, i = datas.give_train(dt=dt, max_t=5.)
default = PyBioNeuron.default_params
pars = PyBioNeuron.get_random()
train = simul(p=default, dt=dt, i_inj=i, show=False, suffix='train')
plot = False
nr = BioNeuronTf(init_p=pars, dt=dt)


class TestNeuronOpt(TestCase):
    def test_init(self):
        with self.assertRaises(TypeError):
            no = NeuronOpt(5)

    def test_loss(self):
        co = NeuronOpt(nr)
        res = tf.zeros((len(t), len(PyBioNeuron.default_init_state), 3))
        ys_ = [
            tf.placeholder(shape=(len(t), 3), dtype=tf.float32, name="test")
        ] + [
            tf.placeholder(shape=(len(t), 3), dtype=tf.float32, name="test")
Exemple #5
0
        dir = '2n-1inh-test'
    elif(xp == '22exc'):
        n_neuron = 2
        conns = {(0,1):circuit.SYNAPSE,
                 (1,0):circuit.SYNAPSE}
        conns_opt = [{(0,1):circuit.get_syn_rand(True),
                      (1,0):circuit.get_syn_rand(True)} for _ in range(100)]
        dir = '2n-2exc-test'
    elif(xp == '21exc1inh'):
        n_neuron = 2
        conns = {(0, 1):circuit.SYNAPSE,
                 (1, 0):circuit.SYNAPSE_inhib}
        conns_opt = {(0, 1):circuit.get_syn_rand(True),
                     (1, 0):circuit.get_syn_rand(False)}
        dir = '2n-1exc1inh-test'
    elif (xp == '22inh'):
        n_neuron = 2
        conns = {(0, 1):circuit.SYNAPSE_inhib,
                 (1, 0):circuit.SYNAPSE_inhib}
        conns_opt = {(0, 1):circuit.get_syn_rand(False),
                     (1, 0):circuit.get_syn_rand(False)}
        dir = '2n-2inh-test'
    elif xp == '41':
        full4to1()
    elif xp=='441':
        full441()
    t, i =datas.give_train(dt=0.5)
    i_1 = np.zeros(i.shape)
    i_injs = np.stack([i, i_1], axis=2)
    test(n_neuron, conns, conns_opt, dir, t, i_injs)