Machine learning 如何在成本函数中包含参数向量之间的相关性?

Machine learning 如何在成本函数中包含参数向量之间的相关性?,machine-learning,pytorch,regularized,Machine Learning,Pytorch,Regularized,我有以下型号: class Model(nn.Module): def __init__(self, dim_in, lambda_=.3): super(FeatExtractorGR, self).__init__() '''The linear transform layer''' self.lt = nn.Linear(in_features = dim_in, out_features = 10, bias=True)

我有以下型号:

class Model(nn.Module):
    def __init__(self, dim_in, lambda_=.3):
        super(FeatExtractorGR, self).__init__()

       '''The linear transform layer'''
        self.lt = nn.Linear(in_features = dim_in, out_features = 10, bias=True)
    
    '''The encoder'''
    self.feature_extractor = \
        nn.Sequential(
            #nn.Linear(in_features = 10, out_features = 30, bias=True),
            nn.BatchNorm1d(10),
            nn.ReLU(),
            nn.Linear(in_features = 10, out_features = 20, bias=True),
            nn.BatchNorm1d(20),
            nn.ReLU(),
            nn.Linear(in_features = 20, out_features = 10, bias=True),
            nn.BatchNorm1d(10),
            nn.ReLU()
        )

def forward(self, x):
    transformed = self.lt(x)
    return self.feature_extractor(transformed)
我想强制线性变换层的权重向量不相关。我试图在成本函数的向量中包含点积:

        params=list(model.lt.parameters())[0]
        dotprod=torch.tensordot(params, params, dims=([1],[1])).abs().fill_diagonal_(0).sum()/2

        loss = other_losses + dotprod * weight

但这不起作用,即使重量非常高。
lt
层的权重向量仍然高度相关。我还试图消除其他损失,但没有效果。我做错了什么?

首先,试着消除
其他损失
,看看在你只关心相关性的情况下,它是否能起作用。这将更好地表明你的问题出在哪里,没有效果。我认为你的“相关性”公式有问题。随机变量X和Y之间的协方差是
Cov(X,Y)=E(XY)-E(X)E(Y)
,你的损失只考虑
E(XY)
项,不是吗。此外,为了使它成为一个相关性,你必须除以X和Y的偏差(但我认为这并不重要,因为训练是正确的),我用点积近似相关性,以降低计算复杂度。但这在国际海事组织也应该起作用