Implementation of the treatise of "Parameter estimation method for human flow simulation" (unofficial)

Introduction

The paper "Parameter estimation method for human flow simulation" was implemented in Python. The implemented code is posted on github. It is also possible to execute the contents as a package. It will be long to explain all the implementation code, so here we will explain the outline of implementation and how to use it as a package. (The same content is written in README.md on github.)

Implementation overview

  1. Implementation of human flow model using Social Force Model (SFM)
  2. Optimization of all parameters and evaluation of results due to differences in objective functions
  3. Optimization for each individual parameter and evaluation of results due to differences in objective functions
  4. Implementation of optimization model for all parameters based on the result of 2.
  5. Implementation of optimization model for each individual parameter based on the result of 3.

Changes from the treatise

  1. In the human flow simulation, the transition parameters (see the paper) were not determined for each destination, but were determined for each person with a normal distribution.
  2. In the evaluation of the parameter estimation method, only Grid was used to create the heat map, and Voronoi was not used. In addition, the roughness of the grid of the heat map was not evaluated and was fixed.
  3. In parameter estimation, in addition to the estimation method as described in the paper, we also implemented an estimation method that estimates only one type of parameter and fixes the other parameters. (Corresponds to 3. Optimization for each individual parameter and evaluation of results by difference in objective function and [5. Implementation of optimization model for each individual parameter](#5. 個別のパラメータごとの最適化モデルの実装))

Use as a package

Packages required for execution

1. Human flow model using SFM

  1. Specify the argument

people_num: The number of people to simulate.

v_arg: A list-type variable with two elements related to human speed. The first factor represents the average speed and the second factor represents the standard deviation of speed.

repul_h: A list-type variable with two elements related to the repulsive force between people. (Details: Parameter estimation method for human flow simulation 3. Human flow simulation model 3.1 Social Force Model)

repul_m: A list-type variable with two elements related to the repulsive force between a person and a wall. (Details: Parameter estimation method for human flow simulation 3. Human flow simulation model 3.1 Social Force Model)

target: A list-type variable of the form (N, 2). N is the number of destinations. The second dimensional element represents the xy coordinates of the destination. The final destination is considered an exit.

R: Radius of a person (represented as a particle)

min_p: The minimum probability that a person at a destination will move to the next destination. The reciprocal of this probability is used as the expected value of staying time at the destination.

p_arg: A two-dimensional list-type variable that determines the probability that a person at a destination will move to the next destination. The number of elements in the first dimension is the factor of the number of destinations minus one. The first element in the second dimension is the mean of the probabilities, and the second element is the standard deviation. The reciprocal of this probability is used as the expected value of the time spent at the destination. When the number of elements in the first dimension is smaller than the number of destinations minus one, it is broadcast like numpy.

wall_x: x coordinate of the wall (the left edge is 0 and the right edge is determined by this variable)

wall_y: y coordinate of the wall (bottom is 0 and top is determined by this variable)

in_target_d: If the distance between the person and the destination is less than this variable, the person is considered to have arrived at the destination. )

dt: The amount of minute time used to update a person's state (position, speed, etc.)

disrupt_point: Stop the simulation when the elapsed time exceeds this variable. (Simulation 1/dt times is 1 unit of elapsed time)

save_format: Specify the format to save the simulation result. Currently only "heat_map" can be used. If "None", the result is not saved.

save_params: Variables used to save the results. "heat_map" requires a list-type variable with two elements, the first element is a tuple that specifies the number of rows and columns in the heatmap, and the second element specifies how often to save. Variable to do. The unit of frequency is the same as "disrupt_point".

```python
people_num = 30
v_arg = [6,2]
repul_h = [5,5]
repul_m = [2,2]
target = [[60,240],[120,150],[90,60],[240,40],[200,120],[170,70],[150,0]]
R = 3
min_p = 0.1
p_arg = [[0.5,0.1]]
wall_x = 300
wall_y = 300
in_target_d = 3
dt = 0.1
save_format = "heat_map"
save_params = [(30,30),1]
```
  1. Generate an instance to simulate

    import people_flow
    model = people_flow.simulation.people_flow(people_num,v_arg,repul_h,repul_m,target,R,min_p,p_arg,wall_x,wall_y,in_target_d,dt,save_format=save_format,save_params=save_params)
    
  2. Run the simulation (get the resulting heatmap)

    maps = model.simulate()
    

During execution, the simulation status is drawn by matplotlib. simulation1.png simulation2.png

2. Optimization of all parameters and evaluation of results due to differences in objective functions

All parameter optimization is performed using each objective function of SSD, SAD, KL, and ZNCC, and the objective function with the best result is output for each parameter. (Details of objective function: Parameter estimation method for human flow simulation 5. Evaluation of each processing combination 5.1 Overview of evaluation method Table 1)

  1. Specify the argument

maps: 3D numpy.ndarray. A heat map that represents the flow data for parameter estimation (representing the number of people in the Grid at each time). people_num, target, R, min_p, wall_x, wall_y, in_target_d, dt, save_params: Variables used for human flow simulation. See 1. Human flow model using SFM

v_range: A list-type variable of the form (2,2). When estimating the average and standard deviation of human speed, it represents the range of values ​​that each can take.

repul_h_range: A list-type variable of the form (2,2). When estimating two parameters related to the repulsive force between people, it represents the range of values ​​that each can take.

repul_m_range: A list-type variable of the form (2,2). When estimating two parameters for the repulsive force between a person and a wall, each represents the range of possible values.

p_range: A list-type variable of the form (2,2). When estimating the mean and standard deviation of the probabilities of moving to the next destination, each represents the range of possible values. In the parameter estimation, the probability of moving to the next destination is calculated as being the same for all destinations.

n_trials: number of times to optimize the estimated parameters

```python
people_num = 30
v_arg = [6,2]
repul_h = [5,5]
repul_m = [2,2]
target = [[60,240],[120,150],[90,60],[240,40],[200,120],[170,70],[150,0]]
R = 3
min_p = 0.1
p_arg = [[0.5,0.1]]
wall_x = 300
wall_y = 300
in_target_d = 3
dt = 0.1
save_params = [(30,30),1]

v_range = [[3,8],[0.5,3]]
repul_h_range = [[2,8],[2,8]]
repul_m_range = [[2,8],[2,8]]
p_range = [[0.1,1],[0.01,0.5]]
n_trials = 10
```
  1. Generate an instance to evaluate

    assessment = people_flow.assessment_framework.assess_framework(maps, people_num, v_arg, repul_h, repul_m, target, R, min_p, p_arg, wall_x, wall_y, in_target_d, dt, 
              save_params, v_range, repul_h_range, repul_m_range, p_range, n_trials)
    
  2. Perform parameter estimation with all objective functions

    assessment.whole_opt()
    
  3. Find the best combination of objective functions

    best_combination = assessment.assess()
    
  4. Graph the parameter estimation result by comparing it with the correct answer

    assessment.assess_paint()
    

The first line is a graph of the normal distribution of people's speed, with the horizontal axis representing speed and the vertical axis representing probability density. The second line is a graph of the function of the repulsive force between people, with the horizontal axis representing the distance between people and the vertical axis representing the magnitude of the force. The third line is a graph of the function of the repulsive force between a person and a wall. The horizontal axis represents the distance between the person and the wall, and the vertical axis represents the magnitude of the force. The fourth line is a graph of the probability of moving to the next destination, the horizontal axis represents the probability of moving to the next destination, and the vertical axis represents the probability density. In addition, each column represents the result for each objective function. assess_paint.png

3. Optimization for each individual parameter and evaluation of results due to differences in objective functions

Optimization is performed for each individual parameter using each objective function of SSD, SAD, KL, and ZNCC, and the objective function with the best result is output for each parameter. (Details of objective function: Parameter estimation method for human flow simulation 5. Evaluation of each processing combination 5.1 Overview of evaluation method Table 1)

  1. Specify the argument

maps: 3D numpy.ndarray. A heat map that represents the flow data for parameter estimation (representing the number of people in the Grid at each time). people_num, target, R, min_p, wall_x, wall_y, in_target_d, dt, save_params: Variables used for human flow simulation. See 1. Human flow model using SFM

v_range: A list-type variable of the form (2,2). When estimating the average and standard deviation of human speed, it represents the range of values ​​that each can take.

repul_h_range: A list-type variable of the form (2,2). When estimating two parameters related to the repulsive force between people, it represents the range of values ​​that each can take.

repul_m_range: A list-type variable of the form (2,2). When estimating two parameters for the repulsive force between a person and a wall, each represents the range of possible values.

p_range: A list-type variable of the form (2,2). When estimating the mean and standard deviation of the probabilities of moving to the next destination, each represents the range of possible values. In the parameter estimation, the probability of moving to the next destination is calculated as being the same for all destinations.

n_trials: number of times to optimize the estimated parameters

```python
people_num = 30
v_arg = [6,2]
repul_h = [5,5]
repul_m = [2,2]
target = [[60,240],[120,150],[90,60],[240,40],[200,120],[170,70],[150,0]]
R = 3
min_p = 0.1
p_arg = [[0.5,0.1]]
wall_x = 300
wall_y = 300
in_target_d = 3
dt = 0.1
save_params = [(30,30),1]

v_range = [[3,8],[0.5,3]]
repul_h_range = [[2,8],[2,8]]
repul_m_range = [[2,8],[2,8]]
p_range = [[0.1,1],[0.01,0.5]]
n_trials = 10
```
  1. Generate an instance to evaluate

    assessment_detail = people_flow.assessment_framework.assess_framework_detail(maps, people_num, v_arg, repul_h, repul_m, target, R, min_p, p_arg, wall_x, wall_y, in_target_d, dt, 
              save_params, v_range, repul_h_range, repul_m_range, p_range, n_trials)
    
  2. Perform parameter estimation with all objective functions

    assessment_detail.whole_opt()
    
  3. Find the best combination of objective functions

    best_combination = assessment_detail.assess()
    
  4. Graph the parameter estimation result by comparing it with the correct answer

    assessment_detail.assess_paint()
    

The first line is a graph of the normal distribution of people's speed, with the horizontal axis representing speed and the vertical axis representing probability density. The second line is a graph of the function of the repulsive force between people, with the horizontal axis representing the distance between people and the vertical axis representing the magnitude of the force. The third line is a graph of the function of the repulsive force between a person and a wall. The horizontal axis represents the distance between the person and the wall, and the vertical axis represents the magnitude of the force. The fourth line is a graph of the probability of moving to the next destination, the horizontal axis represents the probability of moving to the next destination, and the vertical axis represents the probability density. In addition, each column represents the result for each objective function. assessment_paint_detail.png

4. Implementation of optimization model for all parameters

All parameters were optimized using the SSD, SAD, KL, and ZNCC objective functions, and based on the results of [2. Optimization of all parameters and evaluation of results based on differences in objective functions](#2. 全部のパラメータの最適化と目的関数の違いによる結果の評価) The optimization result using the optimum objective function is selected for each parameter and output.

  1. Specify the argument See 1. Human flow model using SFM and 2. Optimization of all parameters and evaluation of results by difference in objective function.

    people_num = 30
    target = [[60,240],[120,150],[90,60],[240,40],[200,120],[170,70],[150,0]]
    R = 3
    min_p = 0.1
    wall_x = 300
    wall_y = 300
    in_target_d = 3
    dt = 0.1
    save_params = [(30,30),1]
    
    v_range = [[3,8],[0.5,3]]
    repul_h_range = [[2,8],[2,8]]
    repul_m_range = [[2,8],[2,8]]
    p_range = [[0.1,1],[0.01,0.5]]
    n_trials = 10
    
  2. Generate an instance to estimate

    inference = people_flow.inference_framework.inference_framework(maps, people_num, target, R, min_p, wall_x, wall_y, in_target_d, dt, save_params, v_range, repul_h_range, repul_m_range, p_range, n_trials)
    
  3. Perform parameter estimation (get estimated parameters)

    inferred_params = inference.whole_opt()
    

5. Implementation of optimization model for each individual parameter

Optimization for each individual parameter is performed using each objective function of SSD, SAD, KL, and ZNCC, and the result of [3. Optimization for each individual parameter and evaluation of the result due to the difference in the objective function](#3. 個別のパラメータごとの最適化と目的関数の違いによる結果の評価) is obtained. Based on this, the optimization result using the optimum objective function is selected for each parameter and output.

  1. Specify the argument See 1. Human flow model using SFM, 3. Optimization for each individual parameter and evaluation of results by difference in objective function.

    people_num = 30
    v_arg = [6,2]
    repul_h = [5,5]
    repul_m = [2,2]
    target = [[60,240],[120,150],[90,60],[240,40],[200,120],[170,70],[150,0]]
    R = 3
    min_p = 0.1
    p_arg = [[0.5,0.1]]
    wall_x = 300
    wall_y = 300
    in_target_d = 3
    dt = 0.1
    save_params = [(30,30),1]
    
    v_range = [[3,8],[0.5,3]]
    repul_h_range = [[2,8],[2,8]]
    repul_m_range = [[2,8],[2,8]]
    p_range = [[0.1,1],[0.01,0.5]]
    n_trials = 10
    
  2. Generate an instance to estimate

    inference_detail = people_flow.inference_framework.inference_framework_detail(maps, people_num, v_arg, repul_h, repul_m, target, R, min_p, p_arg, wall_x, wall_y, in_target_d, dt, save_params, v_range, repul_h_range, repul_m_range, p_range, n_trials)
    
  3. Perform parameter estimation (get estimated parameters)

    inferred_params_detail = inference_detail.whole_opt()
    

in conclusion

I explained the outline of the implementation by Python of the paper "Parameter estimation method of human flow simulation" and how to use the implementation code on github as a package. If you have any questions, advice on implementation code, or problems when using it as a package, please comment.

Recommended Posts

Implementation of the treatise of "Parameter estimation method for human flow simulation" (unofficial)
Until the maximum likelihood estimation method finds the true parameter
Increase the speed of the Monte Carlo method of Cython cut-out implementation.
A simple Python implementation of the k-nearest neighbor method (k-NN)
Implementation of ML-EM method, cross-section reconstruction algorithm for CT scan
Implementation of Scale-space for SIFT
Simulation of the contents of the wallet
Understand the arguments required for the HTTP request method of the Requests module
I tried to summarize the frequently used implementation method of pytest-mock
for, continue, break Explain the flow of iterative processing in Python3-Part 1