1

My question is simple.

How do I make keras output to be limited with boundaries - min and max?

Some people suggest me to make a custom activation function to converts the output to transform in min and max values. I want it to be my last option.

I thought kernel_constraint and bias_constraint on Dense layer with min_max_norm will work but it turns out to be not working.

Isaac Sim
  • 539
  • 1
  • 7
  • 23

1 Answers1

1

If you can sacrifice the linearity of the activation function, then this is easy, you can use Sigmoid to get between 0 and 1 and then simply rescale your output, you will need to solve some equations to find the rescaling parameter which will be in the form

y_in_range = (y_pred + addConst)*multConst

And after a little bit of maths you will find that addConst = min/(max-min) and multConst = (max-min)

But remember you loose the linearity of your final activation layer, if you want it to be linear you have to make the entire function, I know this is also a sort of custom activation, but I believe this is the closest you will get to using an inbuilt keras function.

anand_v.singh
  • 2,768
  • 1
  • 16
  • 35
  • wow, its better than just multiplying sigmoid result * n . I will try to use it in keras if the function can be used right away – Isaac Sim Jan 31 '19 at 01:17