问题描述
我的问题很简单.
如何使keras输出受到边界(最小和最大)的限制?
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.
我认为带有min_max_norm的Dense层上的kernel_constraint和bias_constraint可以工作,但事实证明这是行不通的.
I thought kernel_constraint and bias_constraint on Dense layer with min_max_norm will work but it turns out to be not working.
推荐答案
如果您可以牺牲激活函数的线性,那么这很容易,您可以使用Sigmoid来获得0到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
经过一点数学运算后,您会发现addConst = min/(max-min)
和multConst = (max-min)
And after a little bit of maths you will find that addConst = min/(max-min)
and multConst = (max-min)
但是请记住,您要放松最终激活层的线性度,如果要使其线性化,则必须完成整个功能,我知道这也是一种自定义激活,但是我相信这是最接近的开始使用内置的keras函数.
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.
这篇关于keras极限输出最小值最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!