├── tree ├── traversal.py ├── main.pyc └── main.py ├── eratosthenes └── main.py ├── linked_list └── main.py ├── bst_validator └── main.py ├── Files ├── data.txt └── main.py ├── gif └── main.py ├── README.md ├── openpyxl ├── test.xlsx └── main.py ├── password_generator ├── main.pyc └── main.py ├── queue └── main.py ├── ynonperek └── Basic_Syntax │ ├── 1.py │ └── 2.py ├── bubble_sort └── main.py ├── fibonacci ├── main.py └── recursive.py ├── binary_search ├── Python3 │ └── main.py └── Python2 │ └── main.py ├── hanoi └── main.py ├── bogo_sort └── main.py ├── testing └── main.py ├── insertion_sort └── main.py ├── selection_sort └── main.py ├── merge_sort └── main.py ├── dictionary └── main.py ├── heap └── main.py ├── linear_regression └── main.py ├── quicksort_inplace └── main.py ├── quicksort └── main.py ├── linked_list_sort └── main.py ├── linked_list_sort_alphabetical └── main.py ├── linked_list_sort_custom └── main.py ├── graham_scan └── main.py └── perceptron └── main.py /tree/traversal.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /eratosthenes/main.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /linked_list/main.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bst_validator/main.py: -------------------------------------------------------------------------------- 1 | 2 | class -------------------------------------------------------------------------------- /Files/data.txt: -------------------------------------------------------------------------------- 1 | This is some sample data... -------------------------------------------------------------------------------- /gif/main.py: -------------------------------------------------------------------------------- 1 | 2 | import imageio 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python_Algorithms 2 | Code for various YouTube video lessons + extras 3 | -------------------------------------------------------------------------------- /tree/main.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bfaure/Python_Algorithms/HEAD/tree/main.pyc -------------------------------------------------------------------------------- /openpyxl/test.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bfaure/Python_Algorithms/HEAD/openpyxl/test.xlsx -------------------------------------------------------------------------------- /password_generator/main.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bfaure/Python_Algorithms/HEAD/password_generator/main.pyc -------------------------------------------------------------------------------- /queue/main.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import Queue 4 | 5 | test = Queue.Queue() 6 | 7 | test.put(1) 8 | test.put(2) 9 | test.put(3) 10 | 11 | print test.get() -------------------------------------------------------------------------------- /openpyxl/main.py: -------------------------------------------------------------------------------- 1 | 2 | from openpyxl import Workbook 3 | 4 | wb=Workbook() 5 | 6 | ws=wb.active 7 | 8 | ws['A1']="This is a test" 9 | 10 | wb.save('test.xlsx') 11 | 12 | 13 | -------------------------------------------------------------------------------- /ynonperek/Basic_Syntax/1.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | write a program that asks the user for an integer and prints 4 | the sum of its digits 5 | ''' 6 | 7 | val=raw_input("Enter an integer:") 8 | tot=sum([int(e) for e in str(val)]) 9 | print "Sum of digits: %d"%tot -------------------------------------------------------------------------------- /ynonperek/Basic_Syntax/2.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | write a program that takes a filename as command line argument, 4 | count how many times each word appears in the file and prints the 5 | word that appears the most, along with it's count 6 | ''' 7 | 8 | import sys 9 | print sys.argv 10 | -------------------------------------------------------------------------------- /bubble_sort/main.py: -------------------------------------------------------------------------------- 1 | 2 | def bubble_sort(arr): 3 | swapped=True 4 | while swapped: 5 | swapped=False 6 | for i in range(1,len(arr)): 7 | if arr[i-1]>arr[i]: 8 | arr[i],arr[i-1] = arr[i-1],arr[i] 9 | swapped=True 10 | return arr 11 | 12 | a=[4,3,2,1] 13 | print a 14 | a=bubble_sort(a) 15 | print a -------------------------------------------------------------------------------- /fibonacci/main.py: -------------------------------------------------------------------------------- 1 | 2 | # prints out the first n fibonacci numbers 3 | def fibonacci(n): 4 | last_fibs=[1,1] 5 | for i in xrange(n): 6 | if i<2: 7 | print last_fibs[i] 8 | else: 9 | new_fib=sum(last_fibs) 10 | last_fibs[0],last_fibs[1]=last_fibs[1],new_fib 11 | print new_fib 12 | 13 | fibonacci(100) 14 | 15 | 16 | -------------------------------------------------------------------------------- /binary_search/Python3/main.py: -------------------------------------------------------------------------------- 1 | def binary_search(a,value): 2 | if len(a)==0 or (len(a)==1 and a[0]!=value): 3 | return False 4 | 5 | mid=a[len(a)//2] 6 | if value==mid: return True 7 | if valuemid: return binary_search(a[len(a)//2+1:],value) 9 | 10 | 11 | a=[1,2,3,4,5,6,7,8,9] 12 | print(binary_search(a,5)) -------------------------------------------------------------------------------- /fibonacci/recursive.py: -------------------------------------------------------------------------------- 1 | 2 | # recursive implementation of function, prints out the 3 | # first n fibonacci numbers 4 | def fibonacci(n,cur_fib=[1,1],i=0): 5 | if i==n: 6 | return 7 | if i<2: 8 | print cur_fib[i] 9 | return fibonacci(n,cur_fib,i+1) 10 | else: 11 | new_fib=sum(cur_fib) 12 | print new_fib 13 | return fibonacci(n,[cur_fib[1],new_fib],i+1) 14 | 15 | fibonacci(8) 16 | 17 | -------------------------------------------------------------------------------- /binary_search/Python2/main.py: -------------------------------------------------------------------------------- 1 | 2 | # performs binary search on input list 3 | def binary_search(a,value): 4 | if len(a)==0 or (len(a)==1 and a[0]!=value): 5 | return False 6 | 7 | mid=a[len(a)/2] 8 | if value==mid: return True 9 | if valuemid: return binary_search(a[len(a)/2+1:],value) 11 | 12 | a=[1,2,3,4,5,6,7,8,9] 13 | print binary_search(a,5) -------------------------------------------------------------------------------- /hanoi/main.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | from PyQt4.QtGui import * 4 | from PyQt4.QtCore import * 5 | 6 | class main_window(QWidget): 7 | def __init__(self): 8 | super(main_window,self).__init__() 9 | self.init_ui() 10 | 11 | def init_ui(self): 12 | self.show() 13 | 14 | def main(): 15 | pyqt_app=QApplication(sys.argv) 16 | _=main_window() 17 | sys.exit(pyqt_app.exec_()) 18 | 19 | if __name__ == '__main__': 20 | main() -------------------------------------------------------------------------------- /bogo_sort/main.py: -------------------------------------------------------------------------------- 1 | 2 | from random import randint,shuffle 3 | 4 | def create_array(size=10,max=50): 5 | return [randint(0,max) for _ in range(size)] 6 | 7 | 8 | def bogo_sort(a): 9 | def is_sorted(a): 10 | for i in xrange(1,len(a)): 11 | if a[i]0 and cur_item0: 14 | if self.data[i]self.data[min_child]: 22 | self.data[i],self.data[min_child]=self.data[min_child],self.data[i] 23 | i=min_child 24 | 25 | def _min_child(self,i): 26 | if i*2+1>self.size: return i*2 27 | else: 28 | if self.data[i*2]=self.length(): 42 | print "ERROR: 'Get' Index out of range!" 43 | return None 44 | cur_idx=0 45 | cur_node=self.head 46 | while True: 47 | cur_node=cur_node.next 48 | if cur_idx==index: return cur_node.data 49 | cur_idx+=1 50 | 51 | # Deletes the node at index 'index'. 52 | def erase(self,index): 53 | if index>=self.length(): 54 | print "ERROR: 'Erase' Index out of range!" 55 | return 56 | cur_idx=0 57 | cur_node=self.head 58 | while True: 59 | last_node=cur_node 60 | cur_node=cur_node.next 61 | if cur_idx==index: 62 | last_node.next=cur_node.next 63 | return 64 | cur_idx+=1 65 | 66 | # Allows for bracket operator syntax (i.e. a[0] to return first item). 67 | def __getitem__(self,index): 68 | return self.get(index) 69 | 70 | # ADDED THIS METHOD 71 | # Simplifies the code for selection sort, 72 | # swaps the values at input indices 'index_1' 73 | # and 'index_2', all other values unchanged 74 | def swap(self,index_1,index_2): 75 | val_1=self.get(index_1) # value at 'index_1' 76 | val_2=self.get(index_2) # value at 'index_2' 77 | 78 | # Iterate through list and replace values 79 | cur_idx=0 80 | cur_node=self.head 81 | while cur_idx=self.length() or index<0: 42 | print "ERROR: 'Get' Index out of range!" 43 | return None 44 | cur_idx=0 45 | cur_node=self.head 46 | while True: 47 | cur_node=cur_node.next 48 | if cur_idx==index: return cur_node.data 49 | cur_idx+=1 50 | 51 | # Deletes the node at index 'index'. 52 | def erase(self,index): 53 | if index>=self.length() or index<0: 54 | print "ERROR: 'Erase' Index out of range!" 55 | return 56 | cur_idx=0 57 | cur_node=self.head 58 | while True: 59 | last_node=cur_node 60 | cur_node=cur_node.next 61 | if cur_idx==index: 62 | last_node.next=cur_node.next 63 | return 64 | cur_idx+=1 65 | 66 | # Allows for bracket operator syntax (i.e. a[0] to return first item). 67 | def __getitem__(self,index): 68 | return self.get(index) 69 | 70 | # ADDED THIS METHOD 71 | # Simplifies the code for selection sort, 72 | # swaps the values at input indices 'index_1' 73 | # and 'index_2', all other values unchanged 74 | def swap(self,index_1,index_2): 75 | val_1=self.get(index_1) # value at 'index_1' 76 | val_2=self.get(index_2) # value at 'index_2' 77 | 78 | # Iterate through list and replace values 79 | cur_idx=0 80 | cur_node=self.head 81 | while cur_idx=self.length() or index<0: 42 | print "ERROR: 'Get' Index out of range!" 43 | return None 44 | cur_idx=0 45 | cur_node=self.head 46 | while True: 47 | cur_node=cur_node.next 48 | if cur_idx==index: return cur_node.data 49 | cur_idx+=1 50 | 51 | # Deletes the node at index 'index'. 52 | def erase(self,index): 53 | if index>=self.length() or index<0: 54 | print "ERROR: 'Erase' Index out of range!" 55 | return 56 | cur_idx=0 57 | cur_node=self.head 58 | while True: 59 | last_node=cur_node 60 | cur_node=cur_node.next 61 | if cur_idx==index: 62 | last_node.next=cur_node.next 63 | return 64 | cur_idx+=1 65 | 66 | # Allows for bracket operator syntax (i.e. a[0] to return first item). 67 | def __getitem__(self,index): 68 | return self.get(index) 69 | 70 | # ADDED THIS METHOD 71 | # Simplifies the code for selection sort, 72 | # swaps the values at input indices 'index_1' 73 | # and 'index_2', all other values unchanged 74 | def swap(self,index_1,index_2): 75 | val_1=self.get(index_1) # value at 'index_1' 76 | val_2=self.get(index_2) # value at 'index_2' 77 | 78 | # Iterate through list and replace values 79 | cur_idx=0 80 | cur_node=self.head 81 | while cur_idx0 then counter-clockwise 61 | # If <0 then clockwise 62 | # If =0 then collinear 63 | def det(p1,p2,p3): 64 | return (p2[0]-p1[0])*(p3[1]-p1[1]) \ 65 | -(p2[1]-p1[1])*(p3[0]-p1[0]) 66 | 67 | 68 | # Sorts in order of increasing polar angle from 'anchor' point. 69 | # 'anchor' variable is assumed to be global, set from within 'graham_scan'. 70 | # For any values with equal polar angles, a second sort is applied to 71 | # ensure increasing distance from the 'anchor' point. 72 | def quicksort(a): 73 | if len(a)<=1: return a 74 | smaller,equal,larger=[],[],[] 75 | piv_ang=polar_angle(a[randint(0,len(a)-1)]) # select random pivot 76 | for pt in a: 77 | pt_ang=polar_angle(pt) # calculate current point angle 78 | if pt_angcur_node.value and cur_node.right_child!=None: 44 | return self._find(value,cur_node.right_child) 45 | 46 | def print_tree(self): 47 | if self.root!=None: self._print_tree(self.root) 48 | 49 | def _print_tree(self,cur_node): 50 | if cur_node!=None: 51 | self._print_tree(cur_node.left_child) 52 | print "%d "%cur_node.value 53 | self._print_tree(cur_node.right_child) 54 | 55 | def depth(self): 56 | return self._depth(self.root,0) if self.root!=None else 0 57 | 58 | def _depth(self,cur_node,cur_depth): 59 | if cur_node==None: return cur_depth 60 | left_depth=self._depth(cur_node.left_child,cur_depth+1) 61 | right_depth=self._depth(cur_node.right_child,cur_depth+1) 62 | return max(left_depth,right_depth) 63 | 64 | def display(self): 65 | print "_"*15 66 | levels=[] 67 | cur_nodes=[self.root] 68 | while True: 69 | if len(cur_nodes)==0: break 70 | cur_values=[] 71 | next_nodes=[] 72 | for n in cur_nodes: 73 | if n.value!=None: cur_values.append(n.value) 74 | if n.left_child!=None: next_nodes.append(n.left_child) 75 | if n.right_child!=None: next_nodes.append(n.right_child) 76 | levels.append(cur_values) 77 | cur_nodes=next_nodes 78 | for i,level in enumerate(levels): 79 | sys.stdout.write("Level %d: "%i) 80 | for n in level: 81 | sys.stdout.write("%d "%n) 82 | sys.stdout.write("\n") 83 | print "_"*15 84 | 85 | # performs breath-first search for value parameter 86 | def bfs(self,value): 87 | cur_nodes=[self.root] 88 | while True: 89 | next_nodes=[] 90 | for c in cur_nodes: 91 | if c.value==value: return True 92 | if c.left_child!=None: next_nodes.append(c.left_child) 93 | if c.right_child!=None: next_nodes.append(c.right_child) 94 | cur_nodes=next_nodes 95 | if len(cur_nodes)==0: 96 | return False 97 | 98 | # performs pre-order depth-first search for value parameter 99 | def dfs(self,value,cur_node=-1): 100 | if cur_node==-1: cur_node=self.root 101 | if cur_node==None: return False 102 | if cur_node.value==value: return True 103 | in_left =self.dfs(value,cur_node.left_child) 104 | in_right =self.dfs(value,cur_node.right_child) 105 | if in_left or in_right: 106 | return True 107 | else: 108 | return False 109 | 110 | # deletes the specified input node 111 | def delete_node(self,node): 112 | 113 | # HELPER FUNCTION 114 | # returns the node with minimum value in a tree (could be a sub-tree) 115 | def min_value_node(n): 116 | current=n 117 | while current.left_child!=None: 118 | current=current.left_child 119 | return current 120 | 121 | # HELPER FUNCTION 122 | # returns the number of children for the specified node 123 | def num_children(n): 124 | num_children=0 125 | if n.left_child!=None: num_children+=1 126 | if n.right_child!=None: num_children+=1 127 | return num_children 128 | 129 | # get the parent of the node to be deleted 130 | node_parent=node.parent 131 | 132 | # get the number of children for the node 133 | node_children=num_children(node) 134 | 135 | # CASE 1 (node has no children) 136 | if node_children==0: 137 | 138 | # remove the reference to the node from the parent 139 | if node_parent.left_child==node: 140 | node_parent.left_child=None 141 | else: 142 | node_parent.right_child=None 143 | 144 | # CASE 2 (node has a single child) 145 | elif node_children==1: 146 | 147 | # get the child node 148 | child=node.left_child if node.left_child!=None else node.right_child 149 | 150 | # put the child node in place of the delete node 151 | if node_parent.left_child==node: node_parent.left_child=child 152 | else: node_parent.right_child=child 153 | 154 | # set the parent of the new child 155 | child.parent=node_parent 156 | 157 | # CASE 3 (node has two children) 158 | else: 159 | # get the inorder successor of the deleted node 160 | inorder_successor = min_value_node(node.right_child) 161 | # copy the inorder successor's content to deleted node 162 | node.value = inorder_successor.value 163 | # delete the inorder successor 164 | self.delete_node(inorder_successor) 165 | 166 | # deletes the node in the tree with the specified value 167 | def delete_value(self,value): 168 | return self.delete_node(self.find(value)) 169 | 170 | 171 | tree = binary_tree() 172 | tree.insert(3) 173 | tree.insert(4) 174 | tree.insert(0) 175 | tree.insert(-4) 176 | tree.insert(2) 177 | tree.insert(8) 178 | 179 | tree.display() 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /perceptron/main.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | import matplotlib,sys 3 | from matplotlib import pyplot as plt 4 | import numpy as np 5 | 6 | def predict(inputs,weights): 7 | activation=0.0 8 | for i,w in zip(inputs,weights): 9 | activation += i*w 10 | return 1.0 if activation>=0.0 else 0.0 11 | 12 | def plot(matrix,weights=None,title="Prediction Matrix"): 13 | 14 | if len(matrix[0])==3: # if 1D inputs, excluding bias and ys 15 | fig,ax = plt.subplots() 16 | ax.set_title(title) 17 | ax.set_xlabel("i1") 18 | ax.set_ylabel("Classifications") 19 | 20 | if weights!=None: 21 | y_min=-0.1 22 | y_max=1.1 23 | x_min=0.0 24 | x_max=1.1 25 | y_res=0.001 26 | x_res=0.001 27 | ys=np.arange(y_min,y_max,y_res) 28 | xs=np.arange(x_min,x_max,x_res) 29 | zs=[] 30 | for cur_y in np.arange(y_min,y_max,y_res): 31 | for cur_x in np.arange(x_min,x_max,x_res): 32 | zs.append(predict([1.0,cur_x],weights)) 33 | xs,ys=np.meshgrid(xs,ys) 34 | zs=np.array(zs) 35 | zs = zs.reshape(xs.shape) 36 | cp=plt.contourf(xs,ys,zs,levels=[-1,-0.0001,0,1],colors=('b','r'),alpha=0.1) 37 | 38 | c1_data=[[],[]] 39 | c0_data=[[],[]] 40 | 41 | for i in range(len(matrix)): 42 | cur_i1 = matrix[i][1] 43 | cur_y = matrix[i][-1] 44 | 45 | if cur_y==1: 46 | c1_data[0].append(cur_i1) 47 | c1_data[1].append(1.0) 48 | else: 49 | c0_data[0].append(cur_i1) 50 | c0_data[1].append(0.0) 51 | 52 | plt.xticks(np.arange(x_min,x_max,0.1)) 53 | plt.yticks(np.arange(y_min,y_max,0.1)) 54 | plt.xlim(0,1.05) 55 | plt.ylim(-0.05,1.05) 56 | 57 | c0s = plt.scatter(c0_data[0],c0_data[1],s=40.0,c='r',label='Class -1') 58 | c1s = plt.scatter(c1_data[0],c1_data[1],s=40.0,c='b',label='Class 1') 59 | 60 | plt.legend(fontsize=10,loc=1) 61 | plt.show() 62 | return 63 | 64 | if len(matrix[0])==4: # if 2D inputs, excluding bias and ys 65 | fig,ax = plt.subplots() 66 | ax.set_title(title) 67 | ax.set_xlabel("i1") 68 | ax.set_ylabel("i2") 69 | 70 | if weights!=None: 71 | map_min=0.0 72 | map_max=1.1 73 | y_res=0.001 74 | x_res=0.001 75 | ys=np.arange(map_min,map_max,y_res) 76 | xs=np.arange(map_min,map_max,x_res) 77 | zs=[] 78 | for cur_y in np.arange(map_min,map_max,y_res): 79 | for cur_x in np.arange(map_min,map_max,x_res): 80 | zs.append(predict([1.0,cur_x,cur_y],weights)) 81 | xs,ys=np.meshgrid(xs,ys) 82 | zs=np.array(zs) 83 | zs = zs.reshape(xs.shape) 84 | cp=plt.contourf(xs,ys,zs,levels=[-1,-0.0001,0,1],colors=('b','r'),alpha=0.1) 85 | 86 | c1_data=[[],[]] 87 | c0_data=[[],[]] 88 | for i in range(len(matrix)): 89 | cur_i1 = matrix[i][1] 90 | cur_i2 = matrix[i][2] 91 | cur_y = matrix[i][-1] 92 | if cur_y==1: 93 | c1_data[0].append(cur_i1) 94 | c1_data[1].append(cur_i2) 95 | else: 96 | c0_data[0].append(cur_i1) 97 | c0_data[1].append(cur_i2) 98 | 99 | plt.xticks(np.arange(0.0,1.1,0.1)) 100 | plt.yticks(np.arange(0.0,1.1,0.1)) 101 | plt.xlim(0,1.05) 102 | plt.ylim(0,1.05) 103 | 104 | c0s = plt.scatter(c0_data[0],c0_data[1],s=40.0,c='r',label='Class -1') 105 | c1s = plt.scatter(c1_data[0],c1_data[1],s=40.0,c='b',label='Class 1') 106 | 107 | plt.legend(fontsize=10,loc=1) 108 | plt.show() 109 | return 110 | 111 | print("Matrix dimensions not covered.") 112 | 113 | # each matrix row: up to last row = inputs, last row = y (classification) 114 | def accuracy(matrix,weights): 115 | num_correct = 0.0 116 | preds = [] 117 | for i in range(len(matrix)): 118 | pred = predict(matrix[i][:-1],weights) # get predicted classification 119 | preds.append(pred) 120 | if pred==matrix[i][-1]: num_correct+=1.0 121 | print("Predictions:",preds) 122 | return num_correct/float(len(matrix)) 123 | 124 | # each matrix row: up to last row = inputs, last row = y (classification) 125 | def train_weights(matrix,weights,nb_epoch=10,l_rate=1.00,do_plot=False,stop_early=True,verbose=True): 126 | for epoch in range(nb_epoch): 127 | cur_acc = accuracy(matrix,weights) 128 | print("\nEpoch %d \nWeights: "%epoch,weights) 129 | print("Accuracy: ",cur_acc) 130 | 131 | if cur_acc==1.0 and stop_early: break 132 | if do_plot: plot(matrix,weights,title="Epoch %d"%epoch) 133 | 134 | for i in range(len(matrix)): 135 | prediction = predict(matrix[i][:-1],weights) # get predicted classificaion 136 | error = matrix[i][-1]-prediction # get error from real classification 137 | if verbose: sys.stdout.write("Training on data at index %d...\n"%(i)) 138 | for j in range(len(weights)): # calculate new weight for each node 139 | if verbose: sys.stdout.write("\tWeight[%d]: %0.5f --> "%(j,weights[j])) 140 | weights[j] = weights[j]+(l_rate*error*matrix[i][j]) 141 | if verbose: sys.stdout.write("%0.5f\n"%(weights[j])) 142 | 143 | plot(matrix,weights,title="Final Epoch") 144 | return weights 145 | 146 | def main(): 147 | 148 | nb_epoch = 10 149 | l_rate = 1.0 150 | plot_each_epoch = False 151 | stop_early = True 152 | 153 | part_A = True 154 | 155 | if part_A: # 3 inputs (including single bias input), 3 weights 156 | 157 | # Bias i1 i2 y 158 | matrix = [ [1.00, 0.08, 0.72, 1.0], 159 | [1.00, 0.10, 1.00, 0.0], 160 | [1.00, 0.26, 0.58, 1.0], 161 | [1.00, 0.35, 0.95, 0.0], 162 | [1.00, 0.45, 0.15, 1.0], 163 | [1.00, 0.60, 0.30, 1.0], 164 | [1.00, 0.70, 0.65, 0.0], 165 | [1.00, 0.92, 0.45, 0.0]] 166 | weights= [ 0.20, 1.00, -1.00 ] # initial weights specified in problem 167 | 168 | else: # 2 inputs (including single bias input), 2 weights 169 | 170 | nb_epoch = 1000 171 | 172 | # Bias i1 y 173 | matrix = [ [1.00, 0.08, 1.0], 174 | [1.00, 0.10, 0.0], 175 | [1.00, 0.26, 1.0], 176 | [1.00, 0.35, 0.0], 177 | [1.00, 0.45, 1.0], 178 | [1.00, 0.60, 1.0], 179 | [1.00, 0.70, 0.0], 180 | [1.00, 0.92, 0.0]] 181 | weights= [ 0.20, 1.00 ] # initial weights specified in problem 182 | 183 | train_weights(matrix,weights=weights,nb_epoch=nb_epoch,l_rate=l_rate,do_plot=plot_each_epoch,stop_early=stop_early) 184 | 185 | 186 | if __name__ == '__main__': 187 | main() --------------------------------------------------------------------------------