Skip to content
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

cstwMPCagent reinvented into HARK? #669

Closed
sbenthall opened this issue Apr 30, 2020 · 36 comments
Closed

cstwMPCagent reinvented into HARK? #669

sbenthall opened this issue Apr 30, 2020 · 36 comments
Milestone

Comments

@sbenthall
Copy link
Contributor

cstwMPCagent is depended on by the Uncertainty and the Saving Rate DEMARK.

It has some special properties that should be thought about--how to include it in a way tha seems less specialized?

BufferStockAgent?

https://github.com/llorracc/cstwMPC/blob/master/Code/Python/cstwMPC.py#L21

@mnwhite
Copy link
Contributor

mnwhite commented Apr 30, 2020 via email

@MridulS
Copy link
Member

MridulS commented May 1, 2020

Where is this repo produced from https://github.com/llorracc/cstwMPC/ ? @llorracc [assuming this repo is also autogenerated]

Before removing, I tried to match last update to HARK/cstwMPC with llorracc/cstwMPC.
Last commit to llorracc/cstwMPC is April 12, 2019. I moved the changes after April 12, 2019 to HARK/cstwMPC to the new repo llorracc/cstwMPC.

Should I send in a new PR to llorracc/cstwMPC to override all the files which used to be in HARK/cstwMPC?

@mnwhite
Copy link
Contributor

mnwhite commented May 1, 2020 via email

@llorracc
Copy link
Collaborator

llorracc commented May 4, 2020 via email

@sbenthall
Copy link
Contributor Author

sbenthall commented May 4, 2020

The old cstwMPC code that was in HARK is available in any earlier release:
https://github.com/econ-ark/HARK/tree/0.10.6/HARK/cstwMPC

I'm not sure what all the renaming accomplishes.
There is already a BufferStockTheory REMARK.

I had been under the impression until recently that the cstwMPC REMARK already existed and was located at https://github.com/llorracc/cstwMPC

Now it sounds like you are telling me that there is another layer of intrigue--that the cstwMPC I thought I knew was a mere decoy, and the real cstwMPC was hidden away in a private repo all along.

Obviously, if you hide the "real code" in a private repo, nobody is going to update it. The rationale for having a generator repository is opaque to me. I recommend reducing the complexity of the number of repositories and classes in play.

Why not:

  • decide that the cstwMPC REMARK is truly what it looks like it is
  • tag a release of that REMARK
  • replace what's there with the version of the code that is in HARK 0.10.6
  • tagging a new release of the cstwMPC REMARK.

@sbenthall
Copy link
Contributor Author

Ok, Chris has convinced me privately that he was right, and I was wrong.

I think I did not originally see that his proposal included implicitly the deprecation of the current cstwMPC REMARK code. The new REMARK will become the Single Source of Truth for this functionality.

I suppose this new REMARK will go in the REMARK repository, not in a separate standalone repository.

The remaining issue is the name. I gather than what makes cstwMPC agents special is their awareness of the aggregate economy conditions.

What if the new REMARK was called MarketAwareness. The agent type could be a MarketAwareAgentType. Just spitballing here.

@mnwhite
Copy link
Contributor

mnwhite commented May 5, 2020 via email

@sbenthall
Copy link
Contributor Author

Thank you @mnwhite that is very clarifying.

In that case, I'd argue that the HARK/cstwMPC code should be moved to HARK/examples/cstwMPC and rewritten to use AggShockConsumerType more explicitly.

The extensions could be monkey patched into the instances created in the examples.

Alternatively, this rewrite could be made into a REMARK.
The one tricky thing about renaming the REMARK, now that I think about it, is that the REMARK is about reproducing a paper---in this case, the cstwMPC paper.

If we are trying to help people build similar models, we should be directing users to the HARK classes, not the cstwMPC code.

@sbenthall
Copy link
Contributor Author

Oh, I see how this works now:

https://github.com/econ-ark/HARK/blob/0.10.6/HARK/cstwMPC/cstwMPC.py#L27-L34

So really we are talking about the fate of a small bit of code wrapping the library functionality.
Some of that extra code--the Lorenz share stuff--can be rewritten to use the library code.

What is this code for? It is not up to date with HARK master and breaking for downstream users. Should they remove this code block and just use the inherited method?
https://github.com/econ-ark/HARK/blob/0.10.6/HARK/cstwMPC/cstwMPC.py#L51-L74

@mnwhite
Copy link
Contributor

mnwhite commented May 5, 2020 via email

@mnwhite
Copy link
Contributor

mnwhite commented May 5, 2020 via email

@sbenthall
Copy link
Contributor Author

That is interesting.
This is a nice use case for exploring how we might make HARK more extensible to support minor model differences with less custom code.

@mnwhite
Copy link
Contributor

mnwhite commented May 5, 2020 via email

@sbenthall
Copy link
Contributor Author

#673

@frankovici
Copy link
Contributor

Here's the downstream user that Seb mentioned :)
I am completely fine with deleting
https://github.com/econ-ark/HARK/blob/0.10.6/HARK/cstwMPC/cstwMPC.py#L51-L74
for my purposes and using the inherited method for updating the income process!

@sbenthall
Copy link
Contributor Author

@frankovici thank you! As you can see from this thread, the code is currently in flux.
But the more you can build off of the HARK library code directly, rather than the cstwMPC code, the easier it will be for us to support your work.

@mnwhite
Copy link
Contributor

mnwhite commented May 14, 2020 via email

@llorracc
Copy link
Collaborator

It is not at all specific to cstwMPC. Lots of people are now estimating the degree of heterogeneity necessary to achieve a given dispersion of assets. Dirk Krueger's handbook of macro paper is one example. The fiscal policy paper Edmund and I are working on with Norwegians is another. It is a generically useful thing to be able to do.

If there's a better way to do it, that's fine; but I do not want to let the best be the enemy of the adequate here. And I want to have the FriedmanBufferStockEconomy or whatever we want to call it be a core tool in HARK going forward: One in which you find the distribution of parameters such that you match a target (like the wealth distribution).

@mnwhite
Copy link
Contributor

mnwhite commented May 14, 2020 via email

@llorracc
Copy link
Collaborator

The crucial extra part that is NOT in there is the part that makes it match Friedman (1963): an MPC of 33 percent (or thereabouts). That is, the part that Seb proposed to add: The ability to match a lorenz distribution of wealth to a distribution of parameters. So far as either of us can tell, that is NOT in current HARK.

@sbenthall
Copy link
Contributor Author

Putting aside the current implementation (which I agree with @mnwhite could be improved a lot), I want to be clear on just what distributeParams was supposed to be doing.

An example of its use is cell [8] here:
https://github.com/econ-ark/DemARK/blob/0.10.5/notebooks/Uncertainty-and-the-Saving-Rate.ipynb

The current code for this method is here:
https://github.com/econ-ark/HARK/blob/0.10.6/HARK/cstwMPC/cstwMPC.py#L240

If I understand correctly, the point of this code is to be able to say:

  • For a given model, for a given agent parameter, and a given mathematical distribution...
  • ... make it so that the agents, collectively, have the parameter distributed accordingly.

In the DemARK example, the parameter that is distributed over is the Discount Factor (not the wealth, though I understand why these are connected).

I agree with @mnwhite that the current implementation, as a method on a Market subclass, is quite odd.

It seems like it would be more clean to have this be a way you could choose to parameterize a model.

So, rather than assigning a number to DiscFac in the parameters dictionary as is done here:
https://github.com/econ-ark/HARK/blob/master/HARK/ConsumptionSaving/ConsIndShockModel.py#L1585

Rather, the user could assign a distribution to that parameter:

'DiscFac' : Uniform(mu=1.0065863855906343, sigma=0.0019501105739768)

Then each agent could sample from this distribution to get their discount factor. (Or you could try to use the 'exact match' mechanic here, I suppose).

@mnwhite
Copy link
Contributor

