metropolis_hastings module

metropolis_hastings.backward_probability(current_state: Schedule, proposal_state: Schedule, operator: Operator) float[source]

Returns backward probability to go from state j (proposed state) to i (current state) within a given iteration.

  • current_state: current schedule

  • proposal_state: proposal schedule

  • operator: object of class Operator

  • Backward probability

metropolis_hastings.between_var(sequences: List) float[source]

Computes variance of variable between sequences sequences: M x N list containing the N values of the variable of interest for the M sequences (N is 1/4 of the length of the sequence at the beginning of the MH process)

metropolis_hastings.collect_distributions(accepted_sched: List, activities: Optional[List] = None, exclude_home: bool = True, plot: bool = True, save_fig: Optional[str] = None, return_dict: bool = True)[source]

Collects and plots the distributions of the resulting choice set for different metrics (start time, duration, activity participation).

  • accepted sched: list of accepted schedules from the MH algorithm (final choice set)

  • activities: list of activities for the collection of metrics. If none are passed, the metrics are computed

for all activities - exclude_home: if True only collects info on out of home activities - plot: If True, returns plots - save_fig: export format (png/pdf/svg) as string. if None, the figure is not saved. - return_dict: if True, returns dictionary with statistics

metropolis_hastings.forward_probability(current_state: Schedule, proposal_state: Schedule, operator: Operator) float[source]

Returns forward probability to go from state i (current state) to j (proposed state) within a given iteration.

  • current_state: current schedule

  • proposal_state: proposal schedule

  • operator: object of class Operator

  • Forward probability

metropolis_hastings.random_walk(init_sched: Schedule, n_iter: int = 1000, operators: Optional[List] = None, p_operators: Optional[List] = None, uniform: bool = False, param_file: Optional[str] = None, rnd_term: Optional[float] = None, **kwargs) Generator[Tuple[Schedule, Operator, float], None, None][source]

Random walk generator

Parameters:
  • init_sched (-) –

  • n_iter (-) –

  • p_operators (-) –

  • uniform (-) –

  • param_file (-) –

  • rnd_term (-) –

  • kwargs (-) –

Return type:

Generator with current state, operator, and acceptance probability.

metropolis_hastings.scale_reduction(sequences: List) float[source]

Computes scale reduction of given sequences

metropolis_hastings.target_weight(sched: Schedule, uniform: bool = False, param_file: Optional[str] = None, rnd_term: Optional[float] = None) float[source]

Computes target weight for MH –> utility of schedule from initial model estimated with simple random sampling

Parameters:
  • -sched (Schedule object) –

  • -uniform (if True, returns constant weight) –

  • -param_file (file where to find parameters) –

  • -rnd_term (random term for the utility function) –

metropolis_hastings.within_var(sequences: List) float[source]

Computes variance of variable within sequences sequences: M x N list containing the N values of the variable of interest for the M sequences (N is 1/4 of the length of the sequence at the beginning of the MH process)