예제 #1
0
    def test_uniform_proba_connection_between_cells(self):
        """
        Compare UniformConnectionProba with a regular uniform dist of the same size as
        the maximal all-to-all connections.

        The test will pass if difference between potential conn number is less than 0.95
        """
        threshold = 0.9  # if Uniform dist pass this threshold - creates connection

        Dist.set_seed(13)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=threshold,
                                 seg_dist="uniform")

        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        norm = np.abs(np.random.uniform(size=200 * 100))
        non_zero_norm = np.count_nonzero(norm[norm > threshold])

        non_zero_cell = [len(c.syns) for c in self.pop2.cells]
        non_zero_cell_sum = sum(non_zero_cell)

        # difference of connection number is less then 0.95
        if non_zero_cell_sum > non_zero_norm:
            diff = non_zero_norm / non_zero_cell_sum
        else:
            diff = non_zero_cell_sum / non_zero_norm
        self.assertGreater(diff, 0.95)
예제 #2
0
    def setUpClass(cls):
        morpho_path = os.path.join(path, "..",
                                   "commons/morphologies/swc/my.swc")

        def cell_template():
            cell = Cell(name="cell")
            cell.load_morpho(filepath=morpho_path)
            cell.insert("pas")
            cell.insert("hh")
            return cell

        # Create NetStim
        cls.netstim = NetStimCell("stim1").add_netstim(start=21,
                                                       number=100,
                                                       interval=2)

        # Define connection probabilities
        Dist.set_seed(13)
        weight_dist = NormalDist(mean=0.01, std=0.024)

        # Create population 1
        cls.pop1 = Population("pop_0")
        cls.pop1.add_cells(num=30, cell_function=cell_template)

        connector = cls.pop1.connect(cell_connection_proba=0.6)
        connector.set_source(cls.netstim)
        connector.set_target([c.filter_secs("dend") for c in cls.pop1.cells])
        syn_adder = connector.add_synapse("Exp2Syn")
        syn_adder.add_netcon(weight=weight_dist)
        connector.build()

        # Create population 2
        cls.pop2 = Population("pop_1")
        cls.pop2.add_cells(num=40, cell_function=cell_template)

        connector = cls.pop2.connect(cell_connection_proba=0.8)
        connector.set_source(
            [c.filter_secs("soma")(0.5) for c in cls.pop1.cells])
        connector.set_target([c.filter_secs("dend") for c in cls.pop2.cells])
        syn_adder = connector.add_synapse("Exp2Syn")
        syn_adder.add_netcon(weight=weight_dist)
        connector.build()

        # Create population 3
        cls.pop3 = Population("pop_2")
        cls.pop3.add_cells(num=50, cell_function=cell_template)

        connector = cls.pop3.connect(cell_connection_proba=0.3)
        connector.set_source(
            [c.filter_secs("soma")(0.5) for c in cls.pop2.cells])
        connector.set_target([c.filter_secs("dend") for c in cls.pop3.cells])
        syn_adder = connector.add_synapse("Exp2Syn")
        syn_adder.add_netcon(weight=weight_dist)
        connector.build()
예제 #3
0
    def test_syn_per_cell_rule_one_syn_per_source_1(self):
        Dist.set_seed(13)
        conn = self.pop2.connect(rule="one",
                                 cell_connection_proba=1,
                                 seg_dist="uniform",
                                 syn_num_per_cell_source=1)
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        lens = [len(c.syns) for c in self.pop2.cells]
        self.assertEqual(50, sum(lens))
예제 #4
0
    def test_syn_per_cell_source5(self):
        Dist.set_seed(15)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=0.5,
                                 seg_dist="uniform",
                                 syn_num_per_cell_source=3)
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        lens = [len(c.syns) for c in self.pop2.cells]
        avg = np.average(lens)
        self.assertEqual(75, round(avg))
예제 #5
0
    def test_full_all_to_all_connections_between_cells(self):
        """
        Expected that each cell from pop1 will be connected to each cell in the pop2
        """
        Dist.set_seed(13)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=1.0,
                                 seg_dist="uniform")
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        non_zero_cell = sum([len(c.syns) for c in self.pop2.cells])
        self.assertEqual(20000, non_zero_cell)
예제 #6
0
    def test_uniform_seg_dist(self):
        """
        Expected that seg.x distribution will be uniform,
        mean will be ~0.5 and distribution will be normal between 0-1
        """
        Dist.set_seed(13)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=1.0,
                                 seg_dist="uniform")
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        xs = [s.parent.x for c in self.pop2.cells for s in c.syns]
        self.assertEqual(0.50, round(np.average(xs), 2))
