具有有界条件数权重的感知器

Perceptron with weights of bounded condition number

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

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

是否有实现此约束的标准方法(例如在 pytorch 中)?

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

(代码看了几秒,没测试)

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)
...