TwoEndConnector#

class brainpy.connect.TwoEndConnector(pre=None, post=None)[source]#

Synaptic connector to build connections between two neuron groups.

If users want to customize their Connector, there are two ways:

  1. Implementing build_conn(self) function, which returns one of the connection data csr (CSR sparse data, a tuple of <post_ids, inptr>), coo (COO sparse data, a tuple of <pre_ids, post_ids>), or mat (a binary connection matrix). For instance,

    import brainpy as bp
    class MyConnector(bp.conn.TwoEndConnector):
      def build_conn(self):
        return dict(csr=, mat=, coo=)
    
  2. Implementing functions build_mat(), build_csr(), and build_coo(). Users can provide all three functions, or one of them.

    import brainpy as bp
    class MyConnector(bp.conn.TwoEndConnector):
      def build_mat(self, ):
        return conn_matrix
    
      def build_csr(self, ):
        return post_ids, inptr
    
      def build_coo(self, ):
        return pre_ids, post_ids
    
build_conn()[source]#

build connections with certain data type.

If users want to customize their connections, please provide one of the following functions:

  • build_mat(): build a matrix binary connection matrix.

  • build_csr(): build a csr sparse connection data.

  • build_coo(): build a coo sparse connection data.

  • build_conn(): deprecated.

Returns:

conn – A tuple with two elements: connection type (str) and connection data. For example: return 'csr', (ind, indptr) Or a dict with three elements: csr, mat and coo. For example: return dict(csr=(ind, indptr), mat=None, coo=None)

Return type:

tuple, dict

build_coo()[source]#

Build a coo sparse connection data.

Returns:

conn – A tuple denoting the (pre_ids, post_ids).

Return type:

tuple

build_csr()[source]#

Build a csr sparse connection data.

Returns:

conn – A tuple denoting the (indices, indptr).

Return type:

tuple

build_mat()[source]#

Build a binary matrix connection data.

If users want to customize their connections, please provide one of the following functions:

  • build_mat(): build a matrix binary connection matrix.

  • build_csr(): build a csr sparse connection data.

  • build_coo(): build a coo sparse connection data.

  • build_conn(): deprecated.

Returns:

conn – A binary matrix with the shape (num_pre, num_post).

Return type:

Array

require(*structures)[source]#

Require all the connection data needed.

Examples

>>> import brainpy as bp
>>> conn = bp.connect.FixedProb(0.1)
>>> mat = conn.require(10, 20, 'conn_mat')
>>> mat.shape
(10, 20)
requires(*structures)[source]#

Require all the connection data needed.