예제 #7
0
    def test_uniform(self):
        num = 100
        Dist.set_seed(13)
        avgs = []
        vars = []
        ls = []
        for i in range(20):
            for i in range(num):
                s = self.cell.add_sec("dend", l=UniformDist(low=1, high=10))
                ls.append(s.hoc.L)
                s.remove_immediate_from_neuron()

            vars.append(np.var(ls))
            avgs.append(np.average(ls))

        self.assertEqual(5.3644, round(np.average(avgs), 4))
        self.assertEqual(7.0346, round(np.average(vars), 4))
예제 #8
0
    def test_syn_per_cell_source_pop_syns_num(self):
        Dist.set_seed(15)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=1,
                                 seg_dist="uniform",
                                 syn_num_per_cell_source=UniformTruncatedDist(
                                     low=0, high=5))
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        lens = [len(c.syns) for c in self.pop2.cells]
        defaultdict(int)
        counts = Counter([s.sources[0].parent.cell for s in self.pop2.syns])
        avg_source = np.average(list(counts.values()))
        avg_lens = np.average(lens)
        self.assertEqual(avg_source, avg_lens)
예제 #9
0
    def test_normal_seg_dist(self):
        """
        Expected that seg.x distribution will be truncated normal,
        mean will be ~0.7 and std ~0.2
        """
        Dist.set_seed(13)
        seg_dist = NormalTruncatedSegDist(mean=0.7, std=0.2)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=1.0,
                                 seg_dist=seg_dist)
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        xs = [s.parent.x for c in self.pop2.cells for s in c.syns]
        avg = np.average(xs)
        std = np.std(xs)

        self.assertEqual(0.2, np.round(std, 1))
        self.assertEqual(0.7, np.round(avg, 1))
예제 #10
0
    def setUpClass(cls):
        morpho_path = os.path.join(path, "..",
                                   "commons/morphologies/swc/my.swc")

        def cell_template():
            cell = Cell(name="cell")
            cell.load_morpho(filepath=morpho_path)
            cell.insert("pas")
            cell.insert("hh")
            return cell

        # Define connection probabilities
        Dist.set_seed(13)
        weight_dist1 = NormalTruncatedDist(mean=0.01, std=0.05)
        weight_dist2 = NormalTruncatedDist(mean=0.1, std=0.5)

        # Create population 1
        cls.pop1 = Population("pop_0")
        cls.pop1.add_cells(num=50, cell_function=cell_template)

        # Create population 2
        cls.pop2 = Population("pop_1")
        cls.pop2.add_cells(num=50, cell_function=cell_template)

        connector = cls.pop2.connect(cell_connection_proba=0.5)
        connector.set_source(
            [c.filter_secs("soma")(0.5) for c in cls.pop1.cells])
        connector.set_target([c.filter_secs("dend") for c in cls.pop2.cells])
        connector.add_synapse("ExpSyn").add_netcon(weight=weight_dist1)
        connector.add_synapse("Exp2Syn").add_netcon(weight=weight_dist2)
        connector.group_synapses(name="group1")
        connector.build()

        connector = cls.pop2.connect(cell_connection_proba=0.5)
        connector.set_source(
            [c.filter_secs("soma")(0.5) for c in cls.pop1.cells])
        connector.set_target([c.filter_secs("dend") for c in cls.pop2.cells])
        connector.add_synapse("ExpSyn").add_netcon(weight=1.5)
        connector.add_synapse("Exp2Syn").add_netcon(weight=10.5)
        connector.build()
예제 #11
0
    def test_normal_proba_connection_between_cells(self):
        """
        Compare NormalConnectionProba (which is truncated normal dist) with a regular
        truncated normal dist of the same size as the maximal all-to-all connections.

        The test will pass if difference between potential conn number is less than 0.95
        """
        std = 0.2
        mean = 0.1
        threshold = 0.4  # if Truncated Normal Dist pass this threshold - creates connection

        Dist.set_seed(13)
        cell_conn_proba = NormalConnectionProba(threshold=threshold,
                                                mean=mean,
                                                std=std)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=cell_conn_proba,
                                 seg_dist="uniform")

        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        # create Truncated Normal comparative distribution of the same size as maximal
        # all-to-all connections
        norm = np.abs(np.random.normal(loc=mean, scale=std, size=200 * 100))
        non_zero_norm = np.count_nonzero(norm[norm > threshold])

        non_zero_cell = [len(c.syns) for c in self.pop2.cells]
        non_zero_cell_sum = sum(non_zero_cell)

        # difference of connection number is less then 0.95
        if non_zero_cell_sum > non_zero_norm:
            diff = non_zero_norm / non_zero_cell_sum
        else:
            diff = non_zero_cell_sum / non_zero_norm
        self.assertGreater(diff, 0.95)
