High-level description

This code implements a numerical solver for the generating function of a branching process, assuming diffusive changes in fitness over time. It provides solutions for the lineage propagator, considering the non-sampling constraint.

Code Structure

The code defines a class survival_gen_func that encapsulates the logic for solving the generating function and lineage propagator. It uses numerical integration methods like integrate_rk4 (a 4th order Runge-Kutta implementation) and scipy.integrate.odeint. The class stores precomputed solutions in the phi_solutions dictionary for efficiency.

Symbols

survival_gen_func

Description

This class provides methods to solve for the generating function of a branching process and the lineage propagator, considering non-branching.

Inputs

NameTypeDescription
fitness_gridnumpy.ndarray, optionalDiscretization grid for fitness values. If None, a default grid is used.

Outputs

The class itself does not return any output. Its methods return the computed solutions.

Internal Logic

The class initializes with a fitness grid and precomputes values for numerical efficiency. It stores solutions in the phi_solutions dictionary. The main methods are:

  • integrate_phi: Solves the generating function equation for given parameters.
  • dphi: Computes the time derivative of the generating function.
  • integrate_prop_odeint: Integrates the lineage propagator using scipy.integrate.odeint.
  • integrate_prop: Integrates the lineage propagator using the custom integrate_rk4 method.
  • dprop_backward: Computes the time derivative of the propagator.

integrate_rk4

Description

This function implements a 4th order Runge-Kutta integration scheme with a fixed time step.

Inputs

NameTypeDescription
dffunctionFunction that returns the derivative of the system.
f0numpy.ndarrayInitial conditions for the integration.
Tnumpy.ndarrayTime points at which to evaluate the solution.
dtfloatTime step for the integration.
argstupleAdditional arguments to pass to the derivative function df.

Outputs

NameTypeDescription
solnumpy.ndarraySolution of the integration at the specified time points.

non_negativity_cutoff

Description

A global variable defining the minimum allowed value for the solutions, used to avoid numerical issues with very small or negative values.

Error Handling

The code uses np.maximum to ensure non-negativity of the solutions, replacing values below non_negativity_cutoff with the cutoff value. It also includes checks for valid time ranges within the dprop_backward method and prints warning messages if necessary.

Performance Considerations

The code uses a custom integrate_rk4 implementation instead of scipy.integrate.odeint for the lineage propagator integration, claiming better performance for systems with different convergence criteria. The phi_solutions dictionary stores precomputed generating function solutions to avoid redundant computations.