projectmesa / mesa-examples

Seminal agent-based models developed using Mesa
Other
116 stars 140 forks source link

Integrate Hotelling Law Extension into Mesa Examples #120

Closed aumashankar closed 5 months ago

aumashankar commented 5 months ago

Closes issue #119: Hotelling Law Extension using Mesa (NetLego example using mesa)

Online demo: http://178.128.112.142:8521/

EwoutH commented 5 months ago

Thanks a lot for the PR! Looks like an interesting model to have in our example library. I requested two of our maintainers to review it.

aumashankar commented 5 months ago

Thanks a lot for the PR! Looks like an interesting model to have in our example library. I requested two of our maintainers to review it.

Thanks a lot @EwoutH
We've developed it as a standalone, I'm seeing integration errors related to imports with build run tried to fix as I see Looking forward to reviewer comments / feedback

rht commented 5 months ago

If you could add a test that check's for the prediction of the Hotelling's law, e.g. https://github.com/projectmesa/mesa-examples/blob/1933cbc8251ca047273e0f88193f692ccbb86de6/examples/sugarscape_g1mt/tests.py#L19-L33. The test is run by pytest tests.py. The functions with prefix of test_* are automatically run by pytest. Also, in the visualization, you are meant to show that the standard deviation of the price is decreasing over time.

aumashankar commented 5 months ago

If you could add a test that check's for the prediction of the Hotelling's law, e.g.

https://github.com/projectmesa/mesa-examples/blob/1933cbc8251ca047273e0f88193f692ccbb86de6/examples/sugarscape_g1mt/tests.py#L19-L33

. The test is run by pytest tests.py. The functions with prefix of test_* are automatically run by pytest. Also, in the visualization, you are meant to show that the standard deviation of the price is decreasing over time.

Added tests.py

EwoutH commented 5 months ago

@aumashankar and @rht, thanks for the hard work in the past days. I'm curious, how far along the review process are we? Is there anything I can do to help?

aumashankar commented 5 months ago

@aumashankar and @rht, thanks for the hard work in the past days. I'm curious, how far along the review process are we? Is there anything I can do to help?

@EwoutH we've used old UI and some old api's with agent schedule @rht directed me to new mesa3.0 UI, helping review it in the process. last commit includes the feedback changes from @rht which can further help with review if it's good

rht commented 5 months ago

I ran the Solara simulation, and observed the variance going up over time instead of going down. Doesn't this contradict Hotelling's law?

aumashankar commented 5 months ago

I ran the Solara simulation, and observed the variance going up over time instead of going down. Doesn't this contradict Hotelling's law?

This observation is due to Initial Conditions and Randomness for the basic model we are adjusting the price with random prices taken in the range 5 -15 . The idea of this model is to show how stores will change location based on pricing and some agents will be immobile irrespective of external conditions.

Observing an increase in price variance over time in the simulation does not necessarily contradict Hotelling's Law. as it depends on factors.

We are working further with consumer preferences and market share and no of consumers (might be another PR) where

Hotelling's Law, in the context of spatial competition, suggests that businesses will choose to locate themselves in a manner that minimizes competition, often leading to some form of clustering or minimal differentiation Hotelling's Law can imply that firms will tend to match each other's prices to avoid price wars, which in turn could lead to a reduction in price variance over time as the firms reach a sort of equilibrium state.

Edit: changed test as variance can increase or decrease depending on factors. For now, added another adjust_price_by_neighbour_store() in agents.py to mimic some logic however, it will be fully covered with more dynamics with consumers and market share in the next PR

rht commented 5 months ago

This observation is due to Initial Conditions and Randomness for the basic model

The basic model itself needs to display the Hotelling law, because it is what the example is named after. At least, try changing the default params until the variance reduction happens, and in the readme, tell the reader about the param range, and when and why it starts breaking down, or that the timescale could be longer. This is standard practice for sensitivity analysis.

If you want to speed up the simulation step duration, you can tweak the param play_interval, https://github.com/projectmesa/mesa/blob/4cc03a4300ce2f0600efa3ef45a61f16d2290dc0/mesa/experimental/jupyter_viz.py#L60. Or if this doesn't do, needs to investigate why it is slow for such a low number of agents.

aumashankar commented 5 months ago

This observation is due to Initial Conditions and Randomness for the basic model

The basic model itself needs to display the Hotelling law, because it is what the example is named after. At least, try changing the default params until the variance reduction happens, and in the readme, tell the reader about the param range, and when and why it starts breaking down, or that the timescale could be longer. This is standard practice for sensitivity analysis.

If you want to speed up the simulation step duration, you can tweak the param play_interval, https://github.com/projectmesa/mesa/blob/4cc03a4300ce2f0600efa3ef45a61f16d2290dc0/mesa/experimental/jupyter_viz.py#L60. Or if this doesn't do, needs to investigate why it is slow for such a low number of agents.

There are multiple parts to it, one aspect is that, hotelling law in itself doesn't contradict as it depends on other parameters. However, We are already working on locally with consumers and market share, I think it's better to integrate that and do sensitivity analysis.

I'll get back in a day or two to integrate those here.

aumashankar commented 5 months ago

This observation is due to Initial Conditions and Randomness for the basic model

The basic model itself needs to display the Hotelling law, because it is what the example is named after. At least, try changing the default params until the variance reduction happens, and in the readme, tell the reader about the param range, and when and why it starts breaking down, or that the timescale could be longer. This is standard practice for sensitivity analysis. If you want to speed up the simulation step duration, you can tweak the param play_interval, https://github.com/projectmesa/mesa/blob/4cc03a4300ce2f0600efa3ef45a61f16d2290dc0/mesa/experimental/jupyter_viz.py#L60. Or if this doesn't do, needs to investigate why it is slow for such a low number of agents.

There are multiple parts to it, one aspect is that, hotelling law in itself doesn't contradict as it depends on other parameters. However, We are already working on locally with consumers and market share, I think it's better to integrate that and do sensitivity analysis.

I'll get back in a day or two to integrate those here.

@rht updated PR with consumer preferences, market share, visualizations and tests for simulation

kindly review. I appreciate your patience and helping us with details (we are learning the framework)

rht commented 5 months ago

Everything else LGTM.

aumashankar commented 5 months ago

Everything else LGTM.

Thank you

rht commented 5 months ago

Merged, thank you @aumashankar.

aumashankar commented 5 months ago

Merged, thank you @aumashankar.

@rht Thanks a lot for the review and all the help provided in learning the mesa framework. (the old and new) @EwoutH @jackiekazil @dmasad Thank you for the opportunity.

jackiekazil commented 5 months ago

@aumashankar Thank you for YOUR contribution and for making requested changes. We appreciate your diligence and contribution!