MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ lotka_volterra_step()

MAYAFLUX_API void MayaFlux::Kinesis::Discrete::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.

Parameters
levelsNonnegative levels, updated in place
growthGrowth rate of each level
interactionRow-major N x N matrix; entry (i, j) is how strongly level j suppresses level i, the diagonal being self limitation
dtStep

Each level changes by dt * a_i * (growth_i - sum_j interaction_ij * a_j), all from the levels at the start of the step, then is held at zero or above. With suppression stronger between entries than within them, the levels take turns instead of settling together. Does nothing when the interaction matrix is smaller than N x N. Uses a per-thread scratch vector, so it allocates only the first time a size is seen.

Definition at line 46 of file Dynamics.cpp.

51{
52 const size_t n = std::min(levels.size(), growth.size());
53 if (n == 0 || interaction.size() < n * n)
54 return;
55
56 thread_local std::vector<double> next;
57 next.assign(n, 0.0);
58
59 for (size_t i = 0; i < n; ++i) {
60 const double pressure = weighted_sum(levels.first(n), interaction.subspan(i * n, n));
61 next[i] = std::max(levels[i] + dt * levels[i] * (growth[i] - pressure), 0.0);
62 }
63
64 for (size_t i = 0; i < n; ++i)
65 levels[i] = next[i];
66}
double weighted_sum(std::span< const double > window, std::span< const double > coefs) noexcept
Sum of window[k] * coefs[k] over the shorter of the two.
Definition Kernels.cpp:98

References weighted_sum().

+ Here is the call graph for this function: