machine-learning - 如何在成本函数中包含参数向量之间的相关性?
问题描述
我有以下模型:
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
但这不起作用,即使非常高weight
。该lt
层的权重向量仍然高度相关。我也试过删除other_losses
,但没有效果。我究竟做错了什么?
解决方案
推荐阅读
- ansible - 是否可以在 Ansible 剧本中为 JAR 文件名使用通配符?
- java - 如何“分组” if 语句以在 Android Studio 的微调器中使用?
- dart - 寻找具有不同时区的 2 个 DateTime 对象的差异?
- javascript - Parsley JS 不等于多个 ID
- javascript - 无法添加第二个选择范围(谷歌浏览器)
- c# - 如何将 Firebase 实时数据库连接到我的 C# 项目?
- java - @JsonView 不为 Spark 中部署的 Spring Boot 应用程序渲染
- php - Drupal 8 创建 XML 队列
- rust - rust 语言如何处理控制台输入?
- mixed-integer-programming - 使用 Time Windows 进行一维装箱