Exemple #1
0
 def __init__(self, deviations, exponent, weights=None):
     super(_WeightedPower, self).__init__()
     self.deviations = util.to_tensor(deviations)
     if weights is None:
         weights = 1.0 / deviations.pow(2)
     self.exponent = util.to_tensor(exponent, device=self.deviations.device)
     self.weights = util.to_tensor(weights, device=self.deviations.device)
Exemple #2
0
 def __init__(self, weights, threshold=0.5):
     if threshold < 0:
         raise ValueError("Threshold must be nonnegative, received ",
                          threshold)
     super(Huber, self).__init__()
     self.weights = util.to_tensor(weights)
     self.threshold = threshold
Exemple #3
0
 def __init__(self, weights, exponent=1):
     if not (weights <= 0).all():
         raise ValueError("Weights must be negative.")
     super(InvPower, self).__init__()
     self.weights = util.to_tensor(weights)
     if not isinstance(exponent, torch.Tensor):
         exponent = torch.tensor(exponent)
     self.exponent = exponent
Exemple #4
0
def test_to_tensor():
    args = [0.0, np.array(1.0), torch.tensor(2.0)]
    tensors = util.to_tensor(args)
    for t, arg in zip(tensors, args):
        assert isinstance(t, torch.Tensor)
        assert t.item() == float(arg)
        assert str(t.device) == "cpu"
    assert id(tensors[-1]) == id(args[-1])
Exemple #5
0
 def __init__(self, weights, threshold, alpha=1.0):
     if threshold < 0:
         raise ValueError("Threshold must be nonnegative, received ",
                          threshold)
     super(Sigmoid, self).__init__()
     self.weights = util.to_tensor(weights)
     self.threshold = threshold
     self.alpha = alpha
Exemple #6
0
 def __init__(self, weights, threshold, sigma=None):
     if threshold < 0:
         raise ValueError("Threshold must be nonnegative, received ",
                          threshold)
     if sigma is None:
         sigma = threshold / 2
     super(Hinge, self).__init__()
     self.weights = util.to_tensor(weights)
     self.threshold = threshold
     self.sigma = sigma
Exemple #7
0
 def __init__(self,
              weights,
              attractive_penalty=Log1p,
              repulsive_penalty=LogRatio):
     super(PushAndPull, self).__init__()
     self.weights = util.to_tensor(weights)
     if weights.nelement() == 1:
         raise ValueError("`PushAndPull` requires at least two weights.")
     self.pos_idx = weights >= 0
     self.attractive_penalty = attractive_penalty(weights[self.pos_idx])
     self.repulsive_penalty = repulsive_penalty(weights[~self.pos_idx])
Exemple #8
0
 def __init__(self, deviations):
     super(Quadratic, self).__init__()
     self.deviations = util.to_tensor(deviations)
Exemple #9
0
 def __init__(self, deviations, exponent):
     super(_Log1p, self).__init__()
     self.deviations = util.to_tensor(deviations)
     self.exponent = util.to_tensor(exponent, device=self.deviations.device)
Exemple #10
0
 def __init__(self, deviations, gamma=10.0):
     super(SoftFractional, self).__init__()
     self.deviations = util.to_tensor(deviations)
     self.gamma = util.to_tensor(gamma, device=self.deviations.device)
     if gamma <= 0.0:
         raise ValueError("gamma must be positive, received ", float(gamma))
Exemple #11
0
 def __init__(self, deviations):
     super(Fractional, self).__init__()
     self.deviations = util.to_tensor(deviations)
Exemple #12
0
 def __init__(self, deviations):
     super(Absolute, self).__init__()
     self.deviations = util.to_tensor(deviations)
Exemple #13
0
 def __init__(self, weights, threshold):
     super(_ClippedQuadratic, self).__init__()
     self.weights = util.to_tensor(weights)
     self.threshold = threshold
Exemple #14
0
 def __init__(self, deviations, threshold):
     super(Huber, self).__init__()
     self.deviations = util.to_tensor(deviations)
     self.threshold = threshold
Exemple #15
0
 def __init__(self, weights):
     super(Linear, self).__init__()
     self.weights = util.to_tensor(weights)
Exemple #16
0
 def __init__(self, deviations, weights=None):
     super(WeightedQuadratic, self).__init__()
     self.deviations = util.to_tensor(deviations)
     if weights is None:
         weights = 1.0 / deviations.pow(2)
     self.weights = util.to_tensor(weights, device=self.deviations.device)
Exemple #17
0
 def __init__(self, weights, exponent=1.0):
     super(Log, self).__init__()
     self.weights = util.to_tensor(weights)
     if not isinstance(exponent, torch.Tensor):
         exponent = torch.tensor(exponent, device=weights.device)
     self.exponent = exponent
Exemple #18
0
 def __init__(self, weights):
     super(Cubic, self).__init__()
     self.weights = util.to_tensor(weights)
Exemple #19
0
 def __init__(self, weights, threshold):
     super(_DeadzoneCubic, self).__init__()
     self.weights = util.to_tensor(weights)
     self.threshold = threshold
Exemple #20
0
 def __init__(self, deviations, threshold):
     super(_ClippedQuadratic, self).__init__()
     self.deviations = util.to_tensor(deviations)
     self.threshold = threshold
Exemple #21
0
 def __init__(self, weights, exponent=2):
     super(LogRatio, self).__init__()
     self.weights = util.to_tensor(weights)
     if not isinstance(exponent, torch.Tensor):
         exponent = torch.tensor(exponent)
     self.exponent = exponent