Skip to content

Instantly share code, notes, and snippets.

@kenjisato
Last active August 29, 2015 14:21
Show Gist options
  • Save kenjisato/07a51e08fbd790c020f8 to your computer and use it in GitHub Desktop.
Save kenjisato/07a51e08fbd790c020f8 to your computer and use it in GitHub Desktop.
2015 経済動学 講義資料 (2015-05-18)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
class System:
def __init__(self, f, dim):
self.f = f
self.dim = dim
def forward(self, x):
return self.f(x)
def simulate(s, *, start, steps):
x = np.array(start)
count = 0
while count < steps:
yield x
x = s.forward(x)
count += 1
def shoot(s, *, goal, steps):
for
if __name__ == "__main__":
def f(x):
A = np.array([[1.0, -0.5], [0.0, 1.0]])
return np.dot(A, x)
s = System(f, (2, 2))
path = simulate(s, start=[1., 1.], steps=10)
import numpy as np
class System:
def __init__(self, dim):
self.dim = dim
def forward(self, x):
pass
class Logistic(System):
def __init__(self, a):
self.a = a
super().__init__(dim=1)
# System.__init__(dim=1)
def forward(self, x):
return self.a * x * (1 - x)
class Tent(System):
def __init__(self, a):
self.a = a
super().__init__(dim=1)
def forward(self, x):
return self.a * min(x, 1 - x)
class Linear(System):
def __init__(self, A):
self.A = A
super().__init__(dim=A.shape[0])
def forward(self, x):
return np.dot(self.A, x)
class NoUse:
def forward(self, x):
return 2 * x
def run(system, x, steps):
for i in range(steps):
x1 = system.forward(x)
yield x
x = x1
# Generators
def logistic(x):
"""Logistic map"""
return 4 * x * (1 - x)
def logistic_path(x, length):
y = [x]
for _ in range(length - 1):
y.append(logistic(y[-1]))
return y
def logistic_gen(x, length):
for _ in range(length):
x1 = logistic(x)
yield x
x = x1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment