. Neural Networks
[10]:
123456789101112131415161718192021222324252627282930313233343536373839
from math import exp
from scipy.special import expit
import numpy as np
class ANN():
def __init__(self) -> None:
self.input_nodes=None
self.weights_dict={}
self.activation_dict={}
self.outputs_dict={}
def apply_activation(self,array,activation):
if activation=='sigmoid':
return 1/(1+np.exp(array))
elif activation=='relu':
np.maximum(0,array)
def add_input_layer(self,nodes):
self.input_nodes=nodes
def add_layer(self,nodes,activation):
if not self.weights_dict:
self.weights_dict[1]=np.random.rand(0,1,[self.input_nodes,nodes])
self.activation_dict[1]=activation
else:
self.weights_dict[max(self.weights_dict.keys())+1]=np.random.rand(0,1,[len(self.weights_dict[max(self.weights_dict.keys())]),nodes])
self.activation_dict[max(self.activation_dict.keys())+1]=activation
def fwd_pass(self,input_metrix,activation):
"""use 0 for input layer in layers vairable """
for i in self.weights_dict.keys():
if i==1:
self.outputs_dict[i]=self.apply_activation(np.dot(input_metrix,self.weights_dict[i]),activation)
else:
self.outputs_dict[i]=self.apply_activation(np.dot(self.outputs_dict[i-1],self.weights_dict[i-1]),activation)
def backwd_pass(self):
pass
[20]:
12
import numpy as np
np.random.uniform(0,1,[2,2])Out[20]:
array([[0.45748296, 0.29055574],
[0.79272817, 0.46421864]])
[47]:
123
inp=np.array([[1,2]])
weights=np.ones([2,3])
np.dot(inp,weights)Out[47]:
array([[3., 3., 3.]])
[37]:
12345678910
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
# Compute the cross product
result = np.cross(a, b)
# Output: array([-3, 6, -3])
result
Out[37]:
array([-3, 6, -3])
Previous
Start of course
Next
Introduction To Deep Learning