how can I represent the derivative of a network (e.g. NetGraph or NetChain) as a network? I have tried it with FunctionLayer[] and NetPortGradient, but without success.
I would be very pleased to receive an answer.
Minimal working example:
Let the following layer be given
unet = FunctionLayer[#*FeedForwardNet[#] + 1 &, "Output" -> "Scalar"]
whereby
FeedForwardNet = NetChain[ {LinearLayer[50, "Input" -> "Real"], LogisticSigmoid,LinearLayer[1, "Output" -> "Scalar"]}]
I now want to determine the derivative of unet, but as a network.
With
NetInitialize[unet][1, NetPortGradient["Input"]]
I get the derivative at the point 1. However, I cannot define this as a layer. When I try I get an error:
FunctionLayer[NetInitialize[u][#, NetPortGradient["Input"]] &]
Error: Cannot interpret FunctionLayer[<>][#1, #2] & as a network.
I would not like to carry out a numerical calculation of the derivative.