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 f(z): | |
y = 1/(1+exp(-z)) | |
return y |
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
# importing the necessary modules | |
import numpy as np | |
from itertools import product | |
from math import exp | |
from scipy.stats import uniform | |
inputs = list(product([-1,1], repeat=10)) # a list of all the input vectors | |
# more precisely this function returns | |
# the 1024 possible permutations of the | |
# 10-dimensional binary sequence in the |
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 scipy.stats import uniform | |
n_cities = 500 | |
coords = uniform.rvs(size=n_cities) + uniform.rvs(size=n_cities)*1j | |
def dist(a, b): # calculates distance between two points | |
d = abs(a - b) | |
return d | |
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 | |
u = [1,3,5,2,7,8,10] | |
v = [5,2,7,2,3,10,4] | |
M = np.outer(u, v) | |
print(M) |
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
u = [1,3,5,2,7,8,10] | |
v = [5,2,7,2,3,10,4] | |
M = list(map(lambda i, j: i * j, | |
[i for i in u for j in v], | |
v*len(u))) | |
print(M) |
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
u = [1,3,5,2,7,8,10] | |
v = [5,2,7,2,3,10,4] | |
M = [i * j for i in u for j in v] | |
print(M) |
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
u = [1,3,5,2,7,8,10] | |
v = [5,2,7,2,3,10,4] | |
M = [] | |
for i in u: | |
row = [] | |
for j in v: | |
row.append(i * j) |
NewerOlder