Advertisement
Guest User

neural_nets.py.py

a guest
Mar 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. #
  2. #Imports
  3. #
  4. import numpy as np
  5.  
  6. class BackPropagationNetwork:
  7.     """A back-propagation-network"""
  8.    
  9.     #
  10.     # Class members
  11.     #
  12.     layerCount = 0
  13.     shape =None
  14.     weights = []
  15.    
  16.     #
  17.     #class methods
  18.     #
  19.     def __init__(self, layerSize):
  20.         """initialize the network"""
  21.         # Layer info
  22.         self.layerCount = len(layerSize)-1
  23.         self.shape = layerSize
  24.        
  25.         # Input/Output data from last run
  26.         self.layerInput = []
  27.         self._layerOutput =[]
  28.        
  29.         # create the weight arrays
  30.         for (l1, l2) in zip(layerSize[:-1], layerSize[1:]):
  31.             self.weights.append(np.random.normal(scale =0.1, size =(l2, l1+1)))
  32.            
  33. #
  34. # If run as script, create a test object
  35. #
  36. if __name__ == "__main__":
  37.     bpn = BackPropagationNetwork((2,2,1))
  38.     print(bpn.shape)
  39.     print(bpn.weights)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement