Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy
- import random
- import math
- def func1(x,y):
- result = math.cos(y/100)/(1+(x/100)**2)
- return result;
- def func2(x,y):
- result = (x**2+y**2)*(math.sin(x/50)+math.cos(y/50))
- return result;
- def propagacao():
- for j in range(30):
- Vj = Matriz1[j][0]*MatrizPEntrada[j][0] + Matriz1[j][0]*MatrizPEntrada[j][0] - teta
- yc = math.tanh(Vj)
- Prop[j] = yc
- erro[j] = Matriz1[j][2] - Prop[j]
- print("erro: ",erro)
- def retro():
- for j in range(30):
- grad = erro[j]*Prop[j]*(1-Prop[j])
- Matriz1 = numpy.zeros((100, 3))
- Matriz2 = numpy.zeros((100, 3))
- for x in range(100):
- for y in range(3):
- Matriz1[x][0] = random.randrange(-10000,10000,1)/10
- Matriz1[x][1] = random.randrange(-10000,10000,1)/10
- Matriz1[x][2] = func1(Matriz1[x][0],Matriz1[x][1])
- print("m1x: ",Matriz1[0][0])
- print("m1y: ",Matriz1[0][1])
- print("m1z: ",Matriz1[0][2])
- for x in range(100):
- for y in range(3):
- Matriz2[x][0] = random.randrange(-10000,10000,1)/10
- Matriz2[x][1] = random.randrange(-10000,10000,1)/10
- Matriz2[x][2] = func2(Matriz2[x][0],Matriz2[x][1])
- MatrizPEntrada = numpy.zeros((100,30))
- MatrizPSaida = numpy.zeros((30,1))
- Prop = numpy.zeros((30,1))
- Prop2 = numpy.zeros((30,1))
- erro = numpy.zeros((30,1))
- for x in range(30):
- for y in range(2):
- MatrizPEntrada[x][y] = random.randrange(-10,10)/10
- print("mpe1: ",MatrizPEntrada[0][0])
- print("mpe2: ",MatrizPEntrada[0][1])
- for x in range(30):
- for y in range(1):
- MatrizPSaida[x][y] = random.randrange(-10,10)/10
- teta = 1
- propagacao()
- retro()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement