In [11]:
import PyTorch
from PyTorch import np

def nonlin(x,deriv=False):
	if(deriv==True):
	    return x*(1-x)

	return 1/(1+np.exp(-x))
    
X = np.array([[0,0,1],
            [0,1,1],
            [1,0,1],
            [1,1,1]]).astype('float32')
                
y = np.array([[0],
			[1],
			[1],
			[0]]).astype('float32')

np.random.seed(1)

# randomly initialize our weights with mean 0
syn0 = 2*np.random.random((3,4)) - 1
syn1 = 2*np.random.random((4,1)) - 1

for j in range(60000):

	# Feed forward through layers 0, 1, and 2
    l0 = X
    l1 = nonlin(np.dot(l0,syn0)).astype('float32')
    l2 = nonlin(np.dot(l1,syn1)).astype('float32')
    
    
    loss = crit.forward(l2, y)
    
    # how much did we miss the target value?
    gradOutput = crit.backward(l2, y)
        
    # in what direction is the target value?
    # were we really sure? if so, don't change too much.
    l2_delta = np.array(gradOutput)*nonlin(l2,deriv=True)

    # how much did each l1 value contribute to the l2 error (according to the weights)?
    l1_error = l2_delta.dot(syn1.T)
    
    # in what direction is the target l1?
    # were we really sure? if so, don't change too much.
    l1_delta = l1_error * nonlin(l1,deriv=True)
    syn1_update = l1.T.dot(np.array(l2_delta))
    syn1 += syn1_update
    syn0 += l0.T.dot(l1_delta)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-11-dee2b2eb55c1> in <module>()
     32 
     33 
---> 34     loss = crit.forward(l2, y)
     35 
     36     # how much did we miss the target value?

NameError: name 'crit' is not defined

In [44]:



Out[44]:
array([[0.0590527
-0.063704
-0.0568625
0.0679006
[torch.FloatTensor of size 4x1]
],
       [0.0591873
-0.0638492
-0.0569921
0.0680553
[torch.FloatTensor of size 4x1]
],
       [0.0587609
-0.0633893
-0.0565815
0.0675651
[torch.FloatTensor of size 4x1]
],
       [0.0587427
-0.0633696
-0.056564
0.0675442
[torch.FloatTensor of size 4x1]
]], dtype=object)

In [12]:
import PyTorch
from PyTorchAug import nn
from PyTorch import np

# randomly initialize our weights with mean 0
net = nn.Sequential()
net.add(nn.Linear(3, 4))
net.add(nn.Sigmoid())
net.add(dropout(0,1,2))
net.add(nn.Linear(4, 1))
net.add(nn.Sigmoid())
net.float()

X = np.array([[0,0,1],
            [0,1,1],
            [1,0,1],
            [1,1,1]]).astype('float32')
                
y = np.array([[0],
			[1],
			[1],
			[0]]).astype('float32')

crit = nn.MSECriterion()
crit.float()

for j in range(2400):
    
    net.zeroGradParameters()

    # Feed forward through layers 0, 1, and 2
    output = net.forward(X)
    
    # how much did we miss the target value?
    loss = crit.forward(output, y)
    gradOutput = crit.backward(output, y)
    
    # how much did each l1 value contribute to the l2 error (according to the weights)?
    # in what direction is the target l1?
    # were we really sure? if so, don't change too much.
    gradInput = net.backward(X, gradOutput)
    
    # lets update our weights
    net.updateParameters(1)
    
    if (j% 200) == 0:
        print("Error:" + str(loss))


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-12-309c79481e0f> in <module>()
      7 net.add(nn.Linear(3, 4))
      8 net.add(nn.Sigmoid())
----> 9 net.add(dropout(0,1,2))
     10 net.add(nn.Linear(4, 1))
     11 net.add(nn.Sigmoid())

/Users/amberedmundson/.local/lib/python3.5/site-packages/PyTorch-4.1.1_SNAPSHOT-py3.5-macosx-10.6-x86_64.egg/PyTorchAug.py in mymethod(*args)
    163             lua.insert(-2)
    164             for arg in args:
--> 165                 pushSomething(lua, arg)
    166             res = lua.pcall(len(args) + 1, 1, 1)   # +1 for self
    167             if res != 0:

/Users/amberedmundson/.local/lib/python3.5/site-packages/PyTorch-4.1.1_SNAPSHOT-py3.5-macosx-10.6-x86_64.egg/PyTorchAug.py in pushSomething(lua, something)
    124         raise Exception('pushing numpy array with elements of type ' + dtypestr + ' it not currently implemented')
    125 
--> 126     raise Exception('pushing type ' + str(type(something)) + ' not implemented, value ', something)
    127 
    128 

Exception: ("pushing type <class 'PyTorchLua.Nothing'> not implemented, value ", Nothing)

In [1]:
import PyTorchHelpers

In [ ]:
dropout = PyTorchHelpers.load_lua_class('Dropout.lua', 'Nothing')

In [16]:
d = dropout(0,1,2)

In [17]:
d.updateOutput(0)


Out[17]:
0.0

In [ ]: