def density_voronoi_2(points, cell_size):
r"""Density definition base on Voronoi-diagram. [Steffen2010]_
Compute Voronoi-diagram for each position :math:`\mathbf{p}_i` giving
cells :math:`A_i` to each agent :math:`i`. Area of Voronoi cell is
denoted :math:`|A_i|`. Area :math:`A` is the area inside which we
measure the density.
:math:`S = \{i : \mathbf{p}_i \in A\}` is the set of agents and
:math:`N = |S|` the number of agents that is inside area :math:`A`.
.. math::
D_{V^\prime} = \frac{N}{\sum_{i \in S} |A_i|}
Args:
points (numpy.ndarray):
Two dimensional points :math:`\mathbf{p}_{i \in \mathbb{N}}`
cell_size (float):
Cell size of the meshgrid. Each cell represents an area :math:`A`
inside which density is measured.
Returns:
numpy.ndarray: Grid of values density values for each cell.
"""
# Voronoi tesselation
vor = Voronoi(points)
new_regions, new_vertices = voronoi_finite_polygons_2d(vor)
# Compute areas for all of the Voronoi regions
area = np.array([polygon_area(new_vertices[i]) for i in new_regions])
return _core_2(points, cell_size, area, vor.point_region)
评论列表
文章目录