예제 #12
0
    def test_syn_per_cell_rule_one_normal_truncated(self):
        Dist.set_seed(13)
        conn = self.pop2.connect(rule="one",
                                 cell_connection_proba=1,
                                 seg_dist="uniform",
                                 syn_num_per_cell_source=NormalTruncatedDist(
                                     mean=2, std=0.5))
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        lens = [len(c.syns) for c in self.pop2.cells]
        avg_lens = np.average(lens)

        Dist.set_seed(13)
        rand_avg = np.average(np.random.normal(loc=2, scale=0.5, size=50))

        if avg_lens > rand_avg:
            diff = rand_avg / avg_lens
        else:
            diff = avg_lens / rand_avg
        self.assertGreater(diff, 0.9)
예제 #13
0
    def test_syn_per_cell_source_uniform(self):
        Dist.set_seed(13)
        conn = self.pop2.connect(rule="all",
                                 cell_connection_proba=1,
                                 seg_dist="uniform",
                                 syn_num_per_cell_source=UniformTruncatedDist(
                                     low=0, high=5))
        conn.set_source([c.filter_secs("soma")(0.5) for c in self.pop1.cells])
        conn.set_target(self.pop2.cells)
        conn.add_synapse("Exp2Syn").add_netcon()
        conn.build()

        lens = [len(c.syns) for c in self.pop2.cells]
        avg_lens = np.average(lens)

        Dist.set_seed(13)
        rand_avg = np.average(np.random.uniform(0, 5, size=50) * 50)

        if avg_lens > rand_avg:
            diff = rand_avg / avg_lens
        else:
            diff = avg_lens / rand_avg
        self.assertGreater(diff, 0.9)
예제 #14
0
    def test_normal(self):
        num = 100
        Dist.set_seed(13)
        avgs = []
        vars = []
        ls = []
        for i in range(20):
            for i in range(num):
                s = self.cell.add_sec("dend",
                                      l=NormalTruncatedDist(mean=5, std=2))
                ls.append(s.hoc.L)
                s.remove_immediate_from_neuron()

            vars.append(np.var(ls))
            avgs.append(np.average(ls))

        std = np.sqrt(np.average(vars))
        std_diff = round(abs(std - 2), 2)

        avg = np.average(avgs)
        avg_diff = round(abs(avg - 5), 2)

        self.assertLess(std_diff, 0.1)
        self.assertLess(avg_diff, 0.05)
예제 #15
0
 def test_seed(self):
     Dist.set_seed(13)
     self.assertEqual(13, np.random.get_state()[1][0])
예제 #16
0
if __name__ == '__main__':
    def cell_function():
        cell = Cell(name="cell")
        morpho_path = os.path.join(path, "..", "commons/morphologies/asc/cell1.asc")
        cell.load_morpho(filepath=morpho_path)
        cell.insert("pas")
        cell.insert("hh")
        cell.make_spike_detector(seg=cell.filter_secs("soma")(0.5))
        return cell

    # Create NetStim
    netstim = NetStimCell("stim").add_netstim(start=21, number=100, interval=2)

    # Define connection probabilities
    Dist.set_seed(13)
    connection_proba = NormalConnectionProba(mean=0.8, std=0.1, threshold=0.6)
    weight_dist = NormalTruncatedDist(mean=0.1, std=0.2)

    # Create population 1
    pop1 = Population("pop_1")
    pop1.add_cells(num=4, cell_function=cell_function)

    connector = pop1.connect(cell_connection_proba=connection_proba)
    connector.set_source(netstim)
    connector.set_target([d(0.5) for c in pop1.cells for d in c.filter_secs("dend")])
    syn_adder = connector.add_synapse("Exp2Syn")
    syn_adder.add_netcon(weight=weight_dist)

    connector.build()
    pop1.record()
예제 #17
0
 def test_seed_numpy(self):
     Dist.set_seed(13)
     rand_avg1 = np.average(np.random.uniform(0, 5, size=50) * 50)
     Dist.set_seed(13)
     rand_avg2 = np.average(np.random.uniform(0, 5, size=50) * 50)
     self.assertEqual(rand_avg1, rand_avg2)