【问题标题】:How do I exclude bias from regularization using TensorFlow's `matrix_solve_ls`?如何使用 TensorFlow 的 `matrix_solve_ls` 从正则化中排除偏差?
【发布时间】:2017-09-06 19:11:27
【问题描述】:

给定一个design matrix(初始列1s对应一个偏差因子),我可以执行标准的NN-style L2-Regularized参数估计,其中only the weights are regularized,使用各种Python工具如

scipy.optimize.minimize(lambda p: np.mean((np.dot(dmat, p) - y_data)**2) + lamb*np.dot(p[1:], p[1:]), np.zeros(n_params).T).x

或

scipy.optimize.minimize(lambda p: np.mean((np.dot(dmat, p) - y_data)**2) + 2*lamb*tf.nn.l2_loss(p[1:]).eval(), np.zeros(n_params).T).x

但我认为没有办法使用 TensorFlow 的 tf.matrix_solve_ls 将偏差排除在正则化之外

tf.matrix_solve_ls(dmat, np.array([y_data]).T, l2_regularizer=lamb*len(dmat)).eval()

相当于

scipy.optimize.minimize(lambda p: np.mean((np.dot(dmat, p) - y_data)**2) + lamb*np.dot(p, p), np.zeros(n_params).T).x

如何使用tf.matrix_solve_ls从正则化中排除偏差(或者,通过构造,第一个参数)?

【问题讨论】:

  • 不确定是否使用tf.matrix_solve_ls,但我之前通过仅计算那些不包含“偏差”一词的变量的正则化项来完成此操作。比如reg_term = tf.norm([var for var in tf.trainable_variables() if not 'bias' in var.name])。

标签: python machine-learning tensorflow regularized


【解决方案1】:

很遗憾,当前版本的 matrix_solve_ls 无法做到这一点。另一方面,matrix_solve_ls 中的默认(快速)路径最近更改为简单的复合 Python 函数:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/linalg_ops.py#L293

您可以轻松地制作此代码的版本,其中 l2_regularizer 是一个向量(每个参数都有一个单独的值)。一般来说,在 matrix_solve_ls 中实现这样的泛化可能是一个好主意。也许您可以将此更改作为拉取请求提交?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-08
    • 1970-01-01
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    相关资源
    最近更新 更多