2

I'm training a Neural Network that, given some inputs that here we'll call x and y, is able to predict the output, z. So, z=f(x,y) Once the neural network is correctly trained, I'd like to be able to obtain a model that, given z and x, returns the other input: What i mean is to obtain the model for which: y=g(x,z) Is it possible in Tensorflow? Thak you in advance!

2 Answers2

2

This question kinda put me in a dilemma.

If you think it theoretically it should be possible if and only if your network has no non-linearities like ReLU and has weight matrices( plus bias) which is invertible, it is possible. However matrix multiplication is still a problem as your dimension increases.

But in practice, machine learning models tend to generalize the problem with the given input. So if you can build a model for f(x,y) then you can build another model for g(x,z) as the problem do not differ that much. If you think about complex models, it will not be practical. Also doing this does not make sense to me. There would be loss in the knowledge.

So even if you can do it, it requires lots of extra work. In my opinion it does not worth the prize. Going for a new model should be less painful.

Frightera
  • 4,773
  • 2
  • 13
  • 28
2

You cannot invert a generic nonlinear NN, however there is a NN architecture that will allow you to do this trivially (first proposed here, section 3.2 https://arxiv.org/pdf/1605.08803.pdf).

Basically, you split the input to 2 vectors, u1 and u2, and then transform it like this:

v1 = f1(u2) + g1(u2)u1

v2 = u2

Then, the inverse is:

u1 = (v1 - f(v2)) / g(v2)

u2 = v2

Note that to calculate an inverse a division by g is used (multiplication by g inverse), so you have to make sure that the inverse of g exists.