You can use the same slicing trick to distribute an N-dimensional input into groups of 4. As an example:
with nengo.Network() as max_pool_main:
# Note, you can use a function to define your function here as well,
# this is just an example
max_pool_main.input = nengo.Node(size_in=16)
max_pool_main.output = nengo.Node(size_in=4)
for n in range(16 // 4):
# Make individual subnets and connect to input
subnet = create_subnet()
# Connect sliced input to input of subnet
nengo.Connection(max_pool_main.input[n * 4: n * 4 + 4], subnet)
# Connect output of subnet to sliced output
nengo.Connection(subnet, max_pool_main.output[n])
Note that in the example code above, it makes no assumptions about the order of each element of the input (and it doesn’t need to). All it is doing is “mapping” the groups of 4 dimensions of the input to the various copies of subnet
. You can combine it with the shuffled slicing I suggested in my previous post to get the correct mapping for the max pooling operation, like so:
slice = [0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15]
nengo.Connection(ens.neurons[slice], max_pool_main.input)
If you are looking for an example network to start, I’d suggest the nengo.networks.EnsembleArray
network code. It basically have everything you want (just use the __init__
function, and you can ignore the rest really), all you have to do to customize it to your needs is to replace this line with code to create your subnet
network.