Fractals
Fractal systems.
The package covers escape-time sets, chaos-game attractors, and words and patches of named curves and sets.
CantorInteraction(label, *, target, ratio=1 / 3)
Bases: Interaction
Removal of the middle of every interval of a patch.
Each interval is replaced by its first and its last part of the length ratio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the patch of intervals. |
required |
ratio
|
Annotated[float, open(0, oo)]
|
The length of each kept part relative to its interval. |
1 / 3
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import CantorInteraction
>>> CantorInteraction('removal', target='cantor', ratio=0.25).ratio
0.25
Source code in src/skcomplex/systems/mathematics/fractals/_substitution.py
63 64 65 66 67 68 69 70 71 72 | |
CantorSetSystem(ratio=1 / 3, *, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Cantor set as the substitution of every interval by its two outer parts.
Every generation keeps the first and the last part of each interval, each ratio of its length, and removes the
middle. With the ratio of one third, generation n has 2^n intervals of total length (2/3)^n, and the limit set
has the similarity dimension log 2 / log 3, about 0.631. The system has the patch cantor and its number of
intervals cantor.size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio
|
float
|
The length of each kept part relative to its interval, below one half. |
1 / 3
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The ratio is not between 0 and 1/2. |
Examples:
>>> from skcomplex.systems.mathematics.fractals import CantorSetSystem
>>> CantorSetSystem().prepare().simulate(until=3).get_values('cantor.size').tolist()
[1.0, 2.0, 4.0, 8.0]
Source code in src/skcomplex/systems/mathematics/fractals/_substitution.py
251 252 253 254 255 256 257 258 259 260 | |
ChaosGameSystem(preset='sierpinski', *, maps=None, weights=None, n_points=20000, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
Points that draw the attractor of an iterated function system by the chaos game.
At every step each point moves by one of the affine maps of the system, drawn with probabilities proportional to the
weights. The maps contract, so after a few steps the cloud of points covers the attractor, the unique compact set
that the union of the maps leaves unchanged. The Sierpiński triangle of three maps of ratio 1/2 has the box-counting
dimension log 3 / log 2, and the Barnsley fern is the attractor of four maps. The system has the positions
points.p.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preset
|
str
|
|
'sierpinski'
|
maps
|
Sequence[AffineMap] | None
|
The coefficients |
None
|
weights
|
Sequence[float] | None
|
The weight of every map, or |
None
|
n_points
|
int
|
The number of points, started uniformly in the unit square. |
20000
|
random_state
|
int | Generator | None
|
The seed or generator of the initial points. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The preset is unknown. |
Examples:
>>> from skcomplex.systems.mathematics.fractals import ChaosGameSystem
>>> len(ChaosGameSystem('barnsley', n_points=10).prepare().system_.interactions[0].maps)
4
Source code in src/skcomplex/systems/mathematics/fractals/_chaos_game.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
ChaosPointElement(label, *, p=(0.0, 0.0), size=None)
Bases: Element
Points of the plane, each with its position p.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the points. |
required |
p
|
object
|
The initial position, one row per point or shared. |
(0.0, 0.0)
|
size
|
int | None
|
The number of points, or |
None
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import ChaosPointElement
>>> ChaosPointElement('point', p=(0.5, 0.5)).p
(0.5, 0.5)
Source code in src/skcomplex/systems/mathematics/fractals/_chaos_game.py
70 71 72 | |
InverseJuliaInteraction(label, *, target='points', omega=0.0, p=0.5)
Bases: Interaction
Move of a point to a random square root of z - omega.
The point moves to +√(z - omega) with probability p and to -√(z - omega) otherwise, with the principal square
root, drawn anew at every step for every member of a bound group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The points whose value |
'points'
|
omega
|
complex
|
The constant of the quadratic map. |
0.0
|
p
|
float
|
The probability of the positive square root. |
0.5
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import InverseJuliaInteraction
>>> InverseJuliaInteraction('inverse', p=0.3).p
0.3
Source code in src/skcomplex/systems/mathematics/fractals/_quadratic.py
86 87 88 89 90 91 92 93 94 95 96 97 | |
InverseJuliaPointElement(label, *, z=0.5, size=None)
Bases: Element
Points of the inverse iteration of z -> z² + omega, each with its point z.
An InverseJuliaInteraction moves every point to a square root of z - omega drawn at random.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the points. |
required |
z
|
object
|
The initial point, one per member or shared. |
0.5
|
size
|
int | None
|
The number of points, or |
None
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import InverseJuliaPointElement
>>> InverseJuliaPointElement('point', z=0.5j).z
0.5j
Source code in src/skcomplex/systems/mathematics/fractals/_quadratic.py
53 54 55 | |
InverseJuliaSystem(omega=-0.123 + 0.745j, *, p=0.5, n_points=5000, random_state=0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The random function system z -> ±√(z - omega).
Its points settle on the Julia set of z² + omega.
At every step each point moves to the positive square root of z - omega with probability p and to the negative
one otherwise (Dilão 2023, Exercise 5.8). Both branches invert the quadratic map z -> z² + omega, which repels its
Julia set, so the inverse branches attract the points onto the Julia set, drawn by the chaos game with weights p
and 1 - p. For omega = 0 the Julia set is the unit circle, and the default is Douady's rabbit. The system has
the points points.z.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
omega
|
complex
|
The constant of the quadratic map. |
-0.123 + 0.745j
|
p
|
float
|
The probability of the positive square root. |
0.5
|
n_points
|
int
|
The number of points, started uniformly in the square of side 2 about the origin. |
5000
|
random_state
|
int | Generator | None
|
The seed or generator of the initial points. |
0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import InverseJuliaSystem
>>> InverseJuliaSystem(0.0, n_points=10).prepare().system_.elements[0].size
10
Source code in src/skcomplex/systems/mathematics/fractals/_quadratic.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
JuliaSystem(c=-0.8 + 0.156j, shape=(240, 320), *, window=JULIA_WINDOW, radius=2.0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The filled Julia set of z -> z^2 + c (Dilão 2023 §5.5).
The set holds the starting points whose orbit stays bounded.
Every site holds one starting point z of the window and iterates the map with the same constant c, and n
counts the steps the orbit stays within the escape radius. For c in the Mandelbrot set the filled Julia set is
connected, and outside it the set breaks into dust. The system has the field plane, its orbits plane.z, and its
escape times plane.n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
complex
|
The constant of the map. |
-0.8 + 0.156j
|
shape
|
Sequence[int]
|
The number of sites along the imaginary and the real axis. |
(240, 320)
|
window
|
Window
|
The smallest and largest real part, then the smallest and largest imaginary part, of the starting points. |
JULIA_WINDOW
|
radius
|
float
|
The escape radius, at least 2 and at least |
2.0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import JuliaSystem
>>> JuliaSystem(0.0, (3, 3), window=(-1, 1, -1, 1)).prepare().system_.elements[0].z[:3].tolist()
[(-1+1j), 1j, (1+1j)]
Source code in src/skcomplex/systems/mathematics/fractals/_quadratic.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
KochCurveSystem(angle=60.0, *, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Koch curve as the L-system F → F+F--F+F drawn by a turtle.
Every generation replaces each segment by four segments of a third of its length, with a bump of the turning angle
in the middle. With the angle of 60 degrees the curve keeps its endpoints at (0, 0) and (1, 0), its length is
(4/3)^n at generation n, and its similarity dimension is log 4 / log 3, about 1.262. The system has the word
koch, its symbol counts koch.F, and its size koch.size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
float
|
The turning angle of the turtle in degrees. |
60.0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import KochCurveSystem
>>> KochCurveSystem().prepare().simulate(until=3).get_values('koch.F').tolist()
[1.0, 4.0, 16.0, 64.0]
Source code in src/skcomplex/systems/mathematics/fractals/_substitution.py
189 190 191 192 193 194 195 196 197 198 | |
MandelbrotSystem(shape=(240, 300), *, window=MANDELBROT_WINDOW, radius=2.0, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Mandelbrot set (Dilão 2023 §5.5).
The set holds the points c whose orbit of z -> z^2 + c from 0 stays bounded.
Every site holds one point c of the window and iterates the map, and n counts the steps the orbit stays within
the escape radius. The points of the set never escape, so their count grows with every step, while the count of an
escaped point stops at its escape time and colors the bands around the set. The system has the field plane, its
orbits plane.z, and its escape times plane.n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[int]
|
The number of sites along the imaginary and the real axis. |
(240, 300)
|
window
|
Window
|
The smallest and largest real part, then the smallest and largest imaginary part, of the points. |
MANDELBROT_WINDOW
|
radius
|
float
|
The escape radius, 2 for the quadratic map. |
2.0
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import MandelbrotSystem
>>> MandelbrotSystem((3, 3), window=(-1, 1, -1, 1)).prepare().system_.elements[0].c[3:6].tolist()
[(-1+0j), 0j, (1+0j)]
Source code in src/skcomplex/systems/mathematics/fractals/_quadratic.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
QuadraticMapElement(label, *, z=0.0, n=0, c=0.0, space=None)
Bases: Element
Points of the complex quadratic map z' = z^2 + c, each with a count n of its steps.
A QuadraticMapInteraction iterates the points while they stay within the escape radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the element. |
required |
z
|
object
|
The initial point. |
0.0
|
n
|
int
|
The initial number of steps within the escape radius. |
0
|
c
|
object
|
The constant of the map. |
0.0
|
space
|
BaseSpace | None
|
The space with one point per site, or |
None
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import QuadraticMapElement
>>> QuadraticMapElement('point', c=0.25).c
0.25
Source code in src/skcomplex/systems/mathematics/fractals/_quadratic.py
141 142 143 144 145 146 147 148 149 150 151 152 153 | |
QuadraticMapInteraction(label, *, target='plane', radius=2.0)
Bases: Interaction
Iteration of z' = z^2 + c with a count of the steps within the escape radius.
The point stays once |z| exceeds the escape radius, and the count n stops at its escape time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The points whose values |
'plane'
|
radius
|
float
|
The escape radius. |
2.0
|
Examples:
>>> from skcomplex.systems.mathematics.fractals import QuadraticMapInteraction
>>> QuadraticMapInteraction('escape', radius=3.0).radius
3.0
Source code in src/skcomplex/systems/mathematics/fractals/_quadratic.py
179 180 181 182 | |
RandomAffineMapInteraction(label, *, target='points', state='p', maps=SIERPINSKI_MAPS, weights=(1.0, 1.0, 1.0))
Bases: Interaction
Map of a point of the plane by one affine map of an iterated function system.
The map is drawn anew at every step.
Map k takes (x, y) to (a x + b y + e, c x + d y + f) for its coefficients (a, b, c, d, e, f), and is drawn
with a probability proportional to its weight, independently for every member of a bound group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction, unique among the components of its system. |
required |
target
|
Role
|
The path of the element or group whose position the map sets. |
'points'
|
state
|
str
|
The name of the vector state of the target that holds the position. |
'p'
|
maps
|
Sequence[AffineMap]
|
The coefficients |
SIERPINSKI_MAPS
|
weights
|
Sequence[float]
|
The weight of every map. |
(1.0, 1.0, 1.0)
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The number of weights differs from the number of maps, or a map does not have six coefficients. |
Examples:
>>> from skcomplex.systems.mathematics.fractals import RandomAffineMapInteraction
>>> game = RandomAffineMapInteraction('game', target='points', maps=[(0.5, 0, 0, 0.5, 0, 0)], weights=[1.0])
>>> game.maps
[(0.5, 0, 0, 0.5, 0, 0)]
Source code in src/skcomplex/systems/mathematics/fractals/_chaos_game.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
SierpinskiInteraction(label, *, target, shape='triangle')
Bases: Interaction
Replacement of every triangle or square of a patch by the scaled copies of the Sierpiński triangle or carpet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the patch. |
required |
shape
|
str
|
|
'triangle'
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The shape is unknown. |
Examples:
>>> from skcomplex.systems.mathematics.fractals import SierpinskiInteraction
>>> SierpinskiInteraction('copies', target='sierpinski', shape='carpet').shape
'carpet'
Source code in src/skcomplex/systems/mathematics/fractals/_substitution.py
114 115 116 117 | |
SierpinskiSubstitutionSystem(shape='triangle', *, filled=True, label='system', solver='auto', backend='auto')
Bases: BaseSystem
The Sierpiński triangle or carpet.
The shape is the substitution of a polygon by scaled copies of itself.
The triangle is replaced by its three corner copies of half its side, so generation n has 3^n triangles of
total area (3/4)^n times the first, and the gasket has the similarity dimension log 3 / log 2, about 1.585. The
square is replaced by the eight copies of a third of its side around its middle, so generation n has 8^n
squares of area (8/9)^n, and the carpet has the dimension log 8 / log 3, about 1.893. The system has the patch
sierpinski and its number of polygons sierpinski.size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
str
|
|
'triangle'
|
filled
|
bool
|
Whether the geometry visual draws the polygons as a filled image instead of outlines. |
True
|
label
|
str
|
The label of the system, which names it when it is nested in another one. |
'system'
|
solver
|
BaseSolver | str
|
The solver of the problem, or |
'auto'
|
backend
|
BaseBackend | str
|
The backend that evaluates the compiled functions, or |
'auto'
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
The shape is unknown. |
Examples:
>>> from skcomplex.systems.mathematics.fractals import SierpinskiSubstitutionSystem
>>> SierpinskiSubstitutionSystem().prepare().simulate(until=2).get_values('sierpinski.size').tolist()
[1.0, 3.0, 9.0]
Source code in src/skcomplex/systems/mathematics/fractals/_substitution.py
326 327 328 329 330 331 332 333 334 335 336 337 | |