2
$\begingroup$

When using NetGraph[], I am try to specify the connections between 3 layers like so:

NetGraph[{...some layers...},{...{2,3}->4}]

But I receive the following error message:

"{2,3} is not a valid source for 4."

So it seems that Mathematica is having a hard time taking the input of two different layers into a single layer, which is strange to me, as an operation like:

...2->{3,4}...

Is considered valid, and will create 2 layers with the appropriate weights as output from the layer 2.

Does anyone know how I can have two layers be input to a single layer, while not losing the weighted connections of the first two layers to the third, such as in the following image: enter image description here ? Thanks!

$\endgroup$
1
$\begingroup$

You can use CatenateLayer for this. Something close to your diagram might be like this:

NetGraph[{LinearLayer[4], LinearLayer[4], LinearLayer[4], 
  CatenateLayer[], LinearLayer[3]}, {1 -> 2, 1 -> 3, 2 -> 4, 3 -> 4, 
  4 -> 5}]
$\endgroup$
  • $\begingroup$ Thanks! That's just what I was looking for! There are a lot of layers to look through and understand their functionality. $\endgroup$ – Jmeeks29ig Apr 18 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.