예제 #1
0
파일: test_cnet.py 프로젝트: unibe-cns/NEAT
    def createPointNeurons(self, v_eq=-75.):
        self.v_eq = v_eq
        self.dt = .025
        gh, eh = 50., -43.
        h_chan = channelcollection.h()

        self.greens_tree = GreensTree(
            file_n=os.path.join(MORPHOLOGIES_PATH_PREFIX, 'ball.swc'))
        self.greens_tree.setPhysiology(1., 100. / 1e6)
        self.greens_tree.addCurrent(h_chan, gh, eh)
        self.greens_tree.fitLeakCurrent(v_eq, 10.)
        self.greens_tree.setEEq(v_eq)
        self.greens_tree_pas = self.greens_tree.__copy__(new_tree=GreensTree())
        self.greens_tree_pas.asPassiveMembrane()
        self.sim_tree = self.greens_tree.__copy__(new_tree=NeuronSimTree())
        # set the impedances
        self.greens_tree_pas.setCompTree()
        self.freqs = np.array([0.])
        self.greens_tree_pas.setImpedance(self.freqs)
        # create sov tree
        self.sov_tree = self.greens_tree_pas.__copy__(new_tree=SOVTree())
        self.sov_tree.calcSOVEquations(maxspace_freq=50.)

        z_inp = self.greens_tree_pas.calcZF((1, .5), (1, .5))[0]
        alphas, gammas = self.sov_tree.getSOVMatrices(locarg=[(1., .5)])
        # create NET
        node_0 = NETNode(0, [0], [0], z_kernel=(alphas, gammas[:, 0]**2))
        net_py = NET()
        net_py.setRoot(node_0)
        # check if correct
        assert np.abs(gammas[0, 0]**2 / np.abs(alphas[0]) - z_inp) < 1e-10
        assert np.abs(node_0.z_bar - z_inp) < 1e-10

        # to initialize neuron tree
        self.sim_tree.initModel(dt=self.dt)
        # add ion channel to NET simulator
        a_soma = 4. * np.pi * (self.sim_tree[1].R * 1e-4)**2
        self.cnet = netsim.NETSim(net_py, v_eq=self.v_eq)

        hchan = channelcollection.h()
        self.cnet.addChannel(hchan, 0, gh * a_soma, eh)

        # add the synapse
        # to neuron tree
        self.sim_tree.addDoubleExpSynapse((1, .5), .2, 3., 0.)
        self.sim_tree.setSpikeTrain(0, 0.001, [5.])
        # to net sim
        self.cnet.addSynapse(0, {
            'tau_r': .2,
            'tau_d': 3.,
            'e_r': 0.
        },
                             g_max=0.001)
        self.cnet.setSpikeTimes(0, [5. + self.dt])
예제 #2
0
파일: test_cnet.py 프로젝트: unibe-cns/NEAT
    def createTree(self, reinitialize=1, v_eq=-75.):
        """
        Create simple NET structure

        2     3
        |     |
        |     |
        ---1---
           |
           |
           0
           |
        """
        self.v_eq = v_eq
        loc_ind = np.array([0, 1, 2])

        # kernel constants
        alphas = 1. / np.array([.5, 8.])
        gammas = np.array([-1., 1.])
        alphas_ = 1. / np.array([1.])
        gammas_ = np.array([1.])
        # nodes
        node_0 = NETNode(0, [0, 1, 2], [], z_kernel=(alphas, gammas))
        node_1 = NETNode(1, [0, 1, 2], [0], z_kernel=(alphas_, gammas_))
        node_2 = NETNode(2, [1], [1], z_kernel=(alphas_, gammas_))
        node_3 = NETNode(3, [2], [2], z_kernel=(alphas_, gammas_))
        # add nodes to tree
        net_py = NET()
        net_py.setRoot(node_0)
        net_py.addNodeWithParent(node_1, node_0)
        net_py.addNodeWithParent(node_2, node_1)
        net_py.addNodeWithParent(node_3, node_1)
        # store
        self.net_py = net_py
        self.cnet = netsim.NETSim(net_py, v_eq=self.v_eq)
예제 #3
0
파일: test_cnet.py 프로젝트: unibe-cns/NEAT
    def createTree3(self, reinitialize=1, add_lin=True, v_eq=-75.):
        """
        Create simple NET structure

                         6
                4     5  |
                |     |  |
                |     |  |
             2  ---3---  |
             |     |     |
             ---1---     |
                   |     |
                   0------
                   |
        """
        self.v_eq = v_eq

        # kernel constants
        alphas = 1. / np.array([1.])
        gammas = np.array([1.])
        # nodes
        node_0 = NETNode(0, [0, 1, 2, 3], [], z_kernel=(alphas, gammas))
        node_1 = NETNode(1, [0, 1, 2], [], z_kernel=(alphas, gammas))
        node_2 = NETNode(2, [0], [0], z_kernel=(alphas, gammas))
        node_3 = NETNode(3, [1, 2], [], z_kernel=(alphas, gammas))
        node_4 = NETNode(4, [1], [1], z_kernel=(alphas, gammas))
        node_5 = NETNode(5, [2], [2], z_kernel=(alphas, gammas))
        node_6 = NETNode(6, [3], [3], z_kernel=(alphas, gammas))
        # add nodes to tree
        net_py = NET()
        net_py.setRoot(node_0)
        net_py.addNodeWithParent(node_1, node_0)
        net_py.addNodeWithParent(node_2, node_1)
        net_py.addNodeWithParent(node_3, node_1)
        net_py.addNodeWithParent(node_4, node_3)
        net_py.addNodeWithParent(node_5, node_3)
        net_py.addNodeWithParent(node_6, node_0)
        # linear terms
        alphas = 1. / np.array([1.])
        gammas = np.array([1.])
        self.lin_terms = {
            1: Kernel((alphas, gammas)),
            2: Kernel((alphas, gammas)),
            3: Kernel((alphas, gammas))
        } if add_lin else {}
        # store
        self.net_py = net_py
        self.cnet = netsim.NETSim(net_py, lin_terms=self.lin_terms)
예제 #4
0
 def loadTree(self, reinitialize=0):
     if not hasattr(self, 'net') or reinitialize:
         alphas = np.array([1.]); gammas = np.array([1.])
         # define nodes
         node_r  = NETNode(0, [0,1,2,3,4,5], [],  z_kernel=(alphas, gammas))
         node_s  = NETNode(1, [0],           [0], z_kernel=(alphas, gammas))
         node_b1 = NETNode(2, [1,2,3,4,5],   [1], z_kernel=(alphas, gammas))
         node_b2 = NETNode(3, [2,3,4],       [2], z_kernel=(alphas, gammas))
         node_l3 = NETNode(4, [3],           [3], z_kernel=(alphas, gammas))
         node_l4 = NETNode(5, [4],           [4], z_kernel=(alphas, gammas))
         node_l5 = NETNode(6, [5],           [5], z_kernel=(alphas, gammas))
         # add nodes to tree
         self.net = NET()
         self.net.setRoot(node_r)
         self.net.addNodeWithParent(node_s, node_r)
         self.net.addNodeWithParent(node_b1, node_r)
         self.net.addNodeWithParent(node_b2, node_b1)
         self.net.addNodeWithParent(node_l3, node_b2)
         self.net.addNodeWithParent(node_l4, node_b2)
         self.net.addNodeWithParent(node_l5, node_b1)
