Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. import numpy
  2. import random
  3. import math
  4.  
  5. def func1(x,y):
  6.    result = math.cos(y/100)/(1+(x/100)**2)
  7.    return result;
  8.  
  9.  
  10. def func2(x,y):
  11.     result = (x**2+y**2)*(math.sin(x/50)+math.cos(y/50))
  12.     return result;
  13.  
  14. def propagacao():
  15.     for j in range(30):
  16.         Vj = Matriz1[j][0]*MatrizPEntrada[j][0] + Matriz1[j][0]*MatrizPEntrada[j][0] - teta
  17.         yc = math.tanh(Vj)
  18.         Prop[j] = yc
  19.         erro[j] = Matriz1[j][2] - Prop[j]
  20.         print("erro: ",erro)
  21.  
  22.  
  23. def retro():
  24.     for j in range(30):
  25.         grad = erro[j]*Prop[j]*(1-Prop[j])
  26.  
  27.  
  28.  
  29.        
  30. Matriz1 = numpy.zeros((100, 3))
  31. Matriz2 = numpy.zeros((100, 3))
  32.  
  33. for x in range(100):
  34.     for y in range(3):
  35.         Matriz1[x][0] = random.randrange(-10000,10000,1)/10
  36.         Matriz1[x][1] = random.randrange(-10000,10000,1)/10
  37.         Matriz1[x][2] = func1(Matriz1[x][0],Matriz1[x][1])
  38.  
  39. print("m1x: ",Matriz1[0][0])
  40. print("m1y: ",Matriz1[0][1])
  41. print("m1z: ",Matriz1[0][2])
  42.  
  43. for x in range(100):
  44.     for y in range(3):
  45.         Matriz2[x][0] = random.randrange(-10000,10000,1)/10
  46.         Matriz2[x][1] = random.randrange(-10000,10000,1)/10
  47.         Matriz2[x][2] = func2(Matriz2[x][0],Matriz2[x][1])
  48.  
  49.  
  50. MatrizPEntrada = numpy.zeros((100,30))
  51. MatrizPSaida = numpy.zeros((30,1))
  52. Prop = numpy.zeros((30,1))
  53. Prop2 = numpy.zeros((30,1))
  54. erro = numpy.zeros((30,1))
  55. for x in range(30):
  56.     for y in range(2):
  57.         MatrizPEntrada[x][y] = random.randrange(-10,10)/10
  58.  
  59. print("mpe1: ",MatrizPEntrada[0][0])
  60. print("mpe2: ",MatrizPEntrada[0][1])
  61.  
  62. for x in range(30):
  63.     for y in range(1):
  64.         MatrizPSaida[x][y] = random.randrange(-10,10)/10
  65.  
  66. teta = 1
  67. propagacao()
  68. retro()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement