New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reduce option to decov #2698
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check comments
chainer/functions/loss/decov.py
Outdated
cost = xp.vdot(self.covariance, self.covariance) * h.dtype.type(0.5) | ||
return utils.force_array(cost), | ||
if self.reduce == 'half_frobenius_norm': | ||
cost = xp.vdot(self.covariance, self.covariance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is sqrt
required for frobenius norm, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. I think it is better to provide squared norm (like MSE). So, I change the option to 'half_squared_frobenius_norm'
.
Args: | ||
h (Variable): Variable holding a matrix where the first dimension | ||
corresponds to the batches. | ||
recude (str): Reduction option. Its value must be either |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix
loss_shape = () | ||
else: | ||
loss_shape = (3, 3) | ||
self.assertEqual(loss.data.shape, loss_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use self.gloss.shape
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel 'half_squared_frobenius_norm'
is long.
chainer/functions/loss/decov.py
Outdated
@@ -10,9 +10,14 @@ class DeCov(function.Function): | |||
|
|||
"""DeCov loss (https://arxiv.org/abs/1511.06068)""" | |||
|
|||
def __init__(self): | |||
def __init__(self, reduce='half_squared_frobenius_norm'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about 'half_squared_sum'
?
LGTM |
This PR adds
reduce
option toF.Decov
andF.decov
. Related to #2558