{"action":"created","issue":{"url":"https://api.github.com/repos/QuantEcon/QuantEcon.py/issues/137","labels_url":"https://api.github.com/repos/QuantEcon/QuantEcon.py/issues/137/labels{/name}","comments_url":"https://api.github.com/repos/QuantEcon/QuantEcon.py/issues/137/comments","events_url":"https://api.github.com/repos/QuantEcon/QuantEcon.py/issues/137/events","html_url":"https://github.com/QuantEcon/QuantEcon.py/issues/137","id":68121516,"number":137,"title":"Numba version of mc_sample_path","user":{"login":"oyamad","id":7353083,"avatar_url":"https://avatars.githubusercontent.com/u/7353083?v=3","gravatar_id":"","url":"https://api.github.com/users/oyamad","html_url":"https://github.com/oyamad","followers_url":"https://api.github.com/users/oyamad/followers","following_url":"https://api.github.com/users/oyamad/following{/other_user}","gists_url":"https://api.github.com/users/oyamad/gists{/gist_id}","starred_url":"https://api.github.com/users/oyamad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oyamad/subscriptions","organizations_url":"https://api.github.com/users/oyamad/orgs","repos_url":"https://api.github.com/users/oyamad/repos","events_url":"https://api.github.com/users/oyamad/events{/privacy}","received_events_url":"https://api.github.com/users/oyamad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":35,"created_at":"2015-04-13T15:08:53Z","updated_at":"2015-04-27T11:11:04Z","closed_at":null,"body":"Hi all,\r\nI played further with Numba, by numba-fying? [`mc_sample_path`](https://github.com/QuantEcon/QuantEcon.py/blob/master/quantecon/mc_tools.py#L279).\r\nThe code and performance tests are found [here](http://nbviewer.ipython.org/github/oyamad/mc_sample_path_numba/blob/master/mc_sample_path_numba02.ipynb).\r\n\r\nThe Numba version can be more than 100x faster than the original `qe.mc_sample_path` depending on the problem size (and the environment).\r\n\r\n0. Cell [3] contains the Numba version `mc_sample_path` and the NumPy version `mc_sample_path_numpy`, which follows implementation approach 1 in [@albop 's comment](https://github.com/QuantEcon/QuantEcon.py/issues/132#issuecomment-90955976).\r\n\r\n0. `mc_sample_path_2` in cell [15] follows the approach of Code 1 in [my comment](https://github.com/QuantEcon/QuantEcon.py/issues/132#issuecomment-90792658).\r\n\r\nAs always, there is a tradeoff in introducing Numba: speed v.s. clarity/transparency. Would the use of Numba be justified in this case?\r\n\r\nSome remarks:\r\n\r\n* The main bottleneck in the original `qe.mc_sample_path`, compared to the NumPy version, is in random sampling, which is done for `sample_size` times. The NumPy version is faster as it calls a random sampling routine only once, with size= sample_size.\r\n\r\n* It is interesting that the speed of the original and the NumPy versions, both of which rely on [`np.searchsorted`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.searchsorted.html), is almost constant in the size of the matrix.\r\n"},"comment":{"url":"https://api.github.com/repos/QuantEcon/QuantEcon.py/issues/comments/96611253","html_url":"https://github.com/QuantEcon/QuantEcon.py/issues/137#issuecomment-96611253","issue_url":"https://api.github.com/repos/QuantEcon/QuantEcon.py/issues/137","id":96611253,"user":{"login":"mmcky","id":8263752,"avatar_url":"https://avatars.githubusercontent.com/u/8263752?v=3","gravatar_id":"","url":"https://api.github.com/users/mmcky","html_url":"https://github.com/mmcky","followers_url":"https://api.github.com/users/mmcky/followers","following_url":"https://api.github.com/users/mmcky/following{/other_user}","gists_url":"https://api.github.com/users/mmcky/gists{/gist_id}","starred_url":"https://api.github.com/users/mmcky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmcky/subscriptions","organizations_url":"https://api.github.com/users/mmcky/orgs","repos_url":"https://api.github.com/users/mmcky/repos","events_url":"https://api.github.com/users/mmcky/events{/privacy}","received_events_url":"https://api.github.com/users/mmcky/received_events","type":"User","site_admin":false},"created_at":"2015-04-27T11:11:04Z","updated_at":"2015-04-27T11:11:04Z","body":"@jstac I should have documented what I had tried.  I tried using ``np.random.seed()`` but that didn't seem to work. I wasn't sure if that is because ``mc_sample_path`` uses ``np.random.random()`` - but I will look into it further. \r\n\r\nWe can run with a ``utilities.py`` module for now. If we need to we can always refactor down the track into a sub-package. \r\n"}}