# Neural Network and Enforce Positive Vector

I am trying to implement a neural network where I output a vector of 5 parameters each of which I know to be positive. I have code that works where I end up with an "Output" -> 5.'

However, after training the network, it is often finding good results setting one of these values to be negative. However, physically that is not possible.

Is there a way to change my cost function to enforce (or encourage) positive values?

• There is probably a way, yes. – anderstood Feb 15 '18 at 20:37
• why not add a term to the cost function that vanishes for positive outputs and penalized negative outputs? – yohbs Feb 15 '18 at 21:09
• A penalty like Total[Ramp[-x]^2] should do, where x is the parameter vector. Also, a barrier like -Total[Log[-x]]` might do it. Hard to say without detailed code... – Henrik Schumacher Feb 15 '18 at 22:18
• Another option is to use an activation function for the last layer where the range of the function matches the range of the expected output. e.g. you would often see a sigmoid function if the outputs are probabilities with range 0..1 – Niki Estner Feb 16 '18 at 10:53