Reference¶
- class smup.smup.Smup[source]¶
Main interface with two main methods:
compute()
anddisplay()
.- compute(x=1024, y=720, s=20, norm=2, provisioning=1.0, heterogeneous_areas=False, seed=None)[source]¶
- Parameters
x (
int
) – Width of the picture (in pixels)y (
int
) – Height of the picture (in pixels)s (
int
) – Number of areas to display in the picturenorm (
int
orstr
orfloat
or callable.) – Distance function to use. If norm is a positive float p (or string representation of), the p-norm will (which is not a norm if p<1). Optimized for 1, 2, or ‘inf’ but arbitrary positive float can be used If norm is a callable (must be jittable with proper signature), it will be used as such (not need to be an actual norm or even distance).provisioning (
float
) – Quotas slack. Values < 1 will make holes in the covering, while large values will make a Voronoi diagram.heterogeneous_areas (
bool
) – Tells if the surfaces of site try to have same area or not. If False, each area will have the same size up to roundings (about x*y/s). If True, (s-1) integers between 0 and x*y are draw uniformly independently. The sizes are given by the s intervals generated on [0, x*y].seed (
int
, optional) – Random seed
- Returns
- Return type
Examples
We will use ASCII display for these examples. With the chosen seen, the site 0 should be a ball.
With Euclidian distance, the ball is a disk.
>>> my_smup = Smup() >>> my_smup.compute(x=30, y=20, s=3, norm=2, seed=42) >>> txt = ascii_display(my_smup.picture, my_smup.centers) >>> print(txt) 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 X 2 2 2 1 1 1 X 1 1 1 1 1 1 2 2 2 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 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1 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Arbitrary power can be used for the norm (which may not be a norm in the end).
>>> my_smup.compute(x=30, y=20, s=3, norm=.5, seed=42) >>> txt = ascii_display(my_smup.picture, my_smup.centers) >>> print(txt) 1 1 1 1 1 1 2 2 2 2 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 0 0 2 2 2 2 2 2 2 2 2 X 2 2 2 1 1 1 X 1 1 1 2 2 2 2 2 2 2 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 X 0 0 0 0 0 0 0 0 0 2 2 2 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 2 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 2 2 2 2 1 1 1 1 1 1
You can also specify a custom function and use it. The function, which may not be a norm of even a distance, must be numba compatible with a signature (2,), (2, X) -> (X,). Example:
>>> def diagonal_polarization(center, points): ... return (points[0, :] - center[0] + points[1, :] - center[1])**2 >>> my_smup.compute(x=30, y=20, s=3, norm=diagonal_polarization, seed=42) >>> txt = ascii_display(my_smup.picture, my_smup.centers) >>> print(txt) 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 1 1 1 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 X 2 2 2 1 1 1 X 1 2 2 2 2 2 2 2 2 2 0 0 0 0 0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- Parameters
- Returns
- Return type
Examples
See Using SMUP for graphical examples. Here we just show the file saving feature.
>>> from pathlib import Path >>> import tempfile >>> my_smup = Smup() >>> my_smup.compute(x=30, y=20, s=3, norm=2, seed=42) >>> with tempfile.TemporaryDirectory() as tmpdirname: ... fn = tmpdirname/Path("picture.png") ... my_smup.display(draw_centers=True, save=fn) ... size=fn.stat().st_size >>> size 55984
- smup.smup.compute(x, y, s, distance_function, provisioning=1.0, heterogeneous_areas=False, seed=None)[source]¶
Main function of the package. Computes the pictures.
- Parameters
x (
int
) – Width of the picture (in pixels)y (
int
) – Height of the picture (in pixels)s (
int
) – Number of areas to display in the picturedistance_function (callable) – Functions that computes distances between a center and points
provisioning (
float
) – Quota under/over provisioning. Values < 1 will make holes in the covering, while large values will make a Voronoi diagram.heterogeneous_areas (
bool
) – Tells if the surfaces of site try to have same area or not.seed (
int
, optional) – Random seed
- Returns
- smup.smup.dist_1(center, points)[source]¶
- Parameters
- Returns
Manhattan distances between center and points.
- Return type
Examples
Manhattan distances between the origin and the points (0.3, 0.4), (1, 0), and (2, 1):
>>> center = np.array([0, 0]) >>> points = np.array([ [0.3, 1, 2], [0.4, 0, 1] ]) >>> dist_1(center, points) array([0.7, 1. , 3. ])
- smup.smup.dist_2(center, points)[source]¶
- Parameters
- Returns
Square of Euclidian distances between center and points.
- Return type
Examples
Square distances between the origin and the points (0.3, 0.4), (1, 0), and (2, 1):
>>> center = np.array([0, 0]) >>> points = np.array([ [0.3, 1, 2], [0.4, 0, 1] ]) >>> dist_2(center, points) array([0.25, 1. , 5. ])
- smup.smup.dist_inf(center, points)[source]¶
- Parameters
- Returns
Inf-norm distances between center and points.
- Return type
Examples
Inf-norm distances between the origin and the points (0.3, 0.4), (1, 0), and (2, 1):
>>> center = np.array([0, 0]) >>> points = np.array([ [0.3, 1, 2], [0.4, 0, 1] ]) >>> dist_inf(center, points) array([0.4, 1. , 2. ])
- smup.smup.isfloat(value)[source]¶
-
Examples
>>> isfloat(3) True >>> isfloat("3.145") True >>> isfloat("Hello") False >>> isfloat("1+1") False
- smup.smup.make_dist_p(p=2.0)[source]¶
- Parameters
p (
float
) – Power to apply.- Returns
A jitted function that computes the sum of individual coordinate distances to the power of p. Correspond to a norm (up to re-scaling by 1/p) if p greater or equal to 1.
- Return type
callable
Examples
Let us fix a center and some points.
>>> center = np.array([0, 0]) >>> points = np.array([ [0.3, 1, 2], [0.4, 0, 1] ])
Square distances between the origin and the points (0.3, 0.4), (1, 0), and (2, 1) (equivalent to
dist_2()
)>>> my_dist = make_dist_p(p=2) >>> my_dist(center, points) array([0.25, 1. , 5. ])
Power of 1 (equivalent to
dist_1()
):>>> my_dist = make_dist_p(p=1) >>> my_dist(center, points) array([0.7, 1. , 3. ])
Power of 3:
>>> my_dist = make_dist_p(p=3) >>> my_dist(center, points) array([0.091, 1. , 9. ])
Power of .5 (not a norm; convexity is lost):
>>> my_dist = make_dist_p(p=.5) >>> my_dist(center, points) array([1.18017809, 1. , 2.41421356])