{"action":"created","issue":{"url":"https://api.github.com/repos/torch/torch7/issues/165","labels_url":"https://api.github.com/repos/torch/torch7/issues/165/labels{/name}","comments_url":"https://api.github.com/repos/torch/torch7/issues/165/comments","events_url":"https://api.github.com/repos/torch/torch7/issues/165/events","html_url":"https://github.com/torch/torch7/issues/165","id":59574564,"number":165,"title":"bugs in multinomial?","user":{"login":"andresy","id":192030,"avatar_url":"https://avatars.githubusercontent.com/u/192030?v=3","gravatar_id":"","url":"https://api.github.com/users/andresy","html_url":"https://github.com/andresy","followers_url":"https://api.github.com/users/andresy/followers","following_url":"https://api.github.com/users/andresy/following{/other_user}","gists_url":"https://api.github.com/users/andresy/gists{/gist_id}","starred_url":"https://api.github.com/users/andresy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andresy/subscriptions","organizations_url":"https://api.github.com/users/andresy/orgs","repos_url":"https://api.github.com/users/andresy/repos","events_url":"https://api.github.com/users/andresy/events{/privacy}","received_events_url":"https://api.github.com/users/andresy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-03T00:09:16Z","updated_at":"2015-03-03T00:27:19Z","closed_at":null,"body":"Hi @nicholas-leonard \r\n\r\nLooking closely at multinomial, I see some strange behaviors...\r\n\r\n- when an error occurs, it seems to be modifying the tensor of probabilities passed by the user:\r\n```\r\n> p = torch.rand(10)\r\n> torch.multinomial(p, 3) -- ok\r\n> torch.multinomial(p, 11) -- oops, error\r\n> print(p:size())\r\n  1\r\n 10\r\n[torch.LongStorage of size 2]\r\n```\r\n  something wrong happened!\r\n\r\n- i am not sure it is completely mathematically correct. Or is there something wrong in the random number generator? I am not sure. But if you try the following at home, with C=10,..,60 it works quite fine. With C = 80 or above, you see some weird spiky artefacts which should not exist. Any idea?\r\n\r\n```\r\nrequire 'torch'\r\nrequire 'gnuplot'\r\n\r\ntorch.manualSeed(5555)\r\n\r\nlocal C = 80\r\nlocal N = 100000\r\n\r\n-- some unbalanced data\r\nlocal p = torch.Tensor(C)\r\nfor i=1,C do\r\n   p[i] = i\r\nend\r\nlocal x = torch.multinomial(p, N, true)\r\ngnuplot.axis{'','',0,''}\r\ngnuplot.hist(x)\r\n```\r\n\r\n![image](https://cloud.githubusercontent.com/assets/192030/6453778/9b5f9f5e-c0f6-11e4-9dfb-56705680bf49.png)\r\n"},"comment":{"url":"https://api.github.com/repos/torch/torch7/issues/comments/76861589","html_url":"https://github.com/torch/torch7/issues/165#issuecomment-76861589","issue_url":"https://api.github.com/repos/torch/torch7/issues/165","id":76861589,"user":{"login":"nicholas-leonard","id":3520613,"avatar_url":"https://avatars.githubusercontent.com/u/3520613?v=3","gravatar_id":"","url":"https://api.github.com/users/nicholas-leonard","html_url":"https://github.com/nicholas-leonard","followers_url":"https://api.github.com/users/nicholas-leonard/followers","following_url":"https://api.github.com/users/nicholas-leonard/following{/other_user}","gists_url":"https://api.github.com/users/nicholas-leonard/gists{/gist_id}","starred_url":"https://api.github.com/users/nicholas-leonard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicholas-leonard/subscriptions","organizations_url":"https://api.github.com/users/nicholas-leonard/orgs","repos_url":"https://api.github.com/users/nicholas-leonard/repos","events_url":"https://api.github.com/users/nicholas-leonard/events{/privacy}","received_events_url":"https://api.github.com/users/nicholas-leonard/received_events","type":"User","site_admin":false},"created_at":"2015-03-03T00:27:19Z","updated_at":"2015-03-03T00:27:19Z","body":"I have to update TREPL to see it trigger..."}}