Documentation for v0.1 version (#199)
* Adding Equations, solving typos * improve _code.rst * the team rst and restuctore index.rst * fixing errors --------- Co-authored-by: Dario Coscia <dariocoscia@dhcp-015.eduroam.sissa.it>
This commit is contained in:
committed by
Nicola Demo
parent
3f9305d475
commit
8b7b61b3bd
@@ -16,34 +16,33 @@ def test_LpLoss_constructor():
|
||||
for p in [float('inf'), -float('inf'), 1, 10, -8]:
|
||||
LpLoss(p=p)
|
||||
|
||||
|
||||
def test_LpLoss_forward():
|
||||
# l2 loss
|
||||
loss = LpLoss(p=2, reduction='mean')
|
||||
l2_loss = torch.mean(torch.sqrt((input-target).pow(2)))
|
||||
l2_loss = torch.mean(torch.sqrt((input - target).pow(2)))
|
||||
assert loss(input, target) == l2_loss
|
||||
# l1 loss
|
||||
loss = LpLoss(p=1, reduction='sum')
|
||||
l1_loss = torch.sum(torch.abs(input-target))
|
||||
l1_loss = torch.sum(torch.abs(input - target))
|
||||
assert loss(input, target) == l1_loss
|
||||
|
||||
|
||||
def test_LpRelativeLoss_constructor():
|
||||
# test reduction
|
||||
for reduction in available_reductions:
|
||||
LpLoss(reduction=reduction, relative=True)
|
||||
# test p
|
||||
for p in [float('inf'), -float('inf'), 1, 10, -8]:
|
||||
LpLoss(p=p,relative=True)
|
||||
LpLoss(p=p, relative=True)
|
||||
|
||||
|
||||
def test_LpRelativeLoss_forward():
|
||||
# l2 relative loss
|
||||
loss = LpLoss(p=2, reduction='mean',relative=True)
|
||||
l2_loss = torch.sqrt((input-target).pow(2))/torch.sqrt(input.pow(2))
|
||||
loss = LpLoss(p=2, reduction='mean', relative=True)
|
||||
l2_loss = torch.sqrt((input - target).pow(2)) / torch.sqrt(input.pow(2))
|
||||
assert loss(input, target) == torch.mean(l2_loss)
|
||||
# l1 relative loss
|
||||
loss = LpLoss(p=1, reduction='sum',relative=True)
|
||||
l1_loss = torch.abs(input-target)/torch.abs(input)
|
||||
loss = LpLoss(p=1, reduction='sum', relative=True)
|
||||
l1_loss = torch.abs(input - target) / torch.abs(input)
|
||||
assert loss(input, target) == torch.sum(l1_loss)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,34 +16,33 @@ def test_PowerLoss_constructor():
|
||||
for p in [float('inf'), -float('inf'), 1, 10, -8]:
|
||||
PowerLoss(p=p)
|
||||
|
||||
|
||||
def test_PowerLoss_forward():
|
||||
# l2 loss
|
||||
loss = PowerLoss(p=2, reduction='mean')
|
||||
l2_loss = torch.mean((input-target).pow(2))
|
||||
l2_loss = torch.mean((input - target).pow(2))
|
||||
assert loss(input, target) == l2_loss
|
||||
# l1 loss
|
||||
loss = PowerLoss(p=1, reduction='sum')
|
||||
l1_loss = torch.sum(torch.abs(input-target))
|
||||
l1_loss = torch.sum(torch.abs(input - target))
|
||||
assert loss(input, target) == l1_loss
|
||||
|
||||
|
||||
def test_LpRelativeLoss_constructor():
|
||||
# test reduction
|
||||
for reduction in available_reductions:
|
||||
PowerLoss(reduction=reduction, relative=True)
|
||||
# test p
|
||||
for p in [float('inf'), -float('inf'), 1, 10, -8]:
|
||||
PowerLoss(p=p,relative=True)
|
||||
PowerLoss(p=p, relative=True)
|
||||
|
||||
|
||||
def test_LpRelativeLoss_forward():
|
||||
# l2 relative loss
|
||||
loss = PowerLoss(p=2, reduction='mean',relative=True)
|
||||
l2_loss = (input-target).pow(2)/input.pow(2)
|
||||
loss = PowerLoss(p=2, reduction='mean', relative=True)
|
||||
l2_loss = (input - target).pow(2) / input.pow(2)
|
||||
assert loss(input, target) == torch.mean(l2_loss)
|
||||
# l1 relative loss
|
||||
loss = PowerLoss(p=1, reduction='sum',relative=True)
|
||||
l1_loss = torch.abs(input-target)/torch.abs(input)
|
||||
loss = PowerLoss(p=1, reduction='sum', relative=True)
|
||||
l1_loss = torch.abs(input - target) / torch.abs(input)
|
||||
assert loss(input, target) == torch.sum(l1_loss)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user