def test_iteration(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3 * i + 2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     self.assertEqual(list(ps),
                      [{'a': 3, 'c': 5, 'b': 7},
                       {'a': 8, 'c': 11, 'b': 7},
                       {'a': 13, 'c': 14, 'b': 7}])
 def test_evaluate_with_mask_2D(self):
     ps2d = ParameterSpace({'a': [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]],
                            'b': 7,
                            'c': lambda i, j: 3 * i - 2 * j}, shape=(2, 5))
     ps2d.evaluate(mask=(slice(None), [1, 3, 4]))
     assert_array_equal(ps2d['a'], np.array([[3, 8, 13], [34, 89, 144]]))
     assert_array_equal(ps2d['c'], np.array([[-2, -6, -8], [1, -3, -5]]))
Beispiel #3
0
 def test_create_with_list_of_lists(self):
     schema = {'a': Sequence}
     ps = ParameterSpace({'a': [[1, 2, 3], [4, 5, 6]]},
                         schema,
                         shape=(2,))
     ps.evaluate()
     assert_array_equal(ps['a'], np.array([Sequence([1, 2, 3]), Sequence([4, 5, 6])], dtype=Sequence))  
Beispiel #4
0
 def test_create_with_array_of_sequences(self):
     schema = {"a": Sequence}
     ps = ParameterSpace(
         {"a": np.array([Sequence([1, 2, 3]), Sequence([4, 5, 6])], dtype=Sequence)}, schema, shape=(2,)
     )
     ps.evaluate()
     assert_array_equal(ps["a"], np.array([Sequence([1, 2, 3]), Sequence([4, 5, 6])], dtype=Sequence))
Beispiel #5
0
 def test_evaluate_with_mask_2D(self):
     ps2d = ParameterSpace(
         {"a": [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]], "b": 7, "c": lambda i, j: 3 * i - 2 * j}, shape=(2, 5)
     )
     ps2d.evaluate(mask=(slice(None), [1, 3, 4]))
     assert_array_equal(ps2d["a"], np.array([[3, 8, 13], [34, 89, 144]]))
     assert_array_equal(ps2d["c"], np.array([[-2, -6, -8], [1, -3, -5]]))
Beispiel #6
0
 def test_columnwise_iteration(self):
     ps2d = ParameterSpace(
         {
             'a': [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]],
             'b': 7,
             'c': lambda i, j: 3 * i - 2 * j
         },
         shape=(2, 5))
     ps2d.evaluate(mask=(slice(None), [1, 3, 4]))
     expected = [{
         'a': np.array([3, 34]),
         'b': np.array([7, 7]),
         'c': np.array([-2, 1])
     }, {
         'a': np.array([8, 89]),
         'b': np.array([7, 7]),
         'c': np.array([-6, -3])
     }, {
         'a': np.array([13, 144]),
         'b': np.array([7, 7]),
         'c': np.array([-8, -5])
     }]
     for x, y in zip(ps2d.columns(), expected):
         for key in y:
             assert_array_equal(x[key], y[key])
Beispiel #7
0
 def test_iteration(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3*i+2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     self.assertEqual(list(ps),
                      [{'a': 3, 'c': 5, 'b': 7},
                       {'a': 8, 'c': 11, 'b': 7},
                       {'a': 13, 'c': 14, 'b': 7}])
Beispiel #8
0
 def test_create_with_tuple(self):
     schema = {'a': Sequence}
     ps = ParameterSpace({'a': (1, 2, 3)},
                         schema,
                         shape=(2,))
     ps.evaluate()
     assert_array_equal(ps['a'], np.array([Sequence([1, 2, 3]), Sequence([1, 2, 3])], dtype=Sequence))
 def test_create_with_list_of_lists(self):
     schema = {'a': Sequence}
     ps = ParameterSpace({'a': [[1, 2, 3], [4, 5, 6]]},
                         schema,
                         shape=(2,))
     ps.evaluate()
     assert_array_equal(ps['a'], np.array([Sequence([1, 2, 3]), Sequence([4, 5, 6])], dtype=Sequence))  
 def test_create_with_tuple(self):
     schema = {'a': Sequence}
     ps = ParameterSpace({'a': (1, 2, 3)},
                         schema,
                         shape=(2,))
     ps.evaluate()
     assert_array_equal(ps['a'], np.array([Sequence([1, 2, 3]), Sequence([1, 2, 3])], dtype=Sequence))
Beispiel #11
0
 def test_iteration_items(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3*i+2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     expected = {'a': np.array([3,  8, 13]),
                 'c': np.array([5, 11, 14]),
                 'b': np.array([7, 7, 7])}
     for key, value in ps.items():
         assert_array_equal(expected[key], value)
Beispiel #12
0
 def test_evaluate_with_mask(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3*i+2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     expected = {'a': np.array([ 3,  8, 13]),
                 'c': np.array([ 5, 11, 14]),
                 'b': np.array([7, 7, 7])}
     for key in expected:
         assert_array_equal(expected[key], ps[key])
 def test_evaluate_with_mask(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3 * i + 2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     expected = {'a': np.array([3, 8, 13]),
                 'c': np.array([5, 11, 14]),
                 'b': np.array([7, 7, 7])}
     for key in expected:
         assert_array_equal(expected[key], ps[key])
 def test_iteration_items(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8, 13], 'b': 7, 'c': lambda i: 3 * i + 2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     expected = {'a': np.array([3, 8, 13]),
                 'c': np.array([5, 11, 14]),
                 'b': np.array([7, 7, 7])}
     for key, value in ps.items():
         assert_array_equal(expected[key], value)
Beispiel #15
0
 def test_evaluate(self):
     ps = ParameterSpace(
         {
             'a': [2, 3, 5, 8],
             'b': 7,
             'c': lambda i: 3 * i + 2
         }, shape=(4, ))
     self.assertIsInstance(ps['c'], LazyArray)
     ps.evaluate()
     assert_array_equal(ps['c'], np.array([2, 5, 8, 11]))
Beispiel #16
0
 def test_columnwise_iteration_single_column(self):
     ps2d = ParameterSpace(
         {"a": [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]], "b": 7, "c": lambda i, j: 3 * i - 2 * j}, shape=(2, 5)
     )
     ps2d.evaluate(mask=(slice(None), 3))
     expected = [{"a": np.array([8, 89]), "b": np.array([7, 7]), "c": np.array([-6, -3])}]
     actual = list(ps2d.columns())
     for x, y in zip(actual, expected):
         for key in y:
             assert_array_equal(x[key], y[key])
 def test_columnwise_iteration_single_column(self):
     ps2d = ParameterSpace({'a': [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]],
                            'b': 7,
                            'c': lambda i, j: 3 * i - 2 * j}, shape=(2, 5))
     ps2d.evaluate(mask=(slice(None), 3))
     expected = [{'a': np.array([8, 89]), 'b': np.array([7, 7]), 'c': np.array([-6, -3])}]
     actual = list(ps2d.columns())
     for x, y in zip(actual, expected):
         for key in y:
             assert_array_equal(x[key], y[key])
Beispiel #18
0
 def test_columnwise_iteration(self):
     ps2d = ParameterSpace({'a': [[2, 3, 5, 8, 13], [21, 34, 55, 89, 144]],
                            'b': 7,
                            'c': lambda i, j: 3*i-2*j}, shape=(2, 5))
     ps2d.evaluate(mask=(slice(None), [1, 3, 4]))
     expected = [{'a': np.array([3, 34]), 'b': np.array([7, 7]), 'c': np.array([-2, 1])},
                 {'a': np.array([8, 89]), 'b': np.array([7, 7]), 'c': np.array([-6, -3])},
                 {'a': np.array([13, 144]), 'b': np.array([7, 7]), 'c': np.array([-8, -5])}]
     for x, y in zip(ps2d.columns(), expected):
         for key in y:
             assert_array_equal(x[key], y[key])
Beispiel #19
0
    def connect(self, projection):
        """Connect-up a Projection."""
        logger.debug("conn_list (original) = \n%s", self.conn_list)
        if numpy.any(self.conn_list[:, 0] >= projection.pre.size):
            raise errors.ConnectionError("source index out of range")
        if (self.conn_list.shape[1] < 3 or self.conn_list.shape[1] > 4
                or (self.conn_list.shape[1] == 3
                    and projection.synapse_type.has_parameter('delay'))):
            raise errors.ConnectionError(
                "incompatible number of columns for connection list requires "
                "4 (3 for synapse type without delay)")
        # need to do some profiling, to figure out the best way to do this:
        #  - order of sorting/filtering by local
        #  - use numpy.unique, or just do in1d(self.conn_list)?
        idx = numpy.argsort(self.conn_list[:, 1])
        targets = numpy.unique(self.conn_list[:, 1]).astype(numpy.int)
        local = numpy.in1d(
            targets,
            numpy.arange(projection.post.size)[projection.post._mask_local],
            assume_unique=True)
        local_targets = targets[local]
        self.conn_list = self.conn_list[idx]
        left = numpy.searchsorted(self.conn_list[:, 1], local_targets, 'left')
        right = numpy.searchsorted(self.conn_list[:, 1], local_targets,
                                   'right')
        logger.debug("idx = %s", idx)
        logger.debug("targets = %s", targets)
        logger.debug("local_targets = %s", local_targets)
        logger.debug("conn_list (sorted by target) = \n%s", self.conn_list)
        logger.debug("left = %s", left)
        logger.debug("right = %s", right)

        schema = projection.synapse_type.get_schema()
        for tgt, l, r in zip(local_targets, left, right):
            sources = self.conn_list[l:r, 0].astype(numpy.int)
            param_dict = {'weight': self.conn_list[l:r, 2]}
            if self.conn_list.shape[1] == 4:
                param_dict['delay'] = self.conn_list[l:r, 3]
            connection_parameters = ParameterSpace(param_dict,
                                                   schema=schema,
                                                   shape=(r - l, ))
            if isinstance(projection.synapse_type, StandardSynapseType):
                connection_parameters = projection.synapse_type.translate(
                    connection_parameters)
            connection_parameters.evaluate()
            projection._convergent_connect(sources, tgt,
                                           **connection_parameters)
Beispiel #20
0
    def connect(self, projection):
        """Connect-up a Projection."""
        logger.debug("conn_list (original) = \n%s", self.conn_list)
        if numpy.any(self.conn_list[:, 0] >= projection.pre.size):
            raise errors.ConnectionError("source index out of range")
        if (self.conn_list.shape[1] < 3 or self.conn_list.shape[1] > 4 or 
            (self.conn_list.shape[1] == 3 and projection.synapse_type.has_parameter('delay'))):
            raise errors.ConnectionError("incompatible number of columns for connection list requires "
                                         "4 (3 for synapse type without delay)")
        # need to do some profiling, to figure out the best way to do this:
        #  - order of sorting/filtering by local
        #  - use numpy.unique, or just do in1d(self.conn_list)?
        idx  = numpy.argsort(self.conn_list[:, 1])
        targets = numpy.unique(self.conn_list[:, 1]).astype(numpy.int)
        local = numpy.in1d(targets,
                           numpy.arange(projection.post.size)[projection.post._mask_local],
                           assume_unique=True)
        local_targets = targets[local]
        self.conn_list = self.conn_list[idx]
        left  = numpy.searchsorted(self.conn_list[:, 1], local_targets, 'left')
        right = numpy.searchsorted(self.conn_list[:, 1], local_targets, 'right')
        logger.debug("idx = %s", idx)
        logger.debug("targets = %s", targets)
        logger.debug("local_targets = %s", local_targets)
        logger.debug("conn_list (sorted by target) = \n%s", self.conn_list)
        logger.debug("left = %s", left)
        logger.debug("right = %s", right)

        schema = projection.synapse_type.get_schema()
        for tgt, l, r in zip(local_targets, left, right):
            sources = self.conn_list[l:r, 0].astype(numpy.int)
            param_dict = {'weight': self.conn_list[l:r, 2] }
            if self.conn_list.shape[1] == 4:
                param_dict['delay'] = self.conn_list[l:r, 3]
            connection_parameters = ParameterSpace(param_dict,
                                                   schema=schema,
                                                   shape=(r-l,))
            if isinstance(projection.synapse_type, StandardSynapseType):
                connection_parameters = projection.synapse_type.translate(
                                            connection_parameters)
            connection_parameters.evaluate()
            projection._convergent_connect(sources, tgt, **connection_parameters)
Beispiel #21
0
 def test_evaluate(self):
     ps = ParameterSpace({"a": [2, 3, 5, 8], "b": 7, "c": lambda i: 3 * i + 2}, shape=(4,))
     self.assertIsInstance(ps["c"], LazyArray)
     ps.evaluate()
     assert_array_equal(ps["c"], np.array([2, 5, 8, 11]))
Beispiel #22
0
 def test_evaluate(self):
     ps = ParameterSpace({'a': [2, 3, 5, 8], 'b': 7, 'c': lambda i: 3*i+2}, shape=(4,))
     self.assertIsInstance(ps['c'], LazyArray)
     ps.evaluate()
     assert_array_equal(ps['c'], np.array([ 2,  5,  8, 11]))
Beispiel #23
0
 def test_iteration(self):
     ps = ParameterSpace({"a": [2, 3, 5, 8, 13], "b": 7, "c": lambda i: 3 * i + 2}, shape=(5,))
     ps.evaluate(mask=[1, 3, 4])
     self.assertEqual(list(ps), [{"a": 3, "c": 5, "b": 7}, {"a": 8, "c": 11, "b": 7}, {"a": 13, "c": 14, "b": 7}])