spatiocoexistence.model module¶
- class spatiocoexistence.model.SpatioCoexistenceModel[source]¶
Bases:
objectInitialize the model with parameters from a dictionary or a file. If neither is provided, use default parameters.
Parameters:¶
- parameter_filePath, optional
Path to a parameter file
- paramsdict, optional
Dictionary of model parameters
- initial_inventorynp.ndarray | Path, optional
Initial inventory data or path to file containing it
- use_initial_as_referencebool, default=False
If True, the initial_inventory is only used for plotting comparison and a new inventory is created for simulation
- __init__(parameter_file=None, params=None, initial_inventory=None, use_initial_as_reference=False, reference_inventory=None, threads=1)[source]¶
Initialize the model with parameters from a dictionary or a file. If neither is provided, use default parameters.
Parameters:¶
- parameter_filePath, optional
Path to a parameter file
- paramsdict, optional
Dictionary of model parameters
- initial_inventorynp.ndarray | Path, optional
Initial inventory data or path to file containing it
- use_initial_as_referencebool, default=False
If True, the initial_inventory is only used for plotting comparison and a new inventory is created for simulation
- update_params(params)[source]¶
Set the model parameters from a dictionary and update radius if present.
- plot(title, initial_plot=False, axs=None, threshold=50, filter=1.0, abundances=None, figsize=(22, 10))[source]¶
Plot the current state of the model.
- run_with_plotting(n_steps=1000, plot_interval=50, threshold=50, figsize=(24, 12))[source]¶
Run simulation with interactive plotting.
- optimize_parameters(start_params, lower, upper, rhobeg, rhoend, param_names, stat_funcs, stat_indices=None, n_init=50, n_iter=10, iter_steps=5, reference_inventory=None)[source]¶
Generic optimizer for model parameters to fit arbitrary statistics using log_likelihood.
Parameters¶
- start_paramsnp.ndarray
Initial guess for parameters.
- lowernp.ndarray
Lower bounds for parameters.
- uppernp.ndarray
Upper bounds for parameters.
- param_nameslist[str]
Names of parameters to optimize (order matches start_params).
- stat_funcslist of (func, func_kwargs)
Each tuple: (statistic function, kwargs for function).
- stat_indiceslist of slices or lists, optional
For each stat_func, which indices to use (default: use all).
- n_initint
Initial run steps.
- n_iterint
Number of iterations for averaging.
- iter_stepsint
Steps per iteration.