简体   繁体   English

具有正映射的线性回归

[英]Linear regression with positive mapping

I am using Tensorflow for my research. 我正在使用Tensorflow进行研究。 Recently, I am trying to implement a linear regression in Tensorflow using least squares with positive mapping K, ie, min ||y-Kx|| 最近,我试图使用具有正映射K的最小二乘法在Tensorflow中实现线性回归,即min || y -Kx || such that all elements of K are positive values, where x and y are vectors which are mapped through the matrix K. Basically, I want to enforce the trainable variables K to be positive when implementing it in Tensorflow. 这样K的所有元素都是正值,其中x和y是通过矩阵K映射的向量。基本上,我想在Tensorflow中实现它时强制训练变量K为正。

I've searching for a good way to implement it in Tensorflow. 我正在寻找一种在Tensorflow中实现它的好方法。 Some articles suggest to use tf.clip_by_value, but it is likely to have bunch of zero entries in K. I've found tf.Variable has "constraint" argument which seems to do projection of solution onto a constrained space, but I haven't been able to find a good example to follow for my case. 一些文章建议使用tf.clip_by_value,但它可能在K中有一堆零条目。我发现tf.Variable有“约束”参数,似乎将解决方案投影到受约束的空间,但我没有'为我的案子找到了一个很好的例子。

I would appreciate any suggestion to enforce positive values for trainable variables in Tensorflow. 我将不胜感激任何建议在Tensorflow中强制执行可训练变量的正值。 Thank you for your help in advance. 提前谢谢你的帮助。

Note that constraint : 注意约束

constraint function that is applied after the update of the optimizer . 更新优化程序后应用的约束函数 (eg used to implement norm constraints or value constraints for layer weights) (例如,用于实现层权重的范数约束或值约束)

This means that, following variables all have the same value before update of the optimizer: 这意味着,在更新优化器之前,以下变量都具有相同的值:

myVar1 = tf.Variable([1,-1,2],constraint=lambda x: tf.clip_by_value(x, 0, np.infty))
myVar2 = tf.Variable([1,-1,2],constraint=lambda x: tf.abs(x))
myVar3 = tf.Variable([1,-1,2],constraint=lambda x: tf.clip_by_norm(x,axis=-1))

Another things worth to mention is that, you can also define your own constraint as well: 另外值得一提的是,您也可以定义自己的约束:

def my_constrain(x):
    x = tf.abs(x)
    return tf.clip_by_value(x, 0, 0.5)

a = tf.get_variable(name='a', initializer=0., constraint=lambda x: my_constrain(x))

Another suggestion that you can consider is regularization for a specific parameter. 您可以考虑的另一个建议是针对特定参数进行正则化。 For example, adaptive Lasso ( H.Zou, JASA 2006, Vol. 101, No. 476 ) achieves consistency in parameter estimates by using individual lambda for each variable. 例如,自适应Lasso( H.Zou,JASA 2006,第101卷,第476号 )通过对每个变量使用单个lambda来实现参数估计的一致性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM