P = df[1] Y = df[2] ### # Create and train NN # create recurrent neural network with 1 input, 2 hidden layers with # 2 neurons each and 1 output # the NN has a recurrent connection with delay of 1 timestep in the hidden # layers and a recurrent connection with delay of 1 and 2 timesteps from the output # to the first layer net = prn.CreateNN([1, 2, 2, 1], dIn=[0], dIntern=[1], dOut=[1, 2]) ### # Prepare input Data for gradient calculation data, net = prn.prepare_data(P, Y, net) ### # Calculate derivative vector (gradient vector) # Real Time Recurrent Learning t0_rtrl = time.time() J, E, e = prn.RTRL(net, data) g_rtrl = 2 * np.dot(J.transpose(), e) # calculate g from Jacobian and error vector t1_rtrl = time.time() # Back Propagation Through Time t0_bptt = time.time() g_bptt, E = prn.BPTT(net, data) t1_bptt = time.time()
P = df['P'].values Y = df['Y'].values ### #Create and train NN #create recurrent neural network with 1 input, 2 hidden layers with #2 neurons each and 1 output #the NN has a recurrent connection with delay of 1 timestep in the hidden # layers and a recurrent connection with delay of 1 and 2 timesteps from the output # to the first layer net = prn.CreateNN([1,2,2,1],dIn=[0],dIntern=[1],dOut=[1,2]) ### #Prepare input Data for gradient calculation data,net = prn.prepare_data(P,Y,net) ### #Calculate derivative vector (gradient vector) #Real Time Recurrent Learning t0_rtrl = time.time() J,E,e = prn.RTRL(net,data) g_rtrl = 2 * np.dot(J.transpose(),e) #calculate g from Jacobian and error vector t1_rtrl = time.time() #Back Propagation Through Time t0_bptt = time.time() g_bptt,E = prn.BPTT(net,data) t1_bptt = time.time()