예제 #5
0
class TestNET():
    def loadTree(self, reinitialize=0):
        if not hasattr(self, 'net') or reinitialize:
            alphas = np.array([1.]);
            gammas = np.array([1.])
            # define nodes
            node_r = NETNode(0, [0, 1, 2, 3, 4, 5], [], z_kernel=(alphas, gammas))
            node_s = NETNode(1, [0], [0], z_kernel=(alphas, gammas))
            node_b1 = NETNode(2, [1, 2, 3, 4, 5], [1], z_kernel=(alphas, gammas))
            node_b2 = NETNode(3, [2, 3, 4], [2], z_kernel=(alphas, gammas))
            node_l3 = NETNode(4, [3], [3], z_kernel=(alphas, gammas))
            node_l4 = NETNode(5, [4], [4], z_kernel=(alphas, gammas))
            node_l5 = NETNode(6, [5], [5], z_kernel=(alphas, gammas))
            # add nodes to tree
            self.net = NET()
            self.net.setRoot(node_r)
            self.net.addNodeWithParent(node_s, node_r)
            self.net.addNodeWithParent(node_b1, node_r)
            self.net.addNodeWithParent(node_b2, node_b1)
            self.net.addNodeWithParent(node_l3, node_b2)
            self.net.addNodeWithParent(node_l4, node_b2)
            self.net.addNodeWithParent(node_l5, node_b1)

    def testNodeFunctionalities(self):
        self.loadTree()
        node_r = self.net.root
        node_b = self.net[3]
        node_l = self.net[5]
        # test contains
        assert 1 in node_r
        assert 1 not in node_b and 2 in node_b
        assert 1 not in node_l and 4 in node_l

    def testKernels(self):
        # kernel 1
        a1 = np.array([1., 10.])
        c1 = np.array([2., 20.])
        k1 = Kernel((a1, c1))
        # kernel 2
        a2 = np.array([1., 10.])
        c2 = np.array([4., 40.])
        k2 = Kernel({'a': a2, 'c': c2})
        # kernel 3
        k3 = Kernel(1.)
        # kbar
        assert np.abs(k1.k_bar - 4.) < 1e-12
        assert np.abs(k2.k_bar - 8.) < 1e-12
        assert np.abs(k3.k_bar - 1.) < 1e-12
        # temporal kernel
        t_arr = np.array([0., np.infty])
        assert np.allclose(k1(t_arr), np.array([22., 0.]))
        assert np.allclose(k2(t_arr), np.array([44., 0.]))
        assert np.allclose(k3(t_arr), np.array([1., 0.]))
        # frequency kernel
        s_arr = np.array([0., np.infty]) * 1j
        assert np.allclose(k1.ft(s_arr), np.array([4. + 0j, np.nan * 1j]), equal_nan=True)
        assert np.allclose(k2.ft(s_arr), np.array([8. + 0j, np.nan * 1j]), equal_nan=True)
        assert np.allclose(k3.ft(s_arr), np.array([1. + 0j, np.nan * 1j]), equal_nan=True)
        # test addition
        k4 = k1 + k2
        assert np.abs(k4.k_bar - 12.) < 1e-12
        assert len(k4.a) == 2
        k5 = k1 + k3
        assert np.abs(k5.k_bar - 5.) < 1e-12
        assert len(k5.a) == 3
        # test subtraction
        k6 = k2 - k1
        assert len(k6.a) == 2
        assert np.allclose(k6.c, np.array([2., 20]))
        assert np.abs(k6.k_bar - 4.) < 1e-12
        k7 = k1 - k3
        assert len(k7.a) == 3
        assert np.allclose(k7.c, np.array([2., 20., -1.]))
        assert np.abs(k7.k_bar - 3.) < 1e-12

    def testBasic(self):
        self.loadTree()
        net = self.net
        assert net.getLocInds() == [0, 1, 2, 3, 4, 5]
        assert net.getLocInds(3) == [2, 3, 4]
        assert net.getLeafLocNode(0).index == 1
        assert net.getLeafLocNode(1).index == 2
        assert net.getLeafLocNode(2).index == 3
        assert net.getLeafLocNode(3).index == 4
        assert net.getLeafLocNode(4).index == 5
        assert net.getLeafLocNode(5).index == 6
        # create reduced net
        net_reduced = net.getReducedTree([4, 5])
        node_r = net_reduced[0]
        node_4 = net_reduced.getLeafLocNode(4)
        node_5 = net_reduced.getLeafLocNode(5)
        assert node_r.z_bar == (net[0].z_kernel + net[2].z_kernel).k_bar
        assert node_4.z_bar == (net[3].z_kernel + net[5].z_kernel).k_bar
        assert node_5.z_bar == net[6].z_bar
        # test Iz
        Izs = net.calcIZ([1, 3, 5])
        assert np.abs(Izs[(1, 3)] - .5) < 1e-12
        assert np.abs(Izs[(1, 5)] - .25) < 1e-12
        assert np.abs(Izs[(3, 5)] - .75) < 1e-12
        with pytest.raises(KeyError):
            Izs[(5, 3)]
        assert isinstance(net.calcIZ([4, 5]), float)
        # test impedance matrix calculation
        z_mat_control = np.array([[4., 2.], [2., 3.]])
        print(net_reduced.calcImpMat())
        assert np.allclose(net_reduced.calcImpMat(), z_mat_control)
        # run print commands
        print('\n>>> original net <<<')
        print(net)
        print('\n>>> reduced net <<<')
        print(net_reduced)

    def testCompartmentalization(self):
        self.loadTree()
        net = self.net
        comps = net.getCompartmentalization(Iz=.1)
        assert comps == [[1], [4], [5], [6]]
        comps = net.getCompartmentalization(Iz=.5)
        assert comps == [[1], [2]]
        comps = net.getCompartmentalization(Iz=1.)
        assert comps == [[3]]
        comps = net.getCompartmentalization(Iz=3.)
        assert comps == []
        comps = net.getCompartmentalization(Iz=5.)
        assert comps == []

    def testPlotting(self, pshow=0):
        self.loadTree()
        pl.figure('dendrograms')
        ax = pl.subplot(221)
        self.net.plotDendrogram(ax)
        ax = pl.subplot(222)
        self.net.plotDendrogram(ax,
                                plotargs={'lw': 2., 'color': 'DarkGrey'},
                                labelargs={'marker': 'o', 'ms': 6., 'c': 'r'},
                                textargs={'size': 'small'})
        ax = pl.subplot(223)
        self.net.plotDendrogram(ax,
                                plotargs={'lw': 2., 'color': 'DarkGrey'},
                                labelargs={-1: {'marker': 'o', 'ms': 6., 'c': 'r'},
                                           2: {'marker': 'o', 'ms': 10., 'c': 'y'}},
                                textargs={'size': 'small'})
        ax = pl.subplot(224)
        self.net.plotDendrogram(ax,
                                plotargs={'lw': 2., 'color': 'DarkGrey'},
                                labelargs={-1: {'marker': 'o', 'ms': 6., 'c': 'r'},
                                           2: {'marker': 'o', 'ms': 10., 'c': 'y'}},
                                textargs={'size': 'xx-small'},
                                nodelabels=None,
                                cs_comp={1: 0.05, 4: 0.35, 5: 0.75, 6: 0.95})
        if pshow:
            pl.show()
예제 #6
0
    def createTree(self, reinitialize=1, v_eq=-75.):
        '''
        Create simple NET structure

        2     3
        |     |
        |     |
        ---1---
           |
           |
           0
           |
        '''
        self.v_eq = v_eq
        loc_ind = np.array([0, 1, 2])

        # import btstructs
        # import morphologyReader as morphR
        # net_py = btstructs.STree()
        # # node 0
        # alphas = -1. / np.array([.5, 8.])
        # gammas = np.array([-1.,1.])
        # self.z_0 = - np.sum(gammas / alphas)
        # node_0 = btstructs.SNode(0)
        # node_0.set_content({'layerdata': morphR.layerData(loc_ind, alphas, gammas)})
        # dat = node_0.get_content()['layerdata']
        # dat.set_ninds(np.array([]))
        # net_py.set_root(node_0)
        # # node 1
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # self.z_1 = - np.sum(gammas / alphas)
        # node_1 = btstructs.SNode(1)
        # node_1.set_content({'layerdata': morphR.layerData(loc_ind, alphas, gammas)})
        # dat = node_1.get_content()['layerdata']
        # dat.set_ninds(np.array([0]))
        # net_py.add_node_with_parent(node_1, node_0)
        # # node 2
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # self.z_2 = - np.sum(gammas / alphas)
        # node_2 = btstructs.SNode(2)
        # node_2.set_content({'layerdata': morphR.layerData(loc_ind[1:2], alphas, gammas)})
        # dat = node_2.get_content()['layerdata']
        # dat.set_ninds(np.array([loc_ind[1]]))
        # net_py.add_node_with_parent(node_2, node_1)
        # # node 3
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # node_3 = btstructs.SNode(3)
        # self.z_3 = - np.sum(gammas / alphas)
        # node_3.set_content({'layerdata': morphR.layerData(loc_ind[2:], alphas, gammas)})
        # dat = node_3.get_content()['layerdata']
        # dat.set_ninds(np.array([loc_ind[2]]))
        # net_py.add_node_with_parent(node_3, node_1)

        # kernel constants
        alphas = 1. / np.array([.5, 8.])
        gammas = np.array([-1., 1.])
        alphas_ = 1. / np.array([1.])
        gammas_ = np.array([1.])
        # nodes
        node_0 = NETNode(0, [0, 1, 2], [], z_kernel=(alphas, gammas))
        node_1 = NETNode(1, [0, 1, 2], [0], z_kernel=(alphas_, gammas_))
        node_2 = NETNode(2, [1], [1], z_kernel=(alphas_, gammas_))
        node_3 = NETNode(3, [2], [2], z_kernel=(alphas_, gammas_))
        # add nodes to tree
        net_py = NET()
        net_py.setRoot(node_0)
        net_py.addNodeWithParent(node_1, node_0)
        net_py.addNodeWithParent(node_2, node_1)
        net_py.addNodeWithParent(node_3, node_1)
        # store
        self.net_py = net_py
        self.cnet = netsim.NETSim(net_py, v_eq=self.v_eq)
