MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Dynamics.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file Dynamics.hpp
5 * @brief Time evolution of arrays of independent levels.
6 *
7 * Every function here takes arrays of numbers and writes an array of levels.
8 * What the numbers are, and whether two entries are alike or different, is
9 * entirely their content: nothing here has a notion of grouping or
10 * agreement, and identical numbers give identical levels.
11 */
12
14
15/**
16 * @brief Level at a time of a leaky response to a rectangular pulse.
17 * @param t Time
18 * @param onset Time the pulse begins
19 * @param duration Length of the pulse, held to the period when one is given
20 * @param rise Time constant while the pulse is on; zero or less jumps to one
21 * @param fall Time constant after the pulse ends; zero or less falls to zero at once
22 * @param period Repeat interval; zero or less means a single pulse
23 * @return Level in [0, 1]
24 *
25 * During the pulse the level climbs toward one as 1 - exp(-s / rise), with s
26 * the time since the pulse began. After it ends the level decays from where it
27 * stood as exp(-s / fall). Before the onset it is zero. With a period, the
28 * pattern repeats from rest every period, so a tail still decaying when the
29 * next pulse begins is cut off there.
30 */
31[[nodiscard]] MAYAFLUX_API double pulse_response(
32 double t, double onset, double duration, double rise, double fall, double period = 0.0) noexcept;
33
34/**
35 * @brief pulse_response over arrays, written to out.
36 * @param out Levels, one per entry
37 * @param t Time
38 * @param onset Onset of each entry
39 * @param duration Pulse length of each entry
40 * @param rise Rise constant of each entry
41 * @param fall Fall constant of each entry
42 * @param period Repeat interval of each entry, zero or less for a single pulse
43 *
44 * Runs over the shortest of the spans. A closed form in t, so any time can be
45 * asked for in any order and nothing is carried between calls.
46 */
47MAYAFLUX_API void pulse_response(
48 std::span<double> out,
49 double t,
50 std::span<const double> onset,
51 std::span<const double> duration,
52 std::span<const double> rise,
53 std::span<const double> fall,
54 std::span<const double> period) noexcept;
55
56/**
57 * @brief One explicit step of generalised Lotka-Volterra competition.
58 * @param levels Nonnegative levels, updated in place
59 * @param growth Growth rate of each level
60 * @param interaction Row-major N x N matrix; entry (i, j) is how strongly
61 * level j suppresses level i, the diagonal being self limitation
62 * @param dt Step
63 *
64 * Each level changes by dt * a_i * (growth_i - sum_j interaction_ij * a_j),
65 * all from the levels at the start of the step, then is held at zero or
66 * above. With suppression stronger between entries than within them, the
67 * levels take turns instead of settling together. Does nothing when the
68 * interaction matrix is smaller than N x N. Uses a per-thread scratch
69 * vector, so it allocates only the first time a size is seen.
70 */
71MAYAFLUX_API void lotka_volterra_step(
72 std::span<double> levels,
73 std::span<const double> growth,
74 std::span<const double> interaction,
75 double dt);
76
77} // namespace MayaFlux::Kinesis::Discrete
std::vector< float > * out
double pulse_response(double t, double onset, double duration, double rise, double fall, double period) noexcept
Level at a time of a leaky response to a rectangular pulse.
Definition Dynamics.cpp:7
void lotka_volterra_step(std::span< double > levels, std::span< const double > growth, std::span< const double > interaction, double dt)
One explicit step of generalised Lotka-Volterra competition.
Definition Dynamics.cpp:46