{"action":"created","issue":{"url":"https://api.github.com/repos/chainer/chainer/issues/3429","repository_url":"https://api.github.com/repos/chainer/chainer","labels_url":"https://api.github.com/repos/chainer/chainer/issues/3429/labels{/name}","comments_url":"https://api.github.com/repos/chainer/chainer/issues/3429/comments","events_url":"https://api.github.com/repos/chainer/chainer/issues/3429/events","html_url":"https://github.com/chainer/chainer/pull/3429","id":258798809,"number":3429,"title":"Add order_sampler option to Iterators","user":{"login":"yuyu2172","id":2062128,"avatar_url":"https://avatars3.githubusercontent.com/u/2062128?v=4","gravatar_id":"","url":"https://api.github.com/users/yuyu2172","html_url":"https://github.com/yuyu2172","followers_url":"https://api.github.com/users/yuyu2172/followers","following_url":"https://api.github.com/users/yuyu2172/following{/other_user}","gists_url":"https://api.github.com/users/yuyu2172/gists{/gist_id}","starred_url":"https://api.github.com/users/yuyu2172/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuyu2172/subscriptions","organizations_url":"https://api.github.com/users/yuyu2172/orgs","repos_url":"https://api.github.com/users/yuyu2172/repos","events_url":"https://api.github.com/users/yuyu2172/events{/privacy}","received_events_url":"https://api.github.com/users/yuyu2172/received_events","type":"User","site_admin":false},"labels":[{"id":222603817,"url":"https://api.github.com/repos/chainer/chainer/labels/feature","name":"feature","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":{"login":"hvy","id":5983694,"avatar_url":"https://avatars2.githubusercontent.com/u/5983694?v=4","gravatar_id":"","url":"https://api.github.com/users/hvy","html_url":"https://github.com/hvy","followers_url":"https://api.github.com/users/hvy/followers","following_url":"https://api.github.com/users/hvy/following{/other_user}","gists_url":"https://api.github.com/users/hvy/gists{/gist_id}","starred_url":"https://api.github.com/users/hvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hvy/subscriptions","organizations_url":"https://api.github.com/users/hvy/orgs","repos_url":"https://api.github.com/users/hvy/repos","events_url":"https://api.github.com/users/hvy/events{/privacy}","received_events_url":"https://api.github.com/users/hvy/received_events","type":"User","site_admin":false},"assignees":[{"login":"hvy","id":5983694,"avatar_url":"https://avatars2.githubusercontent.com/u/5983694?v=4","gravatar_id":"","url":"https://api.github.com/users/hvy","html_url":"https://github.com/hvy","followers_url":"https://api.github.com/users/hvy/followers","following_url":"https://api.github.com/users/hvy/following{/other_user}","gists_url":"https://api.github.com/users/hvy/gists{/gist_id}","starred_url":"https://api.github.com/users/hvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hvy/subscriptions","organizations_url":"https://api.github.com/users/hvy/orgs","repos_url":"https://api.github.com/users/hvy/repos","events_url":"https://api.github.com/users/hvy/events{/privacy}","received_events_url":"https://api.github.com/users/hvy/received_events","type":"User","site_admin":false}],"milestone":null,"comments":16,"created_at":"2017-09-19T12:15:02Z","updated_at":"2018-04-25T07:26:50Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/chainer/chainer/pulls/3429","html_url":"https://github.com/chainer/chainer/pull/3429","diff_url":"https://github.com/chainer/chainer/pull/3429.diff","patch_url":"https://github.com/chainer/chainer/pull/3429.patch"},"body":"# Background\r\nThe current interface for iterators can not customize the order of indices.\r\nThis becomes problemetic when some kind of constraints need to be satisfied among indices of a batch.\r\nFor instance, there is no way to prevent a batch from containing more than two indices with the same value. In the current implementation, this can happen when a batch consists of indices from the end of a order and the beginning of the next order.\r\n\r\nThere needs to be an extra abstraction for sampling indices.\r\nInitially, I looked into the way PyTorch does this. https://github.com/pytorch/pytorch/blob/master/torch/utils/data/dataloader.py\r\nThey seem to get indices returned by an object called `batch_sampler`.\r\nIt looked nice, but after working on this direction for a while ([prototype](https://github.com/yuyu2172/chainer/tree/iterator-sampler)), I found that the functionalities of Chainer's iterators and PyTorch's DataLoader are a bit different.\r\n\r\nIn Chainer, we need to support serialization of the iterator.\r\nThis difference is significant because it requires the serialized iterator to recover the state any time, and we need to impose an extra interface requirements for `batch_sampler`.\r\nNamely, we need the `batch_sampler` to pass all information that is necessary to recover its state as well as indices to Iterator.\r\n\r\n# What this PR is\r\nI found that it is much more simple to customize a function to generate an order of indices to iterate.\r\nIn this approach, we assume the function to satisfy the following interaface:\r\n```python\r\n# current_order: An 1-D array of indices.\r\n# current_position: An integer indicating where the iterator is.\r\n# next_order: An 1-D array of indices.\r\ndef order_sampler(current_order, current_position):\r\n     ...\r\n    return next_order\r\n```\r\nI designed the interface so that all the state of an iterator is passed to the function.\r\nPassing `order` back and forth is nice because it requires little change in codebase, and there is no backward-incompatibility."},"comment":{"url":"https://api.github.com/repos/chainer/chainer/issues/comments/384186900","html_url":"https://github.com/chainer/chainer/pull/3429#issuecomment-384186900","issue_url":"https://api.github.com/repos/chainer/chainer/issues/3429","id":384186900,"user":{"login":"yuyu2172","id":2062128,"avatar_url":"https://avatars3.githubusercontent.com/u/2062128?v=4","gravatar_id":"","url":"https://api.github.com/users/yuyu2172","html_url":"https://github.com/yuyu2172","followers_url":"https://api.github.com/users/yuyu2172/followers","following_url":"https://api.github.com/users/yuyu2172/following{/other_user}","gists_url":"https://api.github.com/users/yuyu2172/gists{/gist_id}","starred_url":"https://api.github.com/users/yuyu2172/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuyu2172/subscriptions","organizations_url":"https://api.github.com/users/yuyu2172/orgs","repos_url":"https://api.github.com/users/yuyu2172/repos","events_url":"https://api.github.com/users/yuyu2172/events{/privacy}","received_events_url":"https://api.github.com/users/yuyu2172/received_events","type":"User","site_admin":false},"created_at":"2018-04-25T07:26:50Z","updated_at":"2018-04-25T07:26:50Z","author_association":"CONTRIBUTOR","body":"> --- I think below discussion can be done by other separated PR as well. ---\r\n\r\nI think this discussion should be done in another PR.\r\nThere other PRs that depend on this PR, and I think this should be merged quickly."}}
{"actor":{"display_login":"yuyu2172"}}