The simulation package contains the functions to simulate a single agent in a dynamic discrete choice model. It is structured into two modules. The simulation module with the main function and the simulation_auxiliary with all supplementary functions.

The simulate function

The simulate function can be found in ruspy.simulation.simulation and coordinates the whole simulation process.

simulate(init_dict, ev_known, costs, trans_mat)

Simulating the decision process of Harold Zurcher.

Besides the input Observed costs, Expected value of maintenance and Transition matrix, there is more input specific to the simulation function.

Simulation initialization dictionary

The initialization dictionary contains the following keys:

  • seed : (int) A positive integer setting the random seed for drawing random numbers. If none given, some random seed is drawn.

  • discount_factor : (float) See Discount factor for more details.

  • buses : (int) The number of buses to be simulated.

  • periods : (int) The number of periods to be simulated.

The simulation process

After all inputs are read in, the actual simulation starts. This is coordinated by:

simulate_strategy(num_periods, num_buses, ...)

Simulating the decision process.

The function calls in each period for each bus the following function, to choose the optimal decision:

decide(old_state, costs, disc_fac, ev)

Choosing action in current state.

Then the mileage state increase is drawn:

draw_increment(state, trans_mat)

Drawing a random increase.

The simulation

After the simulation process the observed states, decisions and mileage uses are returned. Additionally the agent’s utility. They are all stored in pandas.DataFrame with column names states, decisions, utilities and usage. Hence, the observed data is a subset of the returned Dataframe.


The simulation notebook allows to easily experiment with the estimation methods described here. The notebook can be downloaded from the simulation folder in the tutorials of ruspy. If you have have everything setup, then it should be easy to run it.