From 6166f96589347f92ff10026c0dd295502e0218e6 Mon Sep 17 00:00:00 2001 From: Jeffrey Lai Date: Sun, 29 Dec 2024 01:28:39 -0800 Subject: [PATCH] update some dysts json metadata - parameterize some hardcoded constants - clean up circadian rhythm - update unbounded indices --- dysts/data/chaotic_attractors.json | 44 ++++++++++--- dysts/flows.py | 101 ++++++++++++----------------- tests/test_ensemble.py | 1 - 3 files changed, 74 insertions(+), 72 deletions(-) diff --git a/dysts/data/chaotic_attractors.json b/dysts/data/chaotic_attractors.json index 5e81f32..c9fcab8 100644 --- a/dysts/data/chaotic_attractors.json +++ b/dysts/data/chaotic_attractors.json @@ -349,7 +349,7 @@ }, "period": 2.9520625, "pesin_entropy": 5.617567417119514, - "unbounded_indices": [0, 1, 2], + "unbounded_indices": [1, 2], "mean": [0.20578754423965043, -0.022789280675006653, 0.006181954059999296], "std": [0.47387058648171193, 0.39966045251784715, 0.7098035797292681] }, @@ -379,7 +379,7 @@ }, "period": 2.7616666666666667, "pesin_entropy": 4.877593783333199, - "unbounded_indices": [0, 1, 2], + "unbounded_indices": [1, 2], "mean": [0.09628302338811898, 0.051081909007632376, 0.014044835128269546], "std": [0.5173893273874359, 0.5621146168812219, 0.7058063557135066] }, @@ -751,12 +751,13 @@ "km": 0.4, "ks": 1, "n": 4, + "ps": 24, + "vc": 2.5, "vd": 6, "vdn": 1.5, "vm": 0.7, "vmax": 4.7, - "vmin": 1.0, - "vs": 6 + "vmin": 1.0 }, "period": 27.0, "pesin_entropy": 0.09372724379002938, @@ -978,8 +979,11 @@ "multiscale_entropy": 0.5591104791210428, "nonautonomous": false, "parameters": { - "d": 1.0, - "m": 1.0 + "g": 9.81, + "l1": 1.0, + "l2": 1.0, + "m1": 1.0, + "m2": 1.0 }, "period": 4.0234, "pesin_entropy": 8.928560651305366, @@ -1045,12 +1049,31 @@ "multiscale_entropy": 0.7807524009298388, "nonautonomous": false, "parameters": { + "aho": 2.5, + "ahr": 0.05, + "ahs": 0.07, + "ams": 0.1, + "amvb": 25, + "amvo": 2.5, + "ans": 0.01, + "anvb": 20, + "anvo": 2, + "ar": 0.1, + "bho": 2.0, + "bhr": 0.1, + "bmo": 2.7777777777777777778, + "bmr": 0.0555555555555555556, + "bms": 4.0, + "bno": 0.375, + "bnr": 0.0125, + "bns": 0.125, "gi": 1800, "gkc": 11, "gkv": 1700, "gl": 7, "kc": 0.183333, "rho": 0.27, + "tscl": 230, "vc": 100, "vi": 100, "vk": -75, @@ -1144,7 +1167,7 @@ "w": 0.81 }, "period": 20.411, - "pesin_entropy": 0.0028307087627546254, + "entropy": 0.0028307087627546254, "unbounded_indices": [2], "mean": [0.39605874701368277, 2.7397572605387843, -0.008946634312398942], "std": [0.14966981525041267, 0.3908426287195323, 0.7076296217622412] @@ -2024,7 +2047,7 @@ }, "period": 28.822573200111794, "pesin_entropy": 0.9110009439099345, - "unbounded_indices": [2], + "unbounded_indices": [1,2], "mean": [-0.08706186157906316, 0.003099475891320229, 0.001757118959650587], "std": [0.4963566077805293, 0.5089387987269263, 0.7072246055642845] }, @@ -2775,7 +2798,7 @@ }, "period": 23.857, "pesin_entropy": 0.4274159768365288, - "unbounded_indices": [0, 1], + "unbounded_indices": [0, 2], "mean": [-0.0017403093986211205, 1.6642129379690616, 0.010636631704986098], "std": [0.6958702046098053, 0.9076069739985229, 0.7071664907860569] }, @@ -3900,7 +3923,7 @@ }, "period": 0.3417647058823529, "pesin_entropy": 10.773094126465404, - "unbounded_indices": [], + "unbounded_indices": [1], "mean": [ 0.09117893552133338, 0.07467874204049706, -0.1279534926442416, 0.08471804040163511 @@ -4044,6 +4067,7 @@ "e": 0.5, "g": 0.1, "h": 0.8, + "lamb": 1.0, "r": 8.12, "s": 1.25 }, diff --git a/dysts/flows.py b/dysts/flows.py index a291fb0..182358b 100755 --- a/dysts/flows.py +++ b/dysts/flows.py @@ -142,23 +142,23 @@ class ThomasLabyrinth(Thomas): class DoublePendulum(DynSys): @staticjit - def _rhs(th1, th2, p1, p2, t, d, m): - g = 9.82 - pre = 6 / (m * d**2) - denom = 16 - 9 * np.cos(th1 - th2) ** 2 - th1_dot = pre * (2 * p1 - 3 * np.cos(th1 - th2) * p2) / denom - th2_dot = pre * (8 * p2 - 3 * np.cos(th1 - th2) * p1) / denom - p1_dot = ( - -0.5 - * (m * d**2) - * (th1_dot * th2_dot * np.sin(th1 - th2) + 3 * (g / d) * np.sin(th1)) - ) - p2_dot = ( - -0.5 - * (m * d**2) - * (-th1_dot * th2_dot * np.sin(th1 - th2) + 3 * (g / d) * np.sin(th2)) - ) - return th1_dot, th2_dot, p1_dot, p2_dot + def _rhs(th1, th2, p1, p2, t, g, l1, l2, m1, m2): + cos_diff = np.cos(th1 - th2) + sin_diff = np.sin(th1 - th2) + denom = l1 * l2 * (m1 + m2 * sin_diff**2) + + th1dot = (l2 * p1 - l1 * p2 * cos_diff) / (l1 * denom) + th2dot = ((m1 + m2) * l1 * p2 - m2 * l2 * p1 * cos_diff) / (m2 * l2 * denom) + + h1 = p1 * p2 * sin_diff / denom + h2 = (m2 * l2 * p1**2) / (2 * l1 * denom**2) + h2 += 0.5 * m2 * p2 * l2 * l1 * th2dot / denom + h2 *= np.sin(2 * (th1 - th2)) + + p1dot = -(m1 + m2) * g * l1 * np.sin(th1) - h1 + h2 + p2dot = -m2 * g * l2 * np.sin(th2) + h1 - h2 + + return th1dot, th2dot, p1dot, p2dot @staticmethod @staticjit @@ -736,8 +736,7 @@ def _rhs( z0, ): ybar = (1 / y0) * yb1 * z * v / (yb2 * x + yb3 + kf) - if x < 0.0: - x = 0 + x = max(0, x) rf = (ci - z0 * z) * np.sqrt(x) xdot = c1 * x * ybar + c2 * ybar + c3 * x**2 + c4 * rf + c5 * x * z - kf * x zdot = (c6 / z0) * rf + c7 * x * z + c8 * z * v + c9 * z - kf * z @@ -1409,14 +1408,14 @@ class ChenLee(DynSys): def _rhs(x, y, z, t, a, b, c): xdot = a * x - y * z ydot = b * y + x * z - zdot = c * z + 0.3333333333333333333333333 * x * y + zdot = c * z + (1 / 3) * x * y return xdot, ydot, zdot @staticjit def _jac(x, y, z, t, a, b, c): row1 = [a, -z, -y] row2 = [z, b, x] - row3 = [0.3333333333333333333333333 * y, 0.3333333333333333333333333 * x, c] + row3 = [(1 / 3) * y, (1 / 3) * x, c] return row1, row2, row3 @@ -1698,18 +1697,18 @@ class ExcitableCell(DynSys): def rhs(self, X, t): v, n, c = X - alpham = 0.1 * (25 + v) / (1 - np.exp(-0.1 * v - 2.5)) - betam = 4 * np.exp(-(v + 50) / 18) + alpham = self.ams * (self.amvb + v) / (1 - np.exp(-self.ar * v - self.amvo)) + betam = self.bms * np.exp(-self.bmr * v - self.bmo) minf = alpham / (alpham + betam) - alphah = 0.07 * np.exp(-0.05 * v - 2.5) - betah = 1 / (1 + np.exp(-0.1 * v - 2)) + alphah = self.ahs * np.exp(-self.ahr * v - self.aho) + betah = 1 / (1 + np.exp(-self.bhr * v - self.bho)) hinf = alphah / (alphah + betah) - alphan = 0.01 * (20 + v) / (1 - np.exp(-0.1 * v - 2)) - betan = 0.125 * np.exp(-(v + 30) / 80) + alphan = self.ans * (self.anvb + v) / (1 - np.exp(-self.ar * v - self.anvo)) + betan = self.bns * np.exp(-self.bnr * v - self.bno) ninf = alphan / (alphan + betan) - tau = 1 / (230 * (alphan + betan)) + tau = 1 / (self.tscl * (alphan + betan)) ca = c / (1 + c) @@ -1774,36 +1773,16 @@ def rhs(self, X, t): class CircadianRhythm(DynSys): - @staticjit - def _rhs( - m, - fc, - fs, - fn, - th, - t, - Ki, - k, - k1, - k2, - kd, - kdn, - km, - ks, - n, - vd, - vdn, - vm, - vmax, - vmin, - v, - ): - vs = 2.5 * ((0.5 + 0.5 * np.cos(th)) + vmin) * (vmax - vmin) - mdot = vs * (Ki**n) / (Ki**n + fn**n) - vm * m / (km + m) - fcdot = ks * m - k1 * fc + k2 * fn - k * fc - fsdot = k * fc - vd * fs / (kd + fs) - fndot = k1 * fc - k2 * fn - vdn * fn / (kdn + fn) - thdot = 2 * np.pi / 24 + def rhs(self, X, t): + m, fc, fs, fn, th = X + vs = self.vc * ((0.5 + 0.5 * np.cos(th)) + self.vmin) * (self.vmax - self.vmin) + mdot = vs * (self.Ki**self.n) / (self.Ki**self.n + fn**self.n) - self.vm * m / ( + self.km + m + ) + fcdot = self.ks * m - self.k1 * fc + self.k2 * fn - self.k * fc + fsdot = self.k * fc - self.vd * fs / (self.kd + fs) + fndot = self.k1 * fc - self.k2 * fn - self.vdn * fn / (self.kdn + fn) + thdot = 2 * np.pi / self.ps return mdot, fcdot, fsdot, fndot, thdot @staticjit @@ -1817,7 +1796,7 @@ def _rhs(x, y, th, t, gamma, psi, w): xdot = y ydot = -1 - np.heaviside(-x, 0) * (x + psi * y * np.abs(y)) + gamma * np.cos(th) thdot = w - return (xdot, ydot, thdot) + return xdot, ydot, thdot @staticjit def _postprocessing(x, y, th): @@ -1999,7 +1978,7 @@ def _rhs(x, y, z, t, a, alpha1, alpha2, b, c, k1, k2, zs): class TurchinHanski(DynSys): @staticjit - def _rhs(n, p, z, t, a, d, e, g, h, r, s): + def _rhs(n, p, z, t, a, d, e, g, h, lamb, r, s): ndot = ( r * (1 - e * np.sin(z)) * n - r * (n**2) @@ -2007,7 +1986,7 @@ def _rhs(n, p, z, t, a, d, e, g, h, r, s): - a * n * p / (n + d) ) pdot = s * (1 - e * np.sin(z)) * p - s * (p**2) / n - zdot = 2 * np.pi + zdot = 2 * np.pi * lamb return ndot, pdot, zdot @staticjit diff --git a/tests/test_ensemble.py b/tests/test_ensemble.py index f5c1bd6..3a1e2b5 100644 --- a/tests/test_ensemble.py +++ b/tests/test_ensemble.py @@ -109,7 +109,6 @@ def test_ensemble_generation_parameter_sampling(self): scale=1e-4, random_seed=random.randint(0, 1000000) ) system_sample = random.sample(get_attractor_list(sys_class="continuous"), 4) - system_sample += ["InteriorSquirmer"] systems = [getattr(dfl, sys)() for sys in system_sample] unperturbed_sols = make_trajectory_ensemble( 256,