Python Programming for Quantitative Economics

This website presents a set of lectures on python programming for quantitative economics, designed and written by Thomas J. Sargent and John Stachurski.


A python program for neural network trained with backpropagation with sigmoid function

import numpy as np
def nonlin(x,deriv=False):
return x*(1-x)
return 1/(1+np.exp(-x))
X = np.array([ [0,0,1],
[1,1,1] ])
y = np.array([[0,0,1,1]]).T
syn0 = 2*np.random.random((3,1)) - 1
for iter in range(10000):
l0 = X
l1 = nonlin(,syn0))
l1_error = y - l1
l1_delta = l1_error * nonlin(l1,True)
syn0 +=,l1_delta)
print ("Output After Training:")
print (l1)