Explanation and implementation of SocialFoceModel

I will explain the SocialFoceModel, which is a type of artificial potential method. This is a model of human crowd behavior based on the dynamics advocated by Helbing.

Click here for the original paper https://arxiv.org/pdf/cond-mat/9805244.pdf

It is basically expressed as the sum of attractive force and repulsive force as shown below.


F_{all} = F_{gall} + F_{others} + F_{obstacle}

Attraction

Here is the formula of the attractive force that works between the pedestrian and the goal.


F_{all} =\frac{V_0e_t-v_t}{\tau}

$ V_0: Maximum speed $ $ e_t: Unit vector in the direction of the goal $ $ \ tau: Time to reach V_0 (time constant) $ $ v_t: Current velocity vector $







repulsive force

Here is the formula for the repulsive force that acts between an obstacle or other pedestrian and the pedestrian. The formulas used are the same.


F_{others}  = F_{obstacle} =  v_rUe^{-\frac{d}{R}}

$ d: Distance to obstacles and other pedestrians (excluding radius) $ $ R, U: Constant $ $ v_r: Direction from obstacle (unit vector) $

The parameters set by the author Helbing are

V_0:1.34 [m/s] \tau:0.5 [s] R:10.0[m^2/s^2] U:0.2[m]

It has become.

Implementation

From this formula and parameters, I would like to display the trajectory when a pedestrian avoids an obstacle.

Normally, you have to consider obstacles and pedestrian radii, but I have omitted it for the sake of simplicity.

# coding: utf-8
import numpy as np
import matplotlib.pyplot as plt

V0  = 1.34 # [m/s] Speed of equilibrium (= max speed)
tau = 0.5  # [sec] Time to reach V0 ziteisuu
delta_sec = 0.01 #[sec]

U = 10.0 # [m^2/s^2]
R = 0.2  # [m]

user_mass_kg = 55 # [kg]
user_mass_N = user_mass_kg / 9.8 # [N]

user_pos = np.array([0.0, 0.0]) # 0=x, 1=y[m]
user_vel = np.array([0.3, 0.0]) # 0=x, 1=y[m/s]
map_size = np.array([10, 10]) # 0=x, 1=y[m]
goal_pos = np.array([10, 5]) # 0=x, 1=y[m]
obstacle_pos = np.array([6, 3]) # 0=x, 1=y[m]

user_pos_lines = user_pos.reshape((2,1))


while True:
	#Attraction
	dist_xy = goal_pos - user_pos
	dist_norm = np.linalg.norm(dist_xy, ord=1)
	e = dist_xy / dist_norm
	F_goal = (V0 * e - user_vel) / tau # [N]
	
	#repulsive force
	dist_xy = user_pos - obstacle_pos
	dist_norm = np.linalg.norm(dist_xy, ord=2)
	v_r = dist_xy / dist_norm
	F_obstacle = v_r * U * np.exp((-1) * dist_norm / R)
	
	#Pedestrian position calculation
	F_all = F_goal + F_obstacle # [N]
	#acceleration[m/s^2]
	user_acc = F_all / user_mass_N
	#speed[m/s]
	user_vel += user_acc * delta_sec
	#position
	user_pos += user_vel * delta_sec
	
	#The distance between the pedestrian and the goal is 0.Finish when it is less than 2m
	if np.linalg.norm(goal_pos - user_pos) < 0.2:
		break
	user_pos_lines = np.append(user_pos_lines, user_pos.reshape((2,1)), axis=1)


#drawing
#Obstacle
plt.scatter(obstacle_pos[0], obstacle_pos[1], color='b', s=100)
#Trajectory
plt.plot(user_pos_lines[0,:], user_pos_lines[1,:], color='r')
#goal
plt.scatter(goal_pos[0], goal_pos[1], color='g', s=200)
plt.show()

print("end")

Execution result

In this way, I was able to create a trajectory to avoid obstacles while heading toward the goal.

Figure_1.png

Recommended Posts

Explanation and implementation of SocialFoceModel
Explanation and implementation of PRML Chapter 4
Explanation and implementation of ESIM algorithm
Explanation and implementation of simple perceptron
Explanation and implementation of Decomposable Attention algorithm
Explanation of edit distance and implementation in Python
Introduction and Implementation of JoCoR-Loss (CVPR2020)
[Reinforcement learning] Explanation and implementation of Ape-X in Keras (failure)
Explanation of CSV and implementation example in each programming language
Implementation and experiment of convex clustering method
Mathematical explanation of binary search and ternary search and implementation method without bugs
Implementation and explanation using XGBoost for beginners
Explanation and implementation of the XMPP protocol used in Slack, HipChat, and IRC
Comparison of k-means implementation examples of scikit-learn and pyclustering
Implementation of TRIE tree with Python and LOUDS
Implementation of Fibonacci sequence
Perceptron basics and implementation
Python --Explanation and usage summary of the top 24 packages
Sequential update of covariance to derivation and implementation of expressions
I touched Wagtail (3). Investigation and implementation of pop-up messages.
Implementation of DB administrator screen by Flask-Admin and Flask-Login
Overview of generalized linear models and implementation in Python
Explanation of package tools and commands for Linux OS
Python implementation of CSS3 blend mode and talk of color space
Problems of liars and honesty
Derivation and implementation of update equations for non-negative tensor factorization
Mechanism of pyenv and virtualenv
Implementation of TF-IDF using gensim
Implementation of MathJax on Sphinx
Pre-processing and post-processing of pytest
Combination of recursion and generator
Combination of anyenv and direnv
Normalizing Flow theory and implementation
Implementation of game theory-Prisoner's dilemma-
Differentiation of sort and generalization of sort
Implementation of independent component analysis
Coexistence of pyenv and autojump
Quantum computer implementation of quantum walk 3
[With simple explanation] Scratch implementation of deep Boltzmann machine with Python ②
Python implementation of particle filters
[With simple explanation] Scratch implementation of deep Boltzmann machine with Python ①
Use and integration of "Shodan"
Problems of liars and honesty
Theory and implementation of multiple regression models-why regularization is needed-
Verification and implementation of video reconstruction method using GRU and Autoencoder
Maxout description and implementation (Python)
Occurrence and resolution of tensorflow.python.framework.errors_impl.FailedPreconditionError
Implementation of quicksort in Python
Comparison of Apex and Lamvery
Source installation and installation of Python
Quantum computer implementation of quantum walk 1
Deep reinforcement learning 2 Implementation of reinforcement learning
Implementation of Scale-space for SIFT
Introduction and tips of mlflow.Tracking
Crawling with Python and Twitter API 2-Implementation of user search function
[Python] I thoroughly explained the theory and implementation of logistic regression
[Python] I thoroughly explained the theory and implementation of decision trees
[Python] Implementation of Nelder–Mead method and saving of GIF images by matplotlib
Implementation of Datetime picker action using line-bot-sdk-python and implementation sample of Image Carousel
[Recommendation] Summary of advantages and disadvantages of content-based and collaborative filtering / implementation method
Environment construction of python and opencv