- ๐ค I study socially-aware mobile robots.
- ๐ซ How to reach me:[email protected]
yuxiang-gao / pysocialforce Goto Github PK
View Code? Open in Web Editor NEWExtended Social Force Model in Python for social navigation research
License: MIT License
Extended Social Force Model in Python for social navigation research
License: MIT License
Hi, thanks for your great work about this social force simulator. I've tried this simulator and find it very useful.
I have a suggestion to improve the computation efficiency about the force calculation, that is the ObstacleForce
class.
the _get_force() func will calculate the distance first for all the points in obstacle lines, then it add masks. When there are lots of obstacles this function will greatly slow-down the process.
To speed up this process, now I add a simple judgement to pre-select nearby obstacles. This improvement will speed up the process from 14sec/step to 0.05sec/step in our case. Note that the solution here is not very elegant. You can try to improve by this thought.
class ObstacleForce(Force):
def _get_force(self):
sigma = self.config("sigma", 0.2)
threshold = self.config("threshold", 0.2) + self.peds.agent_radius
force = np.zeros((self.peds.size(), 2))
if len(self.scene.get_obstacles()) == 0:
return force
obstacles = np.vstack(self.scene.get_obstacles())
pos = self.peds.pos()
for i, p in enumerate(pos):
diff = p - obstacles
diff_select = diff[np.logical_and(np.logical_and(diff[:,0]<10,diff[:,0]>-10),np.logical_and(diff[:,1]<10,diff[:,1]>-10))]
if diff_select.shape[0] == 0:
continue
else:
directions, dist = stateutils.normalize(diff_select)
dist = dist - self.peds.agent_radius
if np.all(dist >= threshold):
continue
dist_mask = dist < threshold
directions[dist_mask] *= np.exp(-dist[dist_mask].reshape(-1, 1) / sigma)
force[i] = np.sum(directions[dist_mask], axis=0)
return force * self.factor
Hi guys,
I'm using your PySocialForce package to model a robot / pedestrian interaction in a 2D world. It's really a great effort from your side to create this package and put it on PyPI. Unfortunately, it's a bit too slow for my reinforcement learning purposes in order to achieve a reasonable amount of training episodes for my robot. (I know I could scale out with A3C, but I'm just a poor student ๐)
I've seen you've already put Numba optimizations into your code and modeled everything as NumPy array, so you're probably aware of the fact that performance is critical to a simulation environment. Have you ever profiled your package, e.g. with cProfile or the new Scalene? (I know, silly question, but I'll have to ask anyways. I can create a profile for you if you want ๐)
I think you've still got lots of Python C-API overhead in your routines which could easily be eliminated by more Numba vectorizations. For example, you're computing the forces sequentially (https://github.com/yuxiang-gao/PySocialForce/blob/master/pysocialforce/simulator.py#L78). And for modeling the forces you're using OOP inheritance which could be replaced by a single function returning a float (https://github.com/yuxiang-gao/PySocialForce/blob/master/pysocialforce/forces.py#L39).
I'm willing to make a major contribution to your project in the near future in case I can figure out some sensible optimizations. Are you interested in a collaboration of any kind? I'll be carrying out this optimization anyways because I need a faster training for my master thesis ๐
Best wishes,
Marco
Hi,
Thanks for your excellent repository.
I have a question about the agent radius. I am not seeing that you are using agent radius in your SocialForce class. How do you consider avoiding a collision when you do not use agent radius? As I am changing the radius, agents still collide with each other lots of times because the radius has not been considered (I know that SFM does not guarantee to avoid collision, but their behavior shows that they do not know the radius). You only take the agent radius into account for avoiding obstacles in ObstacleForce class.
Thanks in advance for your help.
PySocialForce/pysocialforce/simulator.py
Line 50 in 8c81cd1
You are handing over self.config, but for Peds which accesses the attributes in the scene section of the config you should hand over self.scene_config, shouldn't you?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.