respy
respy copied to clipboard
Remove apply_law_of_motion in simulate by selecting child indices with choices.
- respy version used, if any: 2.0.0
- Python version, if any: any
- Operating System: any
What would you like to enhance and why? Is it related to an issue/problem?
When the decisions of individuals are simulated for one period in _simulate_single_period, we apply the law of motion to get the states of the next period in simulate. The law of motion takes the current choice and advances experiences, previous choices and the period. Then, we have to map the advanced states to their state space indices with map_observations_to_states to get information like wages, etc. from the state space and simulate decisions in the next period.
Describe the solution you'd like
As @mo2561057 noted in https://github.com/OpenSourceEconomics/respy/pull/373#discussion_r465812784, we can take a short-cut.
- In
_simulate_single_periodwe have the current choice and the child indices. So, we can simply select the state space indices for the next period without using the law of motion. _simulate_single_periodcould pass the child index along all other information back to_simulate. Then, the call tomap_observations_to_statesinsimulatebecomes obsolete.- Instead of
current_dfwe could only pass the child indices to_simulate_single_periodand the function collects the dataframe rows from the frames by itself.
Caveat
The general idea behind this change is to avoid costly computations especially when the law of motion is complex. At the same time, we are transforming an operation which is CPU bound to something which is IO bound because we have to read states from the disk. We need some testing and benchmarks to see where it pays off.