# How can I compute a mathematical formula for my CNN?

Let's say, for example, I have built the following CNN model using Keras:

model = Sequential()


I wish to be able to transform the above model into a mathematical formula.

I understand the basic structure of a CNN as follows: where

However, I do not know how to go from the above recursive formula to something like this (the first two summations are weights and the second two are adjustable biases): Note: The formula above is just an example and not representative of the code given above.

• Do I need to trace each weight, each bias and each connection of every neuron? If so, how?
• Furthermore, I would highly appreciate it if someone could provide a generalized strategy for tackling such a problem (like finding a math formula to suit a different kind of classifier).
• Lastly, is this an easy task and is it a worthwhile one?

Note: This question was originally posted on Stack Overflow. Unfortunately, I received no responses even after offering a bounty. Hence, I am uploading the question here. Link to the original post here.

• You can unroll the recursion, but it won't simplify much (if at all), as it is based on non-linear function composition, e.g. $y=f(g(h(i(j(x)))))$ where each of $f()$, $g()$ etc represents the function of a single layer. That's one of the main points for having layers - if there was something simpler possible, then deeper neural networks would not be as useful. Jul 19 at 9:56
• @NeilSlater That makes sense, thanks! Jul 19 at 11:05