Git Product home page Git Product logo

pygom's Introduction

pygom - ODE modelling in Python

Github actions Documentation Status pypi version licence Jupyter Book Badge

A generic framework for ode models, specifically compartmental type problems.

This package depends on:

dask
matplotlib
enum34
pandas
python-dateutil
numpy
scipy
sympy

and they should be installed if not already available. Alternatively, the easier way to use a minimal (and isolated) setup is to use conda and create a new environment via:

conda env create -f conda-env.yml

Installation of this package can be performed via:

$ python setup.py install

and tested via:

$ python setup.py test

A reduced form of the documentation may be found on ReadTheDocs.

You may get the full documentation, including the lengthy examples by locally building the documentation found in the folder:

$ doc

Note that building the documentation can be extremely slow depending on the setup of the system. Further details can be found at it's own read me:

$ doc/README.rst

Please be aware that if the module tests fails, then the documentation for the package will not compile.

Please be aware that there may be redundant files within the package as it is under active development.

Contributors

Thomas Finnie ([email protected])

Edwin Tye

Hannah Williams

Jonty Carruthers

Martin Grunnill

Version

0.1.7 Add Approximate Bayesian Computation (ABC) as a method of fitting to data

0.1.6 Bugfix scipy API, pickling, print to logging and simulation

0.1.5 Remove auto-simplification for much faster startup

0.1.4 Much faster Tau leap for stochastic simulations

0.1.3 Defaults to python built-in unittest and more in sync with conda

pygom's People

Contributors

edwintye avatar hareball90 avatar harleyday avatar j-c-gibson avatar jontycarruthersphe avatar mgrunnill avatar trdurrant avatar twomagpi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pygom's Issues

PyGOM and a function no longer within Scipy

Just in case you update scipy note that a function seems to be lost in later version. This causes the error below when importing PyGOM. I found that reverting scipy to version 1.3.2 fixed this issue.
scipy.special.cython_special does not export expected C function __pyx_fuse_0pdtr

Cannot install via ```python setup.py install``` if using setuptools-scm for getting version.

I have tried to install making sure all the required package are in place. I get the following error when python setup.py install in conda:

Traceback (most recent call last):
  File "setup.py", line 80, in <module>
    setup(
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools\__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\distutils\core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools\dist.py", line 453, in __init__
    _Distribution.__init__(
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\distutils\dist.py", line 292, in __init__
    self.finalize_options()
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools\dist.py", line 831, in finalize_options
    ep(self)
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools\dist.py", line 852, in _finalize_setup_keywords
    ep.load()(self, ep.name, value)
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools_scm\integration.py", line 24, in version_keyword
    dist.metadata.version = _get_version(config)
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools_scm\__init__.py", line 173, in _get_version
    parsed_version = _do_parse(config)
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools_scm\__init__.py", line 127, in _do_parse
    version = _version_from_entrypoints(config) or _version_from_entrypoints(
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools_scm\__init__.py", line 65, in _version_from_entrypoints
    version = _call_entrypoint_fn(root, config, ep.load())
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools_scm\__init__.py", line 46, in _call_entrypoint_fn
    return fn(root, config=config)
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools_scm\git.py", line 115, in parse
    require_command("git")
  File "C:\Users\mdgru\anaconda3\envs\pygom\lib\site-packages\setuptools_scm\utils.py", line 142, in require_command
    raise OSError("%r was not found" % name)
OSError: 'git' was not found

When I changed the line 82 of the setup.py from use_scm_version=True, to version=0.17,, the installation worked.

Broken plotting function

The plot function does not give an output.

from pygom import DeterministicOde, Transition, TransitionType
import numpy as np

states= ['S', 'I', 'R']
params = {'beta':0.3, 'gamma':0.5}
t = np.arange(0, 100, 0.5)
transitions = [Transition(origin='S', destination='I', equation='beta*S*I', transition_type='T'),
Transition(origin='I', destination='R', equation='gamma*I', transition_type='T')]

model = DeterministicOde(states, params, transition=transitions)
model.get_ode_eqn()
model.initial_values = ([95, 5, 0], t[0])
model.parameters = {'beta':0.3, 'gamma':0.5}
solution, output = model.integrate(t[1::], full_output=True)
model.plot()

Add contributor guidelines

Contributor guidelines should include:

  • PR template
  • stating what acknowledgement/authorship a contributor is entitled to

Problem after update on Ubuntu 22.04/ Python 3.10

Hello,
I just did the upgrade to 22.04 LTS, I was using PyGom for a covid-related project (very useful library btw).
Unfortunately the installation on Python3.10 seems to be broken. I get the following error during gcc compilation
pygom/model/_tau_leap.c: In function ‘__pyx_tp_dealloc_array’: pygom/model/_tau_leap.c:18375:5: error: lvalue required as increment operand 18375 | ++Py_REFCNT(o); | ^~
Has anyone installed successfully the library on Ubuntu 22.04 with Python 3.10 ?

CI setup convoluted and not useful

Problem

The current setup in travis is confusing due to the almost duplicated steps in line 31 and 33

https://github.com/PublicHealthEngland/pygom/blob/18bdd6ad8c3ecd66371a0ee8d72457d3d695ef0d/.travis.yml#L31-L33

because python setup.py install in fact checks the environment against the variable install_requires which has strict version requirements. This can be observed in the latest master build where the step python setup.py install downloads and installed scipy=1.4.1; conda installed scipy=1.1.0 at the start.

Possible resolution

1.) One of the ways to eliminate the extra step is to remove the conda environment setup and instead let python (which will default to pip) take care of the installation. This is a relatively simple fix given that a requirements.txt exists. The only issue is the potential out-of-sync between the variable install_requires and requirements.txt.

2.) Another way to solve the problem would be to not use python setup.py install at all. This is probably a better approach given most users will setup their environment via conda anyway.
However, looking through the logs suggests that conda is broken — possibly linked to conda/conda#9268 tho I cannot confirm atm — and scipy=1.1.0,dask=0.19.2,pandas=0.23.4 was installed when python=3.5. This is grossly out of date as we have dask>=2.0.0,pandas>=1.0.0 for the other python versions.

3.) Third option which I can think of is to embed requirements.txt directly into setup.py. This is not a complicated, and the only drawback is pip tries to make use of the latest version in a very aggressive manner, something of an issue for backward compatibility without further setup in travis.

Graphing

Issues around producing the flow diagram from the model.

Parsing input variable

Variable here referes to both the states and the parameters. The current system requires an input of the form

    parameterList = ['beta', 'gamma']

but it will be much simpler if it can parse a pure string input like:

    parameterList = 'beta, gamma'

or

    parameterList = 'beta gamma'

using common or space as deliminter.

Stochastic simulation could do with a break clause if specified populations reach 0.

Depending on the nature of the stochastic simulation if certain class/es have gone extinct it is not necessary to continue running the simulation. A break clause could be added to stop a simulation if the population in certain class/es reached 0.

Within the module simulate.py following additions could be made:

  • The function simulate_jump could take the optional argument stop_at_extinction_of. This argument would take a list of indexes of state variables, the default argument would be an empty list.

  • Before the while loop within the function _jump the code extinction_clause = False could be added.

  • The while argument within the function _jump would become while t < finalT and extinction_clause == False:.

  • At the end of the while loop within the function _jump the following code could be added:

if len(self.stop_at_extinction_of)!=0:
    if sum(x[self.stop_at_extinction_of]) ==0:
        extinction_clause = True
  • After the while loop within the function _jump there would have to be some post prossesing. Filling each of the time steps after extinction of the np.arrays xList and tList with either NA values or a string stating the selected population/s had gone extinct.

Occaisonal "TypeError: argument of type ‘bool’ is not iterable" at function tauLeap (line 552) of module pygom.stochastic_simulation.

When running certain stochastic simulation through SimulateOde.simulate_jump methods the error "TypeError: argument of type ‘bool’ is not iterable" occasionally occurs. This happens in line 552 in function tauLeap of module pygom.model.stochastic_simulation.
The error is caused by function _cy_test_tau_leap_safety (file pygom/model/_tau_leap.pyx). When failing to find a low enough tau/jump step _cy_test_tau_leap_safety returns the bool False. However, line 552 in the function tauLeap is expecting a numeric followed by a bool.

Changing _cy_test_tau_leap_safety return if fail from (lines 56-57 of file pygom/model/_tau_leap.pyx):

        if tau_scale*total_rate <= 1.0 or count > 256:
            return False

to:

        if tau_scale*total_rate <= 1.0 or count > 256:
            return tau_scale, False

Solves this issue.

Update verion on pypi

Current PyPi version is 0.1.1 which is quite behind even the master branch. Needs updating.

Documentation build

Add sphinkx_rtd_theme to list of prerequisites for building the documentation.

A colleague reported a few issues with installing on a Mac.

A colleague of mine reported a few issues with installing on a Mac. I am sorry for not giving more information. Partly I am putting this issue up in case I forget to do it at a later date with more detail. I do not have a Mac myself to check this.

Errors installing pygom on Mac (setup.py generating error)

I work with Martin Grunnil and he has opened a previous issue (#58) on this subject on my behalf.
In addition, no one has been able to use pygom on Mac in my lab. See the errors bellow. Thank you in anticipation.

**Traceback (most recent call last):
File "setup.py", line 105, in
scripts=[]
File "/Applications/Anaconda3/anaconda/lib/python3.5/site-packages/setuptools/init.py", line 140, in setup
return distutils.core.setup(attrs)
File "/Applications/Anaconda3/anaconda/lib/python3.5/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/Applications/Anaconda3/anaconda/lib/python3.5/site-packages/setuptools/dist.py", line 370, in init
k: v for k, v in attrs.items()
File "/Applications/Anaconda3/anaconda/lib/python3.5/distutils/dist.py", line 281, in init
self.finalize_options()
File "/Applications/Anaconda3/anaconda/lib/python3.5/site-packages/setuptools/dist.py", line 529, in finalize_options
ep.load()(self, ep.name, value)
File "/Applications/Anaconda3/anaconda/lib/python3.5/site-packages/pkg_resources/init.py", line 2325, in load
return self.resolve()
File "/Applications/Anaconda3/anaconda/lib/python3.5/site-packages/pkg_resources/init.py", line 2331, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/Users/jummy30/Documents/nextcloud/MacDocBK/YORK_PDV_FIELDS/Martin/PYGOM/pygom-master/.eggs/setuptools_scm-6.4.2-py3.5.egg/setuptools_scm/init.py", line 90
version: Optional[ScmVersion]
^
SyntaxError: invalid syntax

Copy transitions within the stochastic framework

To keep track of cumulative numbers of infections, say, it would be useful to be able to couple up the disease transition (TransitionType.T) with a cumulative counter (TransitionType.B), so that equations dealing with the same symbolic flows (rate*state) use the same values in the stochastic framework. Currently they are treated as independent stochastic processes (which is what they've been set up to be).

Multiple origin/destination state

Certain reactions like hydrogen + oxygen -> water require a combination of two states into one. Similarly, a reaction may be a breakdown of one state into many. This is particularly useful in stochastic simulation.

Typesetting of equations in Jupyter notebook

Can you add a function like this to improve viewing of equations within Jupyter notebooks?

def print_ode2(self):
'''
Prints the ode in symbolic form onto the screen/console in actual
symbols rather than the word of the symbol.

    Based on the PyGOM built-in but adapted for Jupyter
    '''
    A = self.get_ode_eqn()
    B = sympy.zeros(A.rows,2)
    for i in range(A.shape[0]):
        B[i,0] = sympy.symbols('d' + str(self._stateList[i]) + '/dt=')
        B[i,1] = A[i]

    return B

Warning on install

      ############################
      # Package would be ignored #
      ############################
      Python recognizes 'pygom.model' as an importable package,
      but it is not listed in the `packages` configuration of setuptools.

      'pygom.model' has been automatically added to the distribution only
      because it may contain data files, but this behavior is likely to change
      in future versions of setuptools (and therefore is considered deprecated).

      Please make sure that 'pygom.model' is included as a package by using
      the `packages` configuration field or the proper discovery methods
      (for example by using `find_namespace_packages(...)`/`find_namespace:`
      instead of `find_packages(...)`/`find:`).

      You can read more about "package discovery" and "data files" on setuptools
      documentation page.

Test fails

When i tried running the test, it failed giving the following error message:
ImportError: No module named libsbml

it seems this package needed to run the script was not included in the requirements and needs to be downloaded first before installing. Do you have any ideas on how to do this or has similar errors been encountered?

get_transition_graph outputs

the original documentation (transition) uses
dot = modelTrans.get_transition_graph() giving an output of the model within an x-y axis

modelTrans.get_transition_graph() outputs the x-y axis figure and a clearer diagram (without axis)

dot = modelTrans.get_transition_graph(show=False) only outputs the clear diagram

Should the default of get_transition_graph() be the third option?

image

create a stocastic system from a deterministic

We can integrate a stochastic object to get the determininistic solution but there isn't an easy constructor for a stochastic model when you have the deterministic one.

This is just a case of copying across the correct fields and submitting them to the constructor. A convienience function would be good.

Use of get_transition_graph method causes AttributeError.

Use of get_transition_graph method with arument show=True causes AttributeError (see below).
Returned graph can be rendered as pdf using method .render(filename='filename', format='pdf') though.

This maybe as the dependent package graphviz was updated to version 20.1 23rd July 2022.

Traceback (most recent call last):
File "C:\Users\mdgru.conda\envs\pygom\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "", line 18, in
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\pygom-0.18-py3.10-win-amd64.egg\pygom\model\deterministic.py", line 356, in get_transition_graph
plt.imshow(img)
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib_api\deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 2611, in imshow
__ret = gca().imshow(
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 2225, in gca
return gcf().gca()
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 830, in gcf
return figure()
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib_api\deprecation.py", line 454, in wrapper
return func(*args, **kwargs)
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 771, in figure
manager = new_figure_manager(
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 346, in new_figure_manager
_warn_if_gui_out_of_main_thread()
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 336, in _warn_if_gui_out_of_main_thread
if (_get_required_interactive_framework(_get_backend_mod()) and
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 206, in _get_backend_mod
switch_backend(dict.getitem(rcParams, "backend"))
File "C:\Users\mdgru.conda\envs\pygom\lib\site-packages\matplotlib\pyplot.py", line 266, in switch_backend
canvas_class = backend_mod.FigureCanvas
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'. Did you mean: 'FigureCanvasAgg'?

Use of derived_param argument option in intiating mode causes NameError when using R0 function.

If derived_param argument is used when intiating a model, the later use of the pygom.model.epi_analysis.R0 can cause a NameError. So for example if the term 'lambda__' was being used for transmission instead of the full force of infection equation the following error would be thrown when using pygom.model.epi_analysis.R0:

Traceback (most recent call last):
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-13-e9cf6dd5a5ac>", line 7, in <module>
    model_R0 = R0(mg_model,disease_states)
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\epi_analysis.py", line 75, in R0
    F, V = disease_progression_matrices(ode, disease_state)
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\epi_analysis.py", line 159, in disease_progression_matrices
    ode2 = SimulateOde(ode.state_list, ode.param_list, transition=FList)
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\simulate.py", line 79, in __init__
    super(SimulateOde, self).__init__(state,
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\deterministic.py", line 71, in __init__
    super(DeterministicOde, self).__init__(state,
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\base_ode_model.py", line 172, in __init__
    self._transitionVector = self._computeTransitionVector()
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\base_ode_model.py", line 964, in _computeTransitionVector
    _f, _t, eqn = self._unrollTransitionList(self._getAllTransition())
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\base_ode_model.py", line 1092, in _unrollTransitionList
    eqn_list = checkEquation(eqn_list, *self._getListOfVariablesDict())
  File "C:\Users\mdgru\anaconda3\envs\amr\lib\site-packages\pygom-0.18-py3.9-win-amd64.egg\pygom\model\_model_verification.py", line 101, in checkEquation
    _eqn = eval(_inputStr)
  File "<string>", line 1, in <module>
NameError: name 'lambda__' is not defined

Fix CI

Travis CI has stopped working, investigate using Jenkins.

import fails on Win10 with Python 3.8 and scipy 1.4.1 on fresh install

Via Josh Lau:
"Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygom_init_.py", line 8, in
from .loss import *
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygom\loss_init_.py", line 7, in
from pygom.loss.confidence_interval import *
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygom\loss\confidence_interval.py", line 23, in
from pygom.model.model_errors import EstimateError, InputError
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygom\model_init
.py", line 11, in
from .epi_analysis import *
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygom\model\epi_analysis.py", line 11, in
from .simulate import SimulateOde
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygom\model\simulate.py", line 19, in
from .stochastic_simulation import cle, exact, firstReaction, tauLeap, hybrid
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pygom\model\stochastic_simulation.py", line 18, in
from ._tau_leap import _cy_test_tau_leap_safety
File "pygom\model_tau_leap.pyx", line 1, in init pygom.model._tau_leap
ImportError: scipy.special.cython_special does not export expected C function __pyx_fuse_0pdtr"

Switching to state*parameter when defined in transistion object as parameter*state

If when constructing a model with transitions the standard parameterstate is used in the equation argument that defines a transition, when using the methods on the model class model.get_ode_eqn(), model.print_ode() or model.print_ode(latex_output=True) the format is changed to stateparameter.

For instance say for a simple SIR model the imunity transition is defined as:

Transition(origin='I',  destination='R', equation='gamma*I', transition_type=TransitionType.T)

When using model.print_ode(latex_output=True) the immunity term in the output becomes I\gamma.

Not sure if this is an issue with Sympy in the background. I think something similar happened when I was using sympy for stable point analyses.

Improved helpfulness of error message

Is it possible to print out which input state does not exist?

~\AppData\Local\Continuum\anaconda3\envs\pygom\lib\site-packages\pygom-0.1.3-py3.6.egg\pygom\model\base_ode_model.py in _extractStateSymbol(self, input_str)
1184 else:
1185 raise InputError("Cannot find input state, input %s " +
-> 1186 "likely to be a vector" % sym_name)
1187 else:
1188 raise InputError("Input state: %s does not exist" % input_str)

InputError: Cannot find input state, input %s likely to be a vector

The passage of time is not a stochastic process: periodic functions may present some dificulty when using .simulate_jump()

I am trying to think of how you would stochastically simulate a model with a periodic term within pygom. The common_models module intialisis a determiistic SIS model with periodic transmision in the following way.

state = ['S', 'E', 'I', 'tau']
param_list = ['mu', 'alpha', 'gamma', 'beta_0', 'beta_1']
derived_param = [('beta_S', 'beta_0 * (1 + beta_1*cos(2*pi*tau))')]
ode = [
    Transition(origin='S', equation='mu - beta_S*S*I - mu*S',
               transition_type=TransitionType.ODE),
    Transition(origin='E', equation='beta_S*S*I - (mu + alpha)*E',
               transition_type=TransitionType.ODE),
    Transition(origin='I', equation='alpha*E - (mu + gamma)*I',
               transition_type=TransitionType.ODE),
    Transition(origin='tau', equation='1',
               transition_type=TransitionType.ODE)
    ]
# initialize the model
ode_obj = DeterministicOde(state, param_list,
                           derived_param=derived_param,
                           ode=ode)

From this example I would intialise a stochastic version of this model in the following way:

actual_states=['S', 'E', 'I', 'R']
state = actual_states + ['time']
param_list = ['mu', 'alpha', 'gamma', 'beta_0', 'beta_1']
derived_param = [('beta_S', 'beta_0 * (1 + beta_1*cos(2*pi*time))')]
transitions = [
    Transition(origin='S', destination='E', equation='beta_S*S*I',
               transition_type=TransitionType.T),
    Transition(origin='E', destination='I', equation='alpha*E',
               transition_type=TransitionType.T),
    Transition(origin='I', estination='R', equation='gamma*I',
               transition_type=TransitionType.T),
    ]
bd_list = [
   Transition(origin=states['S'][i], equation='mu*(S + E + I + R)', transition_type=TransitionType.B)]
   Transition(origin='time', equation='1', transition_type=TransitionType.B)
   ]

bd_list += [Transition(origin=item, equation='mu*'+item, transition_type=TransitionType.D) for item in actual_states]
    # initialize the model
    model = SimulateOde(state, param_list,
                               derived_param=derived_param,
                               transition=transition,
                               birth_death=bd_list)

The issue is that this would stochisticise time if the model.simulate_jump() method was called.

Installation

In addition to deprecation warnings, after running conda install -c conda-forge gcc to solve gcc not found I get the error:
error: command '/home/.../miniconda3/envs/pygom-test/bin/gcc' failed with exit code 1

Other tickets also report install issues.

Edit: this error is on hpc

RecursionError when unpickeling ode objects

simply save an ode object to a file via pickle and load it back

RecursionError                            Traceback (most recent call last)
<ipython-input-9-dce96bd264f0> in <module>
      1 with open('test.pkl', 'rb') as infile:
----> 2     ode2 = pickle.load(infile)

d:\git\pygom_github\pygom\model\ode_utils\compile_canary.py in __getattr__(self, name)
     60             return self._states
     61 
---> 62         if name in self._states:
     63             return self._states[name]
     64         msg = "'{0}' object has no attribute '{1}'"

d:\git\pygom_github\pygom\model\ode_utils\compile_canary.py in __getattr__(self, name)
     58         '''
     59         if name == '_states':
---> 60             return self._states
     61 
     62         if name in self._states:

... last 1 frames repeated, from the frame below ...

d:\git\pygom_github\pygom\model\ode_utils\compile_canary.py in __getattr__(self, name)
     58         '''
     59         if name == '_states':
---> 60             return self._states
     61 
     62         if name in self._states:

RecursionError: maximum recursion depth exceeded in comparison

MLE fitting only estimates maximum likelihood with regards to prediction not spread around prediction.

For transparencies sake I am posting the following email correspondence with Ediwn Tye the original author of PyGOM:

Dear Edwin

Thanks for the response. I did think for a while that not providing the differentials with regards to sigma would be ok if the user is fine with the assumption that variability does not change between predictions. For now I can make the same assumption with the negative binomial and gamma loss functions I am working on as extensions for PyGOM’s model fitting.

If it is ok with you I will raise this as an issue on the PyGOM github page and paste in this email thread for transparencies sake.

Yours Martin

Dr. Martin Grunnill
Senior Mathematical Modeller
Emergency Response Department (Science & Technology)
Public Health England
Manor Farm Rd
Porton Down
SP4 0JG
[email protected]
Tel: 01980612618
www.gov.uk/phe
Follow us on Twitter @PHE_uk

From: Edwin Tye #######@gmail.com
Sent: 29 March 2020 15:35
To: Martin Grunnill [email protected]
Subject: Re: OFFICIAL: Derivatives of Loss functions with Pygom

If you want to extend, then you should file an issue and raise a PR. That way, it will have a lot more visibility and transparency when you face audit one day.

On the loss functions, although I don't have the ability of open the python file now, the master branch on Github - which hopefully is up to date - does have a second derivative for the normal loss; Line 216. As you said, this is only for the estimation and the reason is that $\sigma$ is not an estimate. During the object initialization, you input $\sigma$, and is therefore a fixed value. The intended use is more on the lines of providing a Bayesian-like prior information.

You can argue that $\sigma$ should be estimated and that is not a bad idea. I never had the time, nor see the benefit in estimating $\sigma$ simply because estimating a scalar $\sigma$ is slightly pointless, while the vector $\mathbb{\sigma}$ is not statistically sound because the differential equation is time dependent, so you would need some sort of constraint in the form of say autoregressive models, i.e. $\sigma_{t+1} = \alpha \sigma_{t}, \alpha \in \left[ -1, 1 \right]$. If you want to use matrix $\mathbb{\Sigma}$ then I have nothing to say because I haven't thought about that scenario at all.

Edwin

On Sun, Mar 29, 2020 at 2:24 PM Martin Grunnill [email protected] wrote:
OFFICIAL

Dear Edwin

I am trying to extend Pygom to include fitting with negative binomial, gamma and binomial loss functions. In trying to understand the code I have been looking at the normal loss class (see attached .py file line 139). I am fairly new to model fitting algorithms and other than justifying why certain data conforms to a certain distribution I have tended to see them as a bit of black box. From doing some reading I understand that a lot of methods are based upon Newton type algorithms, using first and second derivative to hone in on the lowest negative log likelihood. What I can’t seem to understands with regards to PyGOM is why the normal loss class provides the 1st and 2nd derivatives with regards to the prediction (mean, \mu or yhat), but ignores the 1st and 2nd derivatives with regards to the spread around the prediction (sigma). With Poisson loss this wouldn’t be an issue as the mean = variance. However with normal loss couldn’t PyGOM make kind of mistake I have tried to illustrate in the attached pdf.

Please understand that I am fairly new to these sorts of algorithms, also I originally trained as a biologist and have simply picked up a lot of maths along the way.

Thanks very much for this. I hope I have been clear in explaining the issue. If not my work contact details are below, I think you have my mobile if not it is 0#########.

Yours Martin

Dr. Martin Grunnill
Senior Mathematical Modeller
Emergency Response Department (Science & Technology)
Public Health England
Manor Farm Rd
Porton Down
SP4 0JG
[email protected]
Tel: 01980612618
www.gov.uk/phe
Follow us on Twitter @PHE_uk
Why no derivatives of sigma.pdf

Initial time value

Improve error message for incorrect time initial condition model.initial_values
(when t[0] is greater than a value in simulation time t[1::]) .

Current message:
ValueError: The values in t must be monotonically increasing or monotonically decreasing; repeated values are allowed.

DFE (and hence R0) fails for conservative systems

For example, a simple SIR model should have disease free equilibrium equation given by S=N0, R=0 (or S=S0, R=N0-S0).
However, DFE(model,['I']) returns S=0, R=0. This also gives R0((model,['I']) = 0 when it should be (S/N)*(beta/alpha). The problem appears to be in epi_analysis.py line 49 where defaults are set to 0 which is invalid in this case.

Need to recompile the pyx files for newer Python?

A C file was throwing the error each time and manually recompiling the corresponding ".pyx" to overwrite the C file ending up sorting the issue.

If the devs want to know the issue, it was with "pygom/model/_tau_leap.c" and it threw the following error, tried on 3 different PC's (2x Windows 10 and 1 Windows 11):
pygom/model_tau_leap.c(18377): error C2105: '--' needs l-value
pygom/model_tau_leap.c(18686): error C2105: '++' needs l-value
pygom/model_tau_leap.c(18688): error C2105: '--' needs l-value
pygom/model_tau_leap.c(18936): error C2105: '++' needs l-value
pygom/model_tau_leap.c(18938): error C2105: '--' needs l-value
Recompiling this file using "cython pygom/model/_tau_leap.pyx" and then restarting setup removed this error.

Creating environment with yaml file

Is it possible to run the setup.py file at the same time as setting up the conda environment?

Can the following be added to the instal_requires list in the setup.py file.
sphinx>=1.4.1
sphinx_rtd_theme>=0.2.0
ipython
numpydoc

Read and write of sbml

Ability to read (and write) a SBML document, translating it into a usable class will greatly improve

1.. Reuse of existing model
2. Synchronization with other software

Parameters depending on compartment size

Hello,

I've been enjoying playing around a bit with this library - thank you!

A suggestion for an additional feature: Could you add functionality that allows ODEs to include parameters that are functions of compartment sizes? For example, to allow users to define force of infection as a function of the ODE variables and then use lambda in the ODEs themselves? This is straightforward to write into the ODEs for simple models, but it would be nice to be able to put in a more complex force of infection without making the ODEs very cumbersome.

SquareLoss with non-empty Target_State leads to failed minimize via .costIV

The problem is in the parsing of the Target_State for initial condition fitting. A list of lists is returned instead of a list of integer indices. Fixing this in base_loss.py corrected the error.
Professor John S. McCaskill, European Centre of Living Technology, Venice

def _getTargetStateIndex(self):
        """
        Get the indices of our targeted states
        """
        if self._targetState is None:
            index_list = range(self._num_state)
        else:
            # index_list = [self._ode.get_state_index(i) for i in self._targetState]   # original version
            index_list = list()                                                          # JSM
            for i in self._targetState:                                             # JSM
                index_list.extend(self._ode.get_state_index(i))    # JSM
        return index_list

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.