Exemplo n.º 1
0
def test_conv12():
    x = Symbol("x")
    y = Symbol("y")
    assert sinh(x / 3) == sinh(sympy.Symbol("x") / 3)
    assert cosh(x / 3) == cosh(sympy.Symbol("x") / 3)
    assert tanh(x / 3) == tanh(sympy.Symbol("x") / 3)
    assert coth(x / 3) == coth(sympy.Symbol("x") / 3)
    assert asinh(x / 3) == asinh(sympy.Symbol("x") / 3)
    assert acosh(x / 3) == acosh(sympy.Symbol("x") / 3)
    assert atanh(x / 3) == atanh(sympy.Symbol("x") / 3)
    assert acoth(x / 3) == acoth(sympy.Symbol("x") / 3)

    assert sinh(x / 3)._sympy_() == sympy.sinh(sympy.Symbol("x") / 3)
    assert cosh(x / 3)._sympy_() == sympy.cosh(sympy.Symbol("x") / 3)
    assert tanh(x / 3)._sympy_() == sympy.tanh(sympy.Symbol("x") / 3)
    assert coth(x / 3)._sympy_() == sympy.coth(sympy.Symbol("x") / 3)
    assert asinh(x / 3)._sympy_() == sympy.asinh(sympy.Symbol("x") / 3)
    assert acosh(x / 3)._sympy_() == sympy.acosh(sympy.Symbol("x") / 3)
    assert atanh(x / 3)._sympy_() == sympy.atanh(sympy.Symbol("x") / 3)
    assert acoth(x / 3)._sympy_() == sympy.acoth(sympy.Symbol("x") / 3)
Exemplo n.º 2
0
def test_conv12b():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    assert sympify(sympy.sinh(x/3)) == sinh(Symbol("x") / 3)
    assert sympify(sympy.cosh(x/3)) == cosh(Symbol("x") / 3)
    assert sympify(sympy.tanh(x/3)) == tanh(Symbol("x") / 3)
    assert sympify(sympy.coth(x/3)) == coth(Symbol("x") / 3)
    assert sympify(sympy.asinh(x/3)) == asinh(Symbol("x") / 3)
    assert sympify(sympy.acosh(x/3)) == acosh(Symbol("x") / 3)
    assert sympify(sympy.atanh(x/3)) == atanh(Symbol("x") / 3)
    assert sympify(sympy.acoth(x/3)) == acoth(Symbol("x") / 3)
Exemplo n.º 3
0
def test_conv12():
    x = Symbol("x")
    y = Symbol("y")
    assert sinh(x/3) == sinh(sympy.Symbol("x") / 3)
    assert cosh(x/3) == cosh(sympy.Symbol("x") / 3)
    assert tanh(x/3) == tanh(sympy.Symbol("x") / 3)
    assert coth(x/3) == coth(sympy.Symbol("x") / 3)
    assert asinh(x/3) == asinh(sympy.Symbol("x") / 3)
    assert acosh(x/3) == acosh(sympy.Symbol("x") / 3)
    assert atanh(x/3) == atanh(sympy.Symbol("x") / 3)
    assert acoth(x/3) == acoth(sympy.Symbol("x") / 3)

    assert sinh(x/3)._sympy_() == sympy.sinh(sympy.Symbol("x") / 3)
    assert cosh(x/3)._sympy_() == sympy.cosh(sympy.Symbol("x") / 3)
    assert tanh(x/3)._sympy_() == sympy.tanh(sympy.Symbol("x") / 3)
    assert coth(x/3)._sympy_() == sympy.coth(sympy.Symbol("x") / 3)
    assert asinh(x/3)._sympy_() == sympy.asinh(sympy.Symbol("x") / 3)
    assert acosh(x/3)._sympy_() == sympy.acosh(sympy.Symbol("x") / 3)
    assert atanh(x/3)._sympy_() == sympy.atanh(sympy.Symbol("x") / 3)
    assert acoth(x/3)._sympy_() == sympy.acoth(sympy.Symbol("x") / 3)
Exemplo n.º 4
0
def test_conv12b():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    assert sympify(sympy.sinh(x / 3)) == sinh(Symbol("x") / 3)
    assert sympify(sympy.cosh(x / 3)) == cosh(Symbol("x") / 3)
    assert sympify(sympy.tanh(x / 3)) == tanh(Symbol("x") / 3)
    assert sympify(sympy.coth(x / 3)) == coth(Symbol("x") / 3)
    assert sympify(sympy.asinh(x / 3)) == asinh(Symbol("x") / 3)
    assert sympify(sympy.acosh(x / 3)) == acosh(Symbol("x") / 3)
    assert sympify(sympy.atanh(x / 3)) == atanh(Symbol("x") / 3)
    assert sympify(sympy.acoth(x / 3)) == acoth(Symbol("x") / 3)
Exemplo n.º 5
0
def diffable_sign(x):
    """
    !Returns shit if x is very close to but not equal to zero!
    if x > 0:
        return 1
    if x < 0:
        return -1
    if x == 0:
        return 0

    :type x: Union[float, Symbol]
    :return: sign(x)
    :rtype: Union[float, Symbol]
    """
    # return x/(-VERY_SMALL_NUMBER + diffable_abs(x))
    return (tanh(x * 1e105))
Exemplo n.º 6
0
def conditional(observable, threshold, value_if, value_else, width=None):
    """
		Provides an smoothed and thus integrator-friendly version of a conditional statement. For most purposes, you can imagine this being equivalent to:
		
		.. code-block:: Python
		
			def conditional(observable,threshold,value_if,value_else):
				if observable<threshold:
					return value_if
				else:
					return value_else
		
		The import difference is that this is smooth and evaluated at runtime.
		
		`width` controls the steepness of the sigmoidal used to implement this. If not specified, this will be guessed – from the threshold if possible.
	"""
    if width is None:
        if sympify(threshold).is_number and threshold != 0:
            width = threshold / 100000
        else:
            width = 1e-5

    return value_if + (1 + tanh(
        (observable - threshold) / width)) / 2 * (value_else - value_if)
import numpy as np
from jitcode import jitcode, y
from symengine import exp, log, sqrt, tanh, sympify

def wrapper():
    tDrugApplication = 10000
    INaFRedMed = 1
    ICaLRedMed = 1
    IKrRedMed = 1
    IKsRedMed = 1

    return Paci2018(tDrugApplication, INaFRedMed,
             ICaLRedMed, IKrRedMed, IKsRedMed)

sigmoid = lambda x: (tanh(x)+1)/2

SHARPN_COEFF = 1e5
def conditional(trigger,threshold,untriggered_value,triggered_value,sharpness=None):
    if sharpness is None:
        if sympify(threshold).is_number and threshold:
            sharpness = SHARPN_COEFF*abs(threshold)
        else:
            sharpness = SHARPN_COEFF
    
    return untriggered_value + sigmoid((trigger-threshold)*sharpness)*(triggered_value-untriggered_value)

def Paci2018(tDrugApplication, INaFRedMed,ICaLRedMed, IKrRedMed, IKsRedMed):
    dY = [None]*23

    '''
    Parameters from optimizer   
Exemplo n.º 8
0
ε = [0.03966, 0.03184, 0.02847]
ν = [1, 2.033, 3.066]
μ = [0.16115668456085775, 0.14093420256851111, 0.11465065353644151]
ybar_0 = 0
τ = 1.7735
ζ = [0.017940997406325931, 0.015689701773967984, 0.012763648066925721]

ydot = [y(i) for i in range(3, 6)]
y_tot = lambda time: sum(y(i, time) for i in range(3))
ydot_tot = lambda time: sum(y(i, time) for i in range(3, 6))
yddot_tot = lambda time: sum(dy(i, time) for i in range(3, 6))

f = {y(i): ydot[i] for i in range(3)}
f.update({
    ydot[i]: μ[i] * sech(ybar_0 - y_tot(t - τ))**2 *
    (yddot_tot(t - τ) + 2 * ydot_tot(t - τ)**2 * tanh(ybar_0 - y_tot(t - τ))) -
    2 * ζ[i] * abs(y_tot(t)) * ydot_tot(t) - ε[i] * ν[i] * ydot[i] -
    ν[i]**2 * y(i)
    for i in range(3)
})

DDE = jitcdde(f, verbose=False)

np.random.seed(23)
DDE.constant_past(np.random.normal(0, 1, 6))
DDE.adjust_diff()

for time in DDE.t + np.arange(0.1, 100, 0.1):
    print(time, *DDE.integrate(time))
Exemplo n.º 9
0
 def tau_h(self, V):
     return self.th0 + self.th1 * (1 - sym_backend.tanh(
         (V - self.vht) / self.dvht)**2)
Exemplo n.º 10
0
 def tau_n(self, V):
     return self.tn0 + self.tn1 * (1 - sym_backend.tanh(
         (V - self.vnt) / self.dvnt)**2)
Exemplo n.º 11
0
 def tau_x(self, V, theta, sigma, t0, t1):
     return t0 + t1 * (1.0 - sym_backend.tanh((V - theta) / sigma)**2)
Exemplo n.º 12
0
 def u0(self, V):
     return 0.5 * (1 - sym_backend.tanh(0.5 * (V + 78) / 6.0))
Exemplo n.º 13
0
 def m0(self, V):
     return 0.5 * (1 + sym_backend.tanh((V - self.vm) / self.dvm))
Exemplo n.º 14
0
 def tau_x(self, Vm, V_0, sigma_x, tau_x_0, tau_x_1):
     return tau_x_0 + tau_x_1 * (1 - (sym_backend.tanh(
         (Vm - V_0) / sigma_x))**2)
Exemplo n.º 15
0
 def r_inf(self, V):
     return 0.5 * (1.0 - sym_backend.tanh(-0.5 * (V - self.Vp) / self.Kp))
Exemplo n.º 16
0
 def v0(self, V):
     return 0.5 * (1 - sym_backend.tanh(0.5 * (V + 25.0) / 12.0))
Exemplo n.º 17
0
 def s0(self, V):
     return 0.5 * (1 - sym_backend.tanh(-0.5 * (V + 20.0) / 6.5))
Exemplo n.º 18
0
 def tu(self, V):
     return 0.27/(sym_backend.exp((V+46)/5.0)+sym_backend.exp(-(V+238)/37.5)) \
                 +5.1/2*(1+sym_backend.tanh((V+57)/3))
Exemplo n.º 19
0
 def n0(self, V):
     return 0.5 * (1 + sym_backend.tanh((V - self.vn) / self.dvn))
Exemplo n.º 20
0
 def z0(self, V):
     return 0.5 * (1 - sym_backend.tanh(-0.5 * (V + 60) / 8.5))
Exemplo n.º 21
0
difference = Symbol("difference")
factor_μ = Symbol("factor_μ")
factor_ζ = Symbol("factor_ζ")

ydot = [y(i) for i in range(3, 6)]
y_tot = sum(current_y(i) for i in range(3))
ydot_tot = sum(current_y(i) for i in range(3, 6))
y_past = sum(past_y(t - τ, i, anchors_past) for i in range(3))
ydot_past = sum(past_y(t - τ, i, anchors_past) for i in range(3, 6))
yddot_past = sum(past_dy(t - τ, i, anchors_past) for i in range(3, 6))

helpers = {
    (anchors_past, anchors(t - τ)),
    (difference, ybar_0 - y_past),
    (factor_μ,
     sech(difference)**2 * (yddot_past + 2 * ydot_past**2 * tanh(difference))),
    (factor_ζ, 2 * abs(y_tot) * ydot_tot),
}

f = {y(i): ydot[i] for i in range(3)}
f.update({
    ydot[i]:
    μ[i] * factor_μ - ζ[i] * factor_ζ - ε[i] * ν[i] * ydot[i] - ν[i]**2 * y(i)
    for i in range(3)
})

DDE = jitcdde(f, helpers=helpers, verbose=False)

np.random.seed(23)
DDE.constant_past(np.random.normal(0, 1, 6))
DDE.adjust_diff()
Exemplo n.º 22
0
 def h0(self, V):
     return 0.5 * (1 + sym_backend.tanh((V - self.vh) / self.dvh))
Exemplo n.º 23
0
 def tau_m(self, V):
     return self.tm0 + self.tm1 * (1 - sym_backend.tanh(
         (V - self.vmt) / self.dvmt)**2)
Exemplo n.º 24
0
 def x_eqm(self, V, theta, sigma):
     return 0.5 * (1.0 - sym_backend.tanh(0.5 * (V - theta) / sigma))