Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
eigenvals_cb = self._jac_eigenvals_svd
if xyp is None:
x, y, intern_p = self._internal
else:
x, y, intern_p = self.pre_process(*xyp)
singular_values = []
for xval, yvals in zip(x, y):
singular_values.append(eigenvals_cb(xval, yvals, intern_p))
return (np.abs(singular_values).max(axis=-1) /
np.abs(singular_values).min(axis=-1))
class OdeSys(ODESys):
""" DEPRECATED, use ODESys instead. """
pass
def _new_x(xout, x, guaranteed_autonomous):
if guaranteed_autonomous:
return 0, abs(x[-1] - xout[-1]) # rounding
else:
return xout[-1], x[-1]
def integrate_auto_switch(odes, kw, x, y0, params=(), **kwargs):
""" Auto-switching between formulations of ODE system.
In case one has a formulation of a system of ODEs which is preferential in
the beginning of the integration, this function allows the user to run the
def _reinsert(indices, arr, new):
trail_dim = arr.shape[-1]+len(indices)
new_arr = np.empty(arr.shape[:-1] + (trail_dim,))
idx_arr, idx_insert = 0, 0
for glbl in range(trail_dim):
if glbl in indices:
new_arr[..., glbl] = new[..., idx_insert]
idx_insert += 1
else:
new_arr[..., glbl] = arr[..., idx_arr]
idx_arr += 1
return new_arr
class SymbolicSys(ODESys):
""" ODE System from symbolic expressions
Creates a :class:`ODESys` instance
from symbolic expressions. Jacobian and second derivatives
are derived when needed.
Parameters
----------
dep_exprs : iterable of (symbol, expression)-pairs
indep : Symbol
Independent variable (default: None => autonomous system).
params : iterable of symbols
Problem parameters. If ``None``: zero parameters assumed (violation of this will
raise a ValueError), If ``True``: params are deduced from (sorted) free_symbols.
jac : ImmutableMatrix or bool (default: True)
if True:
>>> mask1 = res.xout <= 2
>>> import numpy as np
>>> np.allclose(res.yout[mask1, 0], 42*np.exp(-.7*res.xout[mask1]))
True
>>> mask2 = 2 <= res.xout
>>> np.allclose(res.yout[mask2, 0], res.yout[mask2, 0][0]*np.exp(-.1*(res.xout[mask2] - res.xout[mask2][0])))
True
"""
assert len(durations) > 0, 'need at least 1 duration (preferably many)'
assert npoints > 0, 'need at least 1 point per duration'
for k, v in varied_params.items():
if len(v) != len(durations):
raise ValueError("Mismathced lengths of durations and varied_params")
if isinstance(subject, ODESys):
integrate = subject.integrate
numpy = numpy or subject.numpy
else:
integrate = subject
numpy = numpy or np
default_params = default_params or {}
integrate_kwargs = integrate_kwargs or {}
def _get_idx(cont, idx):
if isinstance(cont, dict):
return {k: (v[idx] if hasattr(v, '__len__') and getattr(v, 'ndim', 1) > 0 else v)
for k, v in cont.items()}
else:
return cont[idx]