Search code examples
machine-learningpytorchartificial-intelligence

How to define neural network neuron-by-neuron?


So we want to have a random brain-like neuron mess. Meaning:

  • We have AxB inputs and CxD outputs.
  • We want to have K (where K >= CxD) neurons that are connected to each other at random.
  • Yet so that all K neurons are connected to at least one of AxB inputs,
  • And all K neurons are connected to at least one CxD output.

Something like ths (here AxB=5, K=4, CxD=2):

enter image description here

Operations that neurons shall do are weighted summ + some reduction like LeakyReLu.

So one can imagine that when connection randomnes is controlled so that connections are localised over image patches alike layers of CNN it can produce intresting results.

How one could do such thing (handle neurons one-by-one) in PyTorch?


Solution

  • There are two issues here: The major issue is how to randomly sample the connections, and a minor issue of how to optimize a sparse linear layer.

    As for the minor issue, you can implement a sparse fully-connected layer based on the linked answer.

    As for the random connectivity, you'll have to implement it in a way that there are no "loops"