예제 #7
0
    def createTree2(self, reinitialize=1, add_lin=True, v_eq=-75.):
        '''
        Create simple NET structure

                3     4
                |     |
                |     |
                ---2---
             1     |
             |     |
             ---0---
                |
        '''
        self.v_eq = v_eq
        loc_ind = np.array([0, 1, 2])

        # import btstructs
        # import morphologyReader as morphR
        # net_py = btstructs.STree()
        # # node 0
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # self.z_0 = - np.sum(gammas / alphas)
        # node_0 = btstructs.SNode(0)
        # node_0.set_content({'layerdata': morphR.layerData(loc_ind, alphas, gammas)})
        # dat = node_0.get_content()['layerdata']
        # dat.set_ninds(np.array([]))
        # net_py.set_root(node_0)
        # # node 1
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # self.z_1 = - np.sum(gammas / alphas)
        # node_1 = btstructs.SNode(1)
        # node_1.set_content({'layerdata': morphR.layerData(loc_ind[0:1], alphas, gammas)})
        # dat = node_1.get_content()['layerdata']
        # dat.set_ninds(np.array([0]))
        # net_py.add_node_with_parent(node_1, node_0)
        # # node 2
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # self.z_2 = - np.sum(gammas / alphas)
        # node_2 = btstructs.SNode(2)
        # node_2.set_content({'layerdata': morphR.layerData(loc_ind[1:], alphas, gammas)})
        # dat = node_2.get_content()['layerdata']
        # dat.set_ninds(np.array([]))
        # net_py.add_node_with_parent(node_2, node_0)
        # # node 3
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # self.z_3 = - np.sum(gammas / alphas)
        # node_3 = btstructs.SNode(3)
        # node_3.set_content({'layerdata': morphR.layerData(loc_ind[1:2], alphas, gammas)})
        # dat = node_3.get_content()['layerdata']
        # dat.set_ninds(np.array([loc_ind[1]]))
        # net_py.add_node_with_parent(node_3, node_2)
        # # node 4
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # node_4 = btstructs.SNode(4)
        # self.z_4 = - np.sum(gammas / alphas)
        # node_4.set_content({'layerdata': morphR.layerData(loc_ind[2:], alphas, gammas)})
        # dat = node_4.get_content()['layerdata']
        # dat.set_ninds(np.array([loc_ind[2]]))
        # net_py.add_node_with_parent(node_4, node_2)
        # # linear terms
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # lin3 = morphR.linearLayerData([1], alphas, gammas)
        # alphas = -1. / np.array([1.])
        # gammas = np.array([1.])
        # lin4 = morphR.linearLayerData([2], alphas, gammas)
        # self.lin_terms = [lin3, lin4] if add_lin else []

        # kernel constants
        alphas = 1. / np.array([1.])
        gammas = np.array([1.])
        # nodes
        node_0 = NETNode(0, [0, 1, 2], [], z_kernel=(alphas, gammas))
        node_1 = NETNode(1, [0], [0], z_kernel=(alphas, gammas))
        node_2 = NETNode(2, [1, 2], [], z_kernel=(alphas, gammas))
        node_3 = NETNode(3, [1], [1], z_kernel=(alphas, gammas))
        node_4 = NETNode(4, [2], [2], z_kernel=(alphas, gammas))
        # add nodes to tree
        net_py = NET()
        net_py.setRoot(node_0)
        net_py.addNodeWithParent(node_1, node_0)
        net_py.addNodeWithParent(node_2, node_0)
        net_py.addNodeWithParent(node_3, node_2)
        net_py.addNodeWithParent(node_4, node_2)
        # linear terms
        alphas = 1. / np.array([1.])
        gammas = np.array([1.])
        self.lin_terms = {
            1: Kernel((alphas, gammas)),
            2: Kernel((alphas, gammas))
        } if add_lin else {}
        # store
        self.net_py = net_py
        self.cnet = netsim.NETSim(net_py,
                                  lin_terms=self.lin_terms,
                                  v_eq=self.v_eq)