I'm using TensorFlow. I have many simulated datasets for which values are real. Each one consists of 200 rows and two columns (variables). I'm using a convolutional neural net. I want the simulated data to be the input, and the three parameters in the model that I use to generate that data to be the output. These parameters must be positive. One of them specifically is usually a small fraction. I am using the below code, but the parameter that's usually a small fraction sometimes has negative predicted values. What changes can I make to restrict it to being at least zero? Thanks!
model=models.Sequential()
model.add(layers.Conv1D(32,3, activation='relu', input_shape=(200, 2)))
model.add(layers.MaxPooling1D(2))
model.add(layers.Conv1D(64, 3, activation='relu'))
model.add(layers.MaxPooling1D(2))
model.add(layers.Conv1D(128, 3, activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(3))
It looks like the problem is that your output layer doesn’t have an activation function, which is why you’re getting negative values sometimes. To make sure the outputs are always positive, you can use the softplus
activation:
model.add(layers.Dense(3, activation='softplus'))