mnwhite commented May 15, 2020 via email

@sbenthall
Copy link
Contributor Author

The distribution of the parameter is at the AgentType level, not the agent level.

Oh, I see. A Market has a list of AgentTypes.
https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L851

... In that case, why not just move the distributeParams method in as-is?

[I would change the 'exec' statement to something else, but that's minor]

@sbenthall
Copy link
Contributor Author

Also, since we now have a way of specifying a discretized distribution object, it would be easy enough to have that passed in directly.

@mnwhite
Copy link
Contributor

mnwhite commented May 15, 2020 via email

@sbenthall
Copy link
Contributor Author

I hesitate to say this, but I think a more general treatment of this suggests a deeper consideration of the HARK architecture that goes well beyond the scope of bringing in the features @llorracc wants in the short term.

For example, there seems to be some ambiguity in the design, where it's possible to simulate many agents with different levels of wealth with a single AgentType instance, but not many agents with different discount factors.

If I'm reading this right, it's impossible for HARK to simulate heterogenous agents unless they are interact through a market. But I gather that @llorracc is becoming interested in ergodic distributions with heterogeneous agents in models without market interactions. And even if the only "interesting" cases do involve market mechanisms, being able to do such a simple (but still heterogeneous) simulation cleanly would be useful as a test case.

@sbenthall
Copy link
Contributor Author

I've made #692 to make it this particular aspect of this issue more concrete.

@mnwhite
Copy link
Contributor

mnwhite commented May 15, 2020 via email

@sbenthall
Copy link
Contributor Author

As an aside...I know it's probably baked in at this point, but having a set of classes all having "Type" at the end is a bit redundant, from a programming perspective. Since a class defines a type. I'm sure you know that and this is just flagging an artifact.

And I see what you are saying about ex post and ex ante heterogeneity, which is extremely clarifying:

  • ex post heterogeneity is modeled by having AgentCount > 1 on a since AgentType instance
  • ex ante heterogeneity is modeled by having multiple AgentType instances

If I am not mistaken, there is currently no support for simulation of the behavior of ex ante heterogeneous models without market interaction.

@mnwhite
Copy link
Contributor

mnwhite commented May 15, 2020 via email

@sbenthall
Copy link
Contributor Author

Just for the record... I defer to @mnwhite on the K/Y and Lorenz curve fitting issues, which at this point are over my head.

@llorracc I recommend decoupling these topics. I'll work to get distributeParams in, which will make it possible to release an updated "Uncertainty" DemARK with the discount factor distribution precomputed.

Later, when @mnwhite has a more efficient curve algorithm in HARK, the DemARK can be updated with the option to use it.

In the meantime, you can use the 0.10.5 version of the DemARK for your more flexible uses.

Does that sound OK?

@sbenthall
Copy link
Contributor Author

because instances of these classes represent a type of agents, and there might be many agents of that type.

OK. And am I right in thinking that the reason for this is the presumed performance benefit of simulating the agents all at once?

There is support in HARK for simulating the behavior of ex ante heterogeneous agents without market interaction: MyTypes = [ThisType, ThatType, OtherType] multiThreadCommands(MyTypes, ['initializeSim()','simulate()']

Ah, interesting. I'll have to look more carefully at this functionality.

@mnwhite
Copy link
Contributor

mnwhite commented May 15, 2020 via email

@sbenthall
Copy link
Contributor Author

Ok. I'm trying to get a working PR in for distributeParams and am hung up on a new issue.

The original code for that method depends on a Population parameter on the market instance.
This appears to be sui generis to cstwMPC, only defined here:
https://github.com/econ-ark/HARK/blob/0.10.6/HARK/cstwMPC/SetupParamsCSTW.py#L262

I'm unclear about its role and whether it should be preserved as part of the new patch.

@mnwhite
Copy link
Contributor

mnwhite commented May 15, 2020 via email

@sbenthall
Copy link
Contributor Author

Ok, got it. let's continue this discussion on the PR, which is now ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

5 participants