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.)
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]
```
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)
Run the simulation (get the resulting heatmap)
maps = model.simulate()
During execution, the simulation status is drawn by matplotlib.
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)
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
```
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)
Perform parameter estimation with all objective functions
assessment.whole_opt()
Find the best combination of objective functions
best_combination = assessment.assess()
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.
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)
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
```
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)
Perform parameter estimation with all objective functions
assessment_detail.whole_opt()
Find the best combination of objective functions
best_combination = assessment_detail.assess()
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.
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.
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
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)
Perform parameter estimation (get estimated parameters)
inferred_params = inference.whole_opt()
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.
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
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)
Perform parameter estimation (get estimated parameters)
inferred_params_detail = inference_detail.whole_opt()
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