pytorch 用于复数值的Pytroch钳

os8fio9y  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(85)

我试图使用钳位,但它不工作,因为我有一个复杂的和真实的值的混合。有没有什么东西可以像clamp一样工作,但只适用于真实的和复杂的值?我试着查了一些,除了夹子什么也没查到。

e0bqpujr

e0bqpujr1#

我最终使用HardTanh与如下设置

for key, bounds in self.coefficient_bounds.items():
    min_value, max_value = bounds
    m = torch.nn.Hardtanh(min_value, max_value)
    # the input needs to be a tensor so we have to convert
    # custom_pauli_coefficients[key] to a tensor
    input = torch.tensor(custom_pauli_coefficients[key])
    custom_pauli_coefficients[key] = m(input)

相关问题