【问题标题】:Perceptron with weights of bounded condition number具有有界条件数权重的感知器
【发布时间】:2021-11-19 05:27:02
【问题描述】:

N 是一个(线性)单层感知器,其权重矩阵为 w,维度为 nxn

我想在条件数 k(w)的布尔约束下训练N在优化的每个步骤中,权重 w 保持在给定阈值 k_0 以下。

有没有标准的方法来实现这个约束(比如在 pytorch 中)?

【问题讨论】:

  • 我相信 PyTorch 中没有类似的内置功能。但它很容易实现。
  • 你可以添加一个正则化器来应用这样的约束。
  • 感谢@bobcat 和@Ivan!如果你们中的任何人详细说明了可能的此类实施的细节,我会接受作为答案。

标签: matrix optimization deep-learning neural-network pytorch


【解决方案1】:

在每个优化器步骤之后,检查参数列表并重新调整所有矩阵:

(代码看了几秒钟,但没有经过测试)

def recondition_(x, max_cond): # would need to be fixed for non-square x
    u, s, vh = torch.linalg.svd(x)
    curr_cond = s[0] / s[-1]
    if curr_cond > max_cond:
        ratio = curr_cond / max_cond
        mult = torch.linspace(0, math.log(ratio), len(s)).exp()
        s = mult * s
        x[:] = torch.mm(u, torch.mm(torch.diag(s), vh))

训练循环:

...
optimizer.step()

with torch.no_grad():
    for p in model.parameters():
        if p.dim() == 2:
            recondition_(p, max_cond)
...

【讨论】:

    猜你喜欢
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 2018-07-03
    • 1970-01-01
    • 2020-03-09
    • 2016-04-01
    相关资源
    最近更新 更多