# How to impose a constrained function on multiple output of a model with NeuralNet? [closed]

I work with R software, and I train a model with NeuralNet to predict several outputs.

My training data : it's a matrix with these column a,b,c,d,e,f,g,h.

(f,g,h) are my variables i want to predict.

Here is the formula of model : f+g+h ~ a+b+c+d+e

f,g and h are part of a composition having a sum of 1 or 100 in training data. But when my model predicts my multioutputs it is not a sum of 1.

My question is : how to impose on the model that my Multioutputs are a sum of 1 or 100 ? Is there a constraint function with neuralNet ?

Thank you very much for your help. :)

• You might do better on one of the R mailing lists. – mdewey May 11 '20 at 16:20
• The softmax function is constrained to sum to 1. Hence, $100 \times \text{softmax}(x)$ is constrained to sum to 100. But asking how to get software to do this is not an on-topic question here. – Sycorax May 13 '20 at 16:56
• Thank's. I'm new to machine learning, so, sorry if my question is not appropriate. I thought I understood that the Softmax functions is only for classification problem... My data is only numeric variables in my model. – Ziax May 13 '20 at 20:31

## 1 Answer

I think you are not using any activation function in the output layer. Use softmax as your activation function in the output layer, which will output probabilities of f,g,h that will sum to 1.

• Thank you for your reply. Here is my code: net1 <- neuralnet( f+g+h ~ a+b+c+d+e, train_data, hidden=c(5,3), threshold=0.1, linear.output = TRUE, algorithm = "backprop",learningrate = 0.0001,stepmax=1e6) I should use the "act.fct" function and integrate softmax into it ? – Ziax May 13 '20 at 16:23