respy icon indicating copy to clipboard operation
respy copied to clipboard

Remove apply_law_of_motion in simulate by selecting child indices with choices.

Open tobiasraabe opened this issue 5 years ago • 0 comments

  • 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_period we 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_period could pass the child index along all other information back to _simulate. Then, the call to map_observations_to_states in simulate becomes obsolete.
  • Instead of current_df we could only pass the child indices to _simulate_single_period and 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.

tobiasraabe avatar Aug 17 '20 07:08 tobiasraabe