This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
# This function creates a linearized | |
# function for f at the point $x_0$. | |
def linearise(f, f_p, x_0): | |
f_lin = lambda x: f(x_0) + f_p(x_0) * (x - x_0) | |
return f_lin | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
f = lambda x: x**2 # x² is the function to linearize. | |
x_1 = -1.0 | |
x_2 = 1.0 | |
x_3 = 1.0 | |
x_4 = 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sympy import symbols, expand, diff | |
from sympy.solvers import solve | |
import matplotlib.pyplot as plt | |
X = np.linspace(0, 5, 100) | |
p = lambda x: (x - 1) * (x - 3) * (x - 5) | |
Y = [p(x) for x in X] | |
# We create a variable: x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import jax.numpy as jnp | |
from jax import grad | |
from entmax_jax import entmax, entmax15, sparsemax | |
# Decision based on a threshold | |
def decision(params, features): | |
weights = params['weights'] | |
bias = params['bias'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
torus_width = 10 | |
torus_height = 10 | |
torus = [[[((x+i) % torus_width), ((y+j) % torus_height)] for j in range(-1,2)] for i in range(-1,2) for x in range(torus_width) for y in range(torus_height)] | |
def find_closed_path(start_pos, torus): | |
visited = set() | |
stack = [(start_pos, [])] | |
while stack: | |
curr_pos, curr_path = stack.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
torus_width = 10 | |
torus_height = 10 | |
torus = [[[((x+i) % torus_width), ((y+j) % torus_height)] for j in range(-1,2)] for i in range(-1,2) for x in range(torus_width) for y in range(torus_height)] | |
def find_closed_path(start_pos, torus): | |
visited = set() | |
stack = [(start_pos, [])] | |
while stack: | |
curr_pos, curr_path = stack.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_closed_path(start_pos, torus): | |
visited = set() | |
stack = [(start_pos, [])] | |
while stack: | |
curr_pos, curr_path = stack.pop() | |
if curr_pos in visited: | |
continue | |
visited.add(curr_pos) | |
curr_path.append(curr_pos) | |
for neighbor_coords in torus[curr_pos[0]][curr_pos[1]]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
torus_width = 10 | |
torus_height = 10 | |
torus = [[[((x+i) % torus_width), ((y+j) % torus_height)] for j in range(-1,2)] for i in range(-1,2) for x in range(torus_width) for y in range(torus_height)] | |
def find_closed_path(start_pos, torus): | |
visited = set() | |
stack = [(start_pos, [])] | |
while stack: | |
curr_pos, curr_path = stack.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_closed_path(start_pos, torus): | |
visited = set() | |
stack = [(start_pos, [])] | |
while stack: | |
curr_pos, curr_path = stack.pop() | |
if curr_pos in visited: | |
continue | |
visited.add(curr_pos) | |
curr_path.append(curr_pos) | |
for neighbor in torus[curr_pos[0]][curr_pos[1]]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
torus_width = 10 | |
torus_height = 10 | |
torus = [[[((x+i) % torus_width), ((y+j) % torus_height)] for j in range(-1,2)] for i in range(-1,2) for x in range(torus_width) for y in range(torus_height)] |