{"action":"created","issue":{"url":"https://api.github.com/repos/ubcecon/computing_and_datascience/issues/57","repository_url":"https://api.github.com/repos/ubcecon/computing_and_datascience","labels_url":"https://api.github.com/repos/ubcecon/computing_and_datascience/issues/57/labels{/name}","comments_url":"https://api.github.com/repos/ubcecon/computing_and_datascience/issues/57/comments","events_url":"https://api.github.com/repos/ubcecon/computing_and_datascience/issues/57/events","html_url":"https://github.com/ubcecon/computing_and_datascience/issues/57","id":339039544,"node_id":"MDU6SXNzdWUzMzkwMzk1NDQ=","number":57,"title":"Add test of QuantEcon McCall code to the fixed-point testsuite to compare performance.","user":{"login":"jlperla","id":13106721,"node_id":"MDQ6VXNlcjEzMTA2NzIx","avatar_url":"https://avatars2.githubusercontent.com/u/13106721?v=4","gravatar_id":"","url":"https://api.github.com/users/jlperla","html_url":"https://github.com/jlperla","followers_url":"https://api.github.com/users/jlperla/followers","following_url":"https://api.github.com/users/jlperla/following{/other_user}","gists_url":"https://api.github.com/users/jlperla/gists{/gist_id}","starred_url":"https://api.github.com/users/jlperla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlperla/subscriptions","organizations_url":"https://api.github.com/users/jlperla/orgs","repos_url":"https://api.github.com/users/jlperla/repos","events_url":"https://api.github.com/users/jlperla/events{/privacy}","received_events_url":"https://api.github.com/users/jlperla/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"ArnavSood","id":5009477,"node_id":"MDQ6VXNlcjUwMDk0Nzc=","avatar_url":"https://avatars1.githubusercontent.com/u/5009477?v=4","gravatar_id":"","url":"https://api.github.com/users/ArnavSood","html_url":"https://github.com/ArnavSood","followers_url":"https://api.github.com/users/ArnavSood/followers","following_url":"https://api.github.com/users/ArnavSood/following{/other_user}","gists_url":"https://api.github.com/users/ArnavSood/gists{/gist_id}","starred_url":"https://api.github.com/users/ArnavSood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArnavSood/subscriptions","organizations_url":"https://api.github.com/users/ArnavSood/orgs","repos_url":"https://api.github.com/users/ArnavSood/repos","events_url":"https://api.github.com/users/ArnavSood/events{/privacy}","received_events_url":"https://api.github.com/users/ArnavSood/received_events","type":"User","site_admin":false},"assignees":[{"login":"ArnavSood","id":5009477,"node_id":"MDQ6VXNlcjUwMDk0Nzc=","avatar_url":"https://avatars1.githubusercontent.com/u/5009477?v=4","gravatar_id":"","url":"https://api.github.com/users/ArnavSood","html_url":"https://github.com/ArnavSood","followers_url":"https://api.github.com/users/ArnavSood/followers","following_url":"https://api.github.com/users/ArnavSood/following{/other_user}","gists_url":"https://api.github.com/users/ArnavSood/gists{/gist_id}","starred_url":"https://api.github.com/users/ArnavSood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArnavSood/subscriptions","organizations_url":"https://api.github.com/users/ArnavSood/orgs","repos_url":"https://api.github.com/users/ArnavSood/repos","events_url":"https://api.github.com/users/ArnavSood/events{/privacy}","received_events_url":"https://api.github.com/users/ArnavSood/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-07-06T18:53:08Z","updated_at":"2018-07-06T18:58:29Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Look at https://lectures.quantecon.org/jl/mccall_model_with_separation.html\r\nI think the key code is\r\n```julia\r\nusing Distributions\r\n\r\n# A default utility function\r\n\r\nfunction u(c::Real, σ::Real)\r\n    if c > 0\r\n        return (c^(1 - σ) - 1) / (1 - σ)\r\n    else\r\n        return -10e6\r\n    end\r\nend\r\n\r\n# default wage vector with probabilities\r\n\r\nconst n = 60                                   # n possible outcomes for wage\r\nconst default_w_vec = linspace(10, 20, n)      # wages between 10 and 20\r\nconst a, b = 600, 400                          # shape parameters\r\nconst dist = BetaBinomial(n-1, a, b)\r\nconst default_p_vec = pdf.(dist, support(dist))\r\n\r\nmutable struct McCallModel{TF <: AbstractFloat,\r\n                           TAV <: AbstractVector{TF},\r\n                           TAV2 <: AbstractVector{TF}}\r\n    α::TF         # Job separation rate\r\n    β::TF         # Discount rate\r\n    γ::TF         # Job offer rate\r\n    c::TF         # Unemployment compensation\r\n    σ::TF         # Utility parameter\r\n    w_vec::TAV    # Possible wage values\r\n    p_vec::TAV2   # Probabilities over w_vec\r\n\r\n    McCallModel(α::TF=0.2,\r\n                β::TF=0.98,\r\n                γ::TF=0.7,\r\n                c::TF=6.0,\r\n                σ::TF=2.0,\r\n                w_vec::TAV=default_w_vec,\r\n                p_vec::TAV2=default_p_vec) where {TF, TAV, TAV2} =\r\n        new{TF, TAV, TAV2}(α, β, γ, c, σ, w_vec, p_vec)\r\nend\r\n\r\n\"\"\"\r\nA function to update the Bellman equations.  Note that V_new is modified in\r\nplace (i.e, modified by this function).  The new value of U is returned.\r\n\r\n\"\"\"\r\nfunction update_bellman!(mcm::McCallModel,\r\n                         V::AbstractVector,\r\n                         V_new::AbstractVector,\r\n                         U::Real)\r\n    # Simplify notation\r\n    α, β, σ, c, γ = mcm.α, mcm.β, mcm.σ, mcm.c, mcm.γ\r\n\r\n    for (w_idx, w) in enumerate(mcm.w_vec)\r\n        # w_idx indexes the vector of possible wages\r\n        V_new[w_idx] = u(w, σ) + β * ((1 - α) * V[w_idx] + α * U)\r\n    end\r\n\r\n    U_new = u(c, σ) + β * (1 - γ) * U +\r\n                    β * γ * dot(max.(U, V), mcm.p_vec)\r\n\r\n    return U_new\r\nend\r\n\r\n\r\nfunction solve_mccall_model(mcm::McCallModel;\r\n                            tol::AbstractFloat=1e-5,\r\n                            max_iter::Integer=2000)\r\n\r\n    V = ones(length(mcm.w_vec))    # Initial guess of V\r\n    V_new = similar(V)             # To store updates to V\r\n    U = 1.0                        # Initial guess of U\r\n    i = 0\r\n    error = tol + 1\r\n\r\n    while error > tol && i < max_iter\r\n        U_new = update_bellman!(mcm, V, V_new, U)\r\n        error_1 = maximum(abs, V_new - V)\r\n        error_2 = abs(U_new - U)\r\n        error = max(error_1, error_2)\r\n        V[:] = V_new\r\n        U = U_new\r\n        i += 1\r\n    end\r\n\r\n    return V, U\r\nend\r\nmcm = McCallModel()\r\nV, U = solve_mccall_model(mcm)\r\n```\r\nWith this\r\n- [ ] Get it working (essentially as-is) and add this to the `NLsolve`  ranch as a new test called `mccall.jl` or something like that.  \r\n- [ ] Maybe put it in a separate function so that you can run the `@btime` on it.  You will want to keep that version in the test as a comparison \r\n- [ ] Now, we want to make a separate version of this using the `fixedpoint` library, and changing as little else as possible.\r\n- [ ] I think the key here is first to rewrite the `update_bellman!` to be an inplace function which can be used with a fixed point iteration.\r\n   - rename the `update_bellman!` function to be `bellman_operator!` or something like that\r\n   - move the `mcmc::McCallModel` to the end of the signature\r\n  - In particular, this means you will want to change the signature to `not` return `U_new` but rather to have the whole thing in a single vector with the `V_new` and `U_new` stacked and the `V` and `U` stacked.  Then it becomes a true fixed point operator on a vector\r\n - Get that working fully first, where the `solve_mccall_model` function is modified to use the changed `bellman_operator!` function, but leave the rest of fixed point iteration the same.\r\n  - Check the performance of this with a `@btime` compared to the original code, to make sure that this didn't add a huge amount of overhead.\r\n- [ ] After that, you can modify the iteration in `solve_mccall_model` to use the `bellman_operator!` with the `fixedpoint` function you designed.  This probably involves creating a simple closure in that function prior to calling it.  i.e. \r\n```julia\r\nT!(x_new, x) = bellman_operator!(x_new, x, mcm)\r\n#...\r\nsolution = fixedpoint(T!, x0, inplace=true, ftol=tol)\r\n```\r\n- [ ] Make sure that you are using the same tolerances, and do a `@btime` to see if there is a difference.  Try it with `m=1` or `m=2` as well."},"comment":{"url":"https://api.github.com/repos/ubcecon/computing_and_datascience/issues/comments/403119625","html_url":"https://github.com/ubcecon/computing_and_datascience/issues/57#issuecomment-403119625","issue_url":"https://api.github.com/repos/ubcecon/computing_and_datascience/issues/57","id":403119625,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzExOTYyNQ==","user":{"login":"ArnavSood","id":5009477,"node_id":"MDQ6VXNlcjUwMDk0Nzc=","avatar_url":"https://avatars1.githubusercontent.com/u/5009477?v=4","gravatar_id":"","url":"https://api.github.com/users/ArnavSood","html_url":"https://github.com/ArnavSood","followers_url":"https://api.github.com/users/ArnavSood/followers","following_url":"https://api.github.com/users/ArnavSood/following{/other_user}","gists_url":"https://api.github.com/users/ArnavSood/gists{/gist_id}","starred_url":"https://api.github.com/users/ArnavSood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ArnavSood/subscriptions","organizations_url":"https://api.github.com/users/ArnavSood/orgs","repos_url":"https://api.github.com/users/ArnavSood/repos","events_url":"https://api.github.com/users/ArnavSood/events{/privacy}","received_events_url":"https://api.github.com/users/ArnavSood/received_events","type":"User","site_admin":false},"created_at":"2018-07-06T18:58:29Z","updated_at":"2018-07-06T18:58:29Z","author_association":"COLLABORATOR","body":"Makes sense. I'll probably step out for lunch and then get to this."}}
{"actor":{"display_login":"ArnavSood"}}