-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Random MarkovChain #154
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
Random MarkovChain #154
Conversation
…rated Maybe put in utilities.py
@oyamad Neat - It will be good to have this for easily creating some matrix for testing or demonstration etc. Regarding the name. What do you think about just mimicking the np structure by adding a random subpackage or module? We could then use the hierarchy of the package to capture the essence contained in the name import quantecon as qe
qe.random.choice(n, k, replace=False) |
@mmcky Thank you for your comments. It is a good idea to make it parallel to NumPy, which would make the names easier to remember. Just for information:
|
@oyamad Thanks for the additional info - good to know. Given how much Happy to help re-package this as a subpackage if you like. |
@mmcky Please feel free to edit the branch, thanks! Maybe we would better fix the interface for |
…ies and add check_random_state
See also issue #153
|
I think this PR is ready for merging. Importantly, this contains the feature of (Sparse matrix support and renaming and moving |
Add the same test case as in the Julia version
Match with the Julia version QuantEcon/QuantEcon.jl#63
Hi @oyamad - Sorry for my delay. Just reacquainting myself with this issue. This is looking good. Are you still happy for this to be merged? I see that nosetests is reporting all OK for |
Does this need to be updated prior to merge?
|
@oyamad I am happy to move code around to fulfil the checkbox above. I wanted to run a few things by you before I implement this:
Thanks |
1, 2: Please do go ahead as you suggest. 3, 4: @jstac once mentioned having a subpackage (say |
I support having a I feel that names like |
… for now as used in examples
@oyamad I only came across one instance of |
@oyamad I think the reorganisation is complete. When you have some time - it would be great if you could have a quick look at the branch. Once that is done we should go ahead and get approval to merge. |
@mmcky Many thanks! I will have a closer look tomorrow, but one quick comment: maybe |
@oyamad Great thanks. I have moved |
@mmcky Thanks! It seems that |
instead of random_probvec, random_sample_without_replacement from ..util
move test_sample_without_replacement_* from markov/tests to util/tests
I made a few changes:
|
…ing relevant utility functions from the utilities subpackage which is geared more towards internal utilities and package infrastructure
@oyamad These are excellent points. I have discussed with @jstac today and we have decided to do a bit more reorganisation. The qe.random.probvec()
qe.random.sample_without_replacement() Thanks for updating the examples section, I had only focused on the I have moved associated tests |
…ccomodate new subpackage
@mmcky Very good, thanks. I am now very happy with this PR. This is an independent issue probably for another PR: some other files might also be moved to
|
Great thanks for the feedback @oyamad. Good idea re: migration to |
What are the chances we can rename the If we do this, then I am happy to rewrite (or find my code) to do the Rouwenhorst approximation as well and can drop it in there. |
@cc7768 Good idea. I will do this revision as part of this PR. Let's add Rouwenhorst approximation in another PR. Having a look at |
Merging this issue now. Thanks @oyamad for this addition. Thanks everyone for comments and suggestions. |
Random MarkovChain and some Reorganisation of Repository into ``util``, ``markov`` and ``random`` sub packages.
(This is not yet ready to merge.)I wrote some functions that generate random
MarkovChain
or stochastic matrix. I hope this module will be useful at least for developers and probably for users as well.random_probvec
generates random probability vectors (whose entries are nonnegative and sum to one). (Note that just generating random numbers from [0, 1] and divide them by the sum would generate probability values that are skewed toward 0.5.)random_choice_without_replacement
.random_markov_chain
will support sparse matrix format onceMarkovChain
does.random_choice_without_replacement(n, k, num_trials=None)
is equivalent tonp.random.choice(n, k, replace=False)
and is much (100x?) faster with Numba.random_choice_without_replacement
may be included inutilities.py
. Its name seems too long. Anybody have any idea?random_state
will be modified once we fix a common interface (I opened a new issue Option to supply a random seed #153 to discuss this).