예제 #1
0
 def test_simul(self):
     syns = {(0, 1): circuit.SYNAPSE, (1, 2): circuit.SYNAPSE}
     gaps = {(2, 1): circuit.GAP}
     t = [0., 0.1, 0.2, 0.3]
     i = np.ones((4, 3))
     p = [neuron.PyBioNeuron.default_params for _ in range(3)]
     csimul.simul(t, i, p, syns, gaps)
예제 #2
0
def dual():
    inhib =circuit.SYNAPSE_inhib
    connections = {(1,0) : circuit.SYNAPSE2, (0,1) : inhib}
    t = np.array(sp.arange(0.0, 2500.,datas.DT))
    i0 = 10.*((t>300)&(t<350)) + 20.*((t>900)&(t<950))
    i1 = 10.*((t>500)&(t<550)) + 20.*((t>700)&(t<750)) + 14*((t>1100)&(t<1800))+ 22*((t>1900)&(t<2000))
    i_injs = np.array([i0, i1]).transpose()
    sim.simul(t, i_injs, [p, p], connections, show=True, save=False)
예제 #3
0
파일: tapwith.py 프로젝트: lungd/ODYNN-1
def run():
    name = sys.argv[1]

    # plt.rcParams['figure.facecolor'] = 'Indigo'

    # c = circuit.CircuitFix([p for _ in range(9)], synapses=syns, gaps=gaps, labels=labels)
    # c.plot()

    t, i = datas.full4(dt=dt, nb_neuron_zero=5)
    i[:, :, :] = i[:, :, [0, 1, 4, 5, 6, 7, 8, 2, 3]]
    _, itest = datas.full4_test(dt=dt, nb_neuron_zero=5)
    itest[:, :, :] = itest[:, :, [0, 1, 4, 5, 6, 7, 8, 2, 3]]

    dir = utils.set_dir('Tapwith_' + name)
    n_out = [4, 5]
    train = sim.simul(pars=[p for _ in range(9)],
                      t=t,
                      i_injs=i,
                      synapses=syns,
                      gaps=gaps,
                      n_out=n_out,
                      suffix='train',
                      labels=labels)
    test = sim.simul(pars=[p for _ in range(9)],
                     t=t,
                     i_injs=itest,
                     synapses=syns,
                     gaps=gaps,
                     n_out=n_out,
                     labels=labels,
                     suffix='test')

    # n = nr.BioNeuronTf([rand() for _ in range(9)], dt=dt)
    n = nr.Neurons([
        nr.NeuronLSTM(dt=dt),
        nr.NeuronLSTM(dt=dt),
        nr.BioNeuronTf([p for _ in range(5)], dt=dt),
        nr.NeuronLSTM(dt=dt),
        nr.NeuronLSTM(dt=dt)
    ])
    ctf = CircuitTf(n,
                    synapses=syns_opt[0],
                    gaps=gaps_opt[0],
                    labels=labels,
                    commands={4, 5},
                    sensors={0, 1, 7, 8})
    ctf.plot(save=True)
    exit()
    # ctf = CircuitTf.create_random(neurons = n, n_neuron=9, dt=dt, syn_keys={k: v['E']>-60 for k,v in syns.items()}, gap_keys=gaps.keys(), labels=labels, commands={4, 5},
    #                 sensors={0, 1, 7, 8}, n_rand=n_parallel)
    copt = CircuitOpt(circuit=ctf)
    copt.optimize(subdir=dir,
                  train=train,
                  test=test,
                  n_out=[4, 5],
                  l_rate=(0.1, 9, 0.95))
예제 #4
0
def opt_neurons():
    connections = {(0, 1):circuit.SYNAPSE_inhib,
                   (1, 0):circuit.SYNAPSE}
    t = np.array(sp.arange(0.0, 1000.,datas.DT))
    i0 = 10. * ((t > 200) & (t < 400)) + 30. * ((t > 500) & (t < 600))
    i1 = 30. * ((t > 700) & (t < 800))
    i_injs = np.array([i0, i1]).transpose()
    f = sim.simul(t, i_injs, [p, p], connections, dump=True)
    c = CircuitOpt([p, p], connections)
    c.opt_neurons(f)
예제 #5
0
파일: tapwith.py 프로젝트: lungd/ODYNN-1
def analyse(dir):
    from odynn import optim
    import pandas as pd
    import seaborn as sns
    import pylab as plt
    dir = utils.set_dir(dir)
    dic = optim.get_vars(dir, loss=True)

    train, test = optim.get_data(dir)
    df = pd.DataFrame.from_dict({'loss': dic['loss']})  # .head(4)
    df = df.sort_values('loss').reset_index(drop=True)
    # df = df.dropna()
    sns.barplot(x=df.index, y='loss', data=df)
    plt.show()

    dic = optim.get_best_result(dir)
    ctf = optim.get_model(dir)
    ctf.plot(save=True)
    ctf.init_params = dic
    sim.simul(t=train[0], i_injs=train[1], circuit=ctf, show=True, save=True)
    sim.simul(t=test[0], i_injs=test[1], circuit=ctf, show=True, save=True)
예제 #6
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))
예제 #7
0
    def test_opt_circuits(self):
        print('one target'.center(40, '#'))
        n_out = [1]
        train = csim.simul(t=t,
                           i_injs=i_injs,
                           pars=pars,
                           synapses=conns,
                           n_out=n_out,
                           show=False)
        co = CircuitOpt(
            cr.CircuitTf(nr.BioNeuronTf(pars, dt=dt), synapses=conns_opt))
        co.optimize(dir, n_out=n_out, train=train, epochs=1, plot=plot)
        optim.get_best_result(dir)

        self.assertEqual(co._loss.shape, ())

        print('one target parallel'.center(40, '#'))
        co = CircuitOpt(
            cr.CircuitTf(nr.BioNeuronTf(n_rand=n_neuron, dt=dt),
                         synapses=conns_opt_parallel))
        co.optimize(dir,
                    n_out=n_out,
                    train=train,
                    test=train,
                    epochs=1,
                    plot=plot,
                    evol_var=evol_var)
        self.assertEqual(co._loss.shape, (10, ))

        print('several targets'.center(40, '#'))
        n_out = [0, 1]
        train = csim.simul(t=t,
                           i_injs=i_injs,
                           pars=pars,
                           synapses=conns,
                           n_out=n_out,
                           show=False)
        co = CircuitOpt(
            cr.CircuitTf(nr.BioNeuronTf(pars, dt=dt), synapses=conns_opt))
        co.optimize(dir,
                    n_out=n_out,
                    train=train,
                    epochs=1,
                    w_n=(1, 2),
                    plot=plot,
                    evol_var=evol_var)
        self.assertEqual(co._loss.shape, ())

        print('several targets parallel'.center(40, '#'))
        co = CircuitOpt(
            cr.CircuitTf.create_random(
                n_neuron=2, syn_keys={k: False
                                      for k in conns.keys()}, dt=dt))
        co.optimize(dir,
                    n_out=n_out,
                    train=train,
                    epochs=1,
                    w_n=(1., 0.2),
                    plot=plot,
                    evol_var=evol_var)
        self.assertEqual(co._loss.shape, (10, ))

        print('1 LSTM'.center(40, '#'))
        neurons = nr.Neurons(
            [nr.NeuronLSTM(dt=dt),
             nr.BioNeuronTf(p, fixed='all', dt=dt)])
        c = cr.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),
                    epochs=1,
                    plot=plot,
                    evol_var=evol_var)

        print('2 LSTM'.center(40, '#'))
        neurons = nr.Neurons([nr.NeuronLSTM(dt=dt), nr.NeuronLSTM(dt=dt)])
        c = cr.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),
                    epochs=1,
                    plot=plot,
                    evol_var=evol_var)

        conns_opt[(0, 2)] = odynn.circuit.get_syn_rand()
        with self.assertRaises(AttributeError):
            c = cr.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),
                        epochs=1,
                        plot=plot,
                        evol_var=evol_var)

        print('2 bio + 1 LSTM'.center(40, '#'))
        neurons = nr.Neurons([
            nr.BioNeuronTf(init_p=[p for _ in range(2)], dt=dt),
            nr.NeuronLSTM(dt=dt)
        ])
        c = cr.CircuitTf(neurons=neurons, synapses=conns_opt)
        co = CircuitOpt(circuit=c)
        train[1] = i_injs3
        co.optimize(dir,
                    train=train,
                    n_out=[0, 1],
                    l_rate=(0.01, 9, 0.95),
                    epochs=1,
                    plot=plot,
                    evol_var=evol_var)