Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

mean_squared_error with ignore_nan option #190

Merged
merged 12 commits into from
Jun 22, 2018

Conversation

mottodora
Copy link
Member

@mottodora mottodora commented Jun 18, 2018

  • fix test to chainer-chemistry style
  • add double backward tests
  • add documents

@mottodora mottodora changed the title [WIP] mean_squared_error with ignore_nan option mean_squared_error with ignore_nan option Jun 19, 2018
"""Mean squared error (a.k.a. Euclidean loss) function."""

def __init__(self, ignore_nan=False):
self.task_weight = None
Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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)

@delta2323 delta2323 self-requested a review June 20, 2018 12:41
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)
Copy link
Member

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?

Copy link
Member Author

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):
Copy link
Member

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-io
Copy link

codecov-io commented Jun 21, 2018

Codecov Report

Merging #190 into master will increase coverage by 0.44%.
The diff coverage is 88.34%.

@@            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

@corochann
Copy link
Member

LGTM.
Can you check? @delta2323

Copy link
Member

@delta2323 delta2323 left a 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)

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

@delta2323 delta2323 merged commit ea10e10 into chainer:master Jun 22, 2018
@mottodora mottodora deleted the mse-ignore-nan branch June 27, 2018 07:23
@mottodora mottodora added this to the 0.4.0 milestone Jul 3, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants