1 """Library of common model equation primitives.
2
3 Contains functions, expressions, etc.
4 """
5
6 from numpy import inf
7 from PyDSTool.MProject import ModelLibrary
8 import PyDSTool.ModelSpec
9 from PyDSTool.Symbolic import Fun
10
11 __all__ = ['threshold', 'linear_decay']
12
13
14
15 threshold = ModelLibrary('threshold',
16 spectype = Fun,
17 pars={'k': [-inf,inf]},
18 indepdomain={'x': [-inf,inf]},
19 depdomain=[0,1],
20 description="""Smooth R -> [0,1] functions of
21 one parameter that represent thresholds""")
22 tanh_spec = Fun('1+tanh(x/k)', ['x'], 'tanh_thresh')
23 logistic_spec = Fun('1/(1+exp(-k*x))', ['x'], 'logistic_thresh')
24 alg_spec = Fun('0.5*(1+x/(sqrt(k+x*x)))', ['x'], 'algebraic_thresh')
25
26
27 threshold.add_spec([tanh_spec, logistic_spec, alg_spec])
28
29
30 linear_decay = ModelLibrary('linear_decay',
31 spectype = Fun,
32 pars={'tau': [0,inf], 'x_inf': [-inf,inf]},
33 indepdomain={'x': [-inf,inf]},
34 depdomain=[-inf,inf],
35 description="""Linear decay given by two
36 parameters""")
37 linear_decay.add_spec(Fun('(x_inf-x)/tau', ['x'], 'linear'))
38