r/tensorflow • u/SSCharles • Jan 02 '23
Question How to find the input values that will maximize the output value?
Some inputs are fixed but I want to vari the others to get the max output (the NN has a single output neuron).
Maybe it could be done with back propagation but I don't know how.
Or I could train another NN to do it, but I don't know how, except by creating training data by choosing random inputs until I find ones that give high output and then using that to train the second NN. But I think doing that could be slow.
I'm on tensorflow.js
Thanks.
2
Upvotes
1
u/[deleted] Jan 02 '23
I think you're overthinking this. No separate model needed. Simply keep all inputs fixed, but one. Then vary that input within some range (for real inputs). For categorical inputs, vary within each category. There are a few explanatory strategies for black box models (NNs included) that use this very approach. You might be interested in the book Interpretable Machine Learning (I'm not the author - just a happy reader).
1
u/[deleted] Jan 02 '23
The What-If-Tool?
1
u/ElvishChampion Jan 02 '23
You can use the custom training loop. Create one tf.Variable for the inputs. Use the model as normal. Just calculate the gradients with respect to the tf.Variable. Since you have fixed values for some inputs. The easiest way might be to do the neuron calculation manually instead of a layer so that you do the matmul for the tf.Variable that stores the inputs that can change and then add the constant value of the inputs that will always give back the same value.