-
Notifications
You must be signed in to change notification settings - Fork 132
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
mean_squared_error with ignore_nan
option
#190
Conversation
mottodora
commented
Jun 18, 2018
•
edited
Loading
edited
- fix test to chainer-chemistry style
- add double backward tests
- add documents
ignore_nan
optionignore_nan
option
"""Mean squared error (a.k.a. Euclidean loss) function.""" | ||
|
||
def __init__(self, ignore_nan=False): | ||
self.task_weight = None |
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.
Can you write
#TODO (mottodora): implement task weight calculation
so that others can understand it is simply not implemented yet?
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 forgot to delete this line. But I will write comments.
diff = x0 - x1 | ||
if self.ignore_nan: | ||
diff = chainer.functions.where(xp.isnan(diff.array), | ||
xp.zeros_like(diff.array), diff) |
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'm not sure but xp.zeros_like(diff.array)
can be just 0, in that case we can skip creating (allocating memory of) maybe large zero array.
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.
chainer where
function receive only same shape ndarray. (https://docs.chainer.org/en/stable/reference/generated/chainer.functions.where.html)
loss_expect += ((x0_data[i] - numpy.nan_to_num(x2_data[i])) ** 2 | ||
* nan_mask[i]) | ||
loss_expect /= x0_data.size | ||
assert numpy.allclose(loss_value, loss_expect) |
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.
Why did you use numpy.allclose
in this function, while pytest.approx
in check_forward
?
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 this. Thank you.
|
||
"""Mean squared error (a.k.a. Euclidean loss) function.""" | ||
|
||
def __init__(self, ignore_nan=False): |
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.
IMO, what "ignore" means can differ from people to people. So, I would suggest more descriptive option name "e.g. convert_nan_to_zero" or write what this option does in detail in the document.
Codecov Report
@@ Coverage Diff @@
## master #190 +/- ##
==========================================
+ Coverage 76.64% 77.08% +0.44%
==========================================
Files 87 89 +2
Lines 3712 3875 +163
==========================================
+ Hits 2845 2987 +142
- Misses 867 888 +21 |
LGTM. |
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.
LGTM except the comment.
return chainer_chemistry.functions.mean_squared_error(x0, x1, | ||
ignore_nan=True) | ||
gradient_check.check_backward(func, (x0_data, x2_data), None, eps=1e-2) | ||
|
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.
Could you add tests for backward and double backward with ignore_nan=True
using x0
and x1
?
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