QuantEcon / QuantEcon.notebooks

Jupyter notebooks contributed by QuantEcon developers, users and the community
BSD 3-Clause "New" or "Revised" License
122 stars 105 forks source link

Add markov_chain_ex01_jl.ipynb #63

Closed nswa17 closed 6 years ago

nswa17 commented 6 years ago

Add julia translation of markov_chain_ex01_py.ipynb.

oyamad commented 6 years ago

@nswa17 I have a few comments on your PR. Can we talk tomorrow during the office hours?

oyamad commented 6 years ago

One question: What is the "scope" of srand(12345)? Is it effective for the whole session on the notebook?

sglyon commented 6 years ago

Yep, srand sets the seed on Julia's global RNG.

If you want to isolate its effects you can construct your own instance of a RNG (e.g MersenneTwister(0)) and then call srand on that.

julia> methods(srand)
# 9 methods for generic function "srand":
srand() in Base.Random at random.jl:244
srand(r::MersenneTwister) in Base.Random at random.jl:232
srand(r::MersenneTwister, seed::Array{UInt32,1}) in Base.Random at random.jl:145
srand(r::MersenneTwister, n::Integer) in Base.Random at random.jl:233
srand(r::MersenneTwister, filename::AbstractString) in Base.Random at random.jl:234
srand(r::MersenneTwister, filename::AbstractString, n::Integer) in Base.Random at random.jl:234
srand(seed::Union{Array{UInt32,1}, Integer}) in Base.Random at random.jl:249
srand(filename::AbstractString) in Base.Random at random.jl:254
srand(filename::AbstractString, n::Integer) in Base.Random at random.jl:254
oyamad commented 6 years ago

@sglyon Thanks.

What's the "best practice" in Julia for reproducibility with code involving randomness, if any? In QE.py, some routines encourage to use a random_state option; e.g., see this notebook below cell [21] (also QuantEcon/QuantEcon.py#153).

We once discussed this in a different issue QuantEcon/QuantEcon.jl#63. Do we want to have an rng option in functions with randomness in QE.jl?

sglyon commented 6 years ago

Sorry for the delay in responding here.

I don’t think there is a best practice yet...

As you say, we could have all the routines take an optional argument rng of type RNG (An abstract type that all random number generators subtype).

The workaround right now is that users set the seed on the global RNG before each call to one of quantecon’s routines with randomness. I’m not sure how many people would take advantage of the rng option on these functions. If there wouldn’t be many, mabye it isn’t worth the hassle?

If you can’t tell, I don’t yet have a concrete opinion on this issue yet.

oyamad commented 6 years ago

@sglyon Thanks. For this particular case of this notebook, I think we shouldn't make any comment on reproducibility. (The main purpose of the corresponding comment in the Python version is to explain the random_state option.)

nswa17 commented 6 years ago

I have a question on the header of notebooks. Are there any general rules of author in Quantecon.notebooks? Especially for the typical case of translation from an existing notebook?

oyamad commented 6 years ago
nswa17 commented 6 years ago

I'm sorry to forget to use defined prettyprint function in cell Ln[55]. Also I changed the name of variable pi in cells into psi.

oyamad commented 6 years ago

There still remain several pis (and also in math expressions in LaTeX). Search for them.

nswa17 commented 6 years ago

I thought the pis in the math expressions are more familiar than psi. Sorry for that. I fixed it.

oyamad commented 6 years ago

I should have told you to search for "π", too.

nswa17 commented 6 years ago

Fixed it. I hope this is OK. Sorry to be late.

jstac commented 6 years ago

@oyamad It's a good question. There's no policy. Perhaps we should have one. The general rule going forwards is that good behavior is enforced by the market (upvotes and downvotes). But sometimes we observe market failure...

For translations, an attribution of the original author(s) plus "edited by" the new author seems suitable.

jstac commented 6 years ago

I had a look and this is fine as is.