In [47]:
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)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-47-dee2b2eb55c1> in <module>()
     47     # were we really sure? if so, don't change too much.
     48     l1_delta = l1_error * nonlin(l1,deriv=True)
---> 49     syn1_update = l1.T.dot(np.array(l2_delta))
     50     syn1 += syn1_update
     51     syn0 += l0.T.dot(l1_delta)

TypeError: Argument 'self' has incorrect type (expected PyTorch._FloatTensor, got float)

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 [5]:
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())
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-5-c210bbd06571> in <module>()
      7 net.add(nn.Linear(3, 4))
      8 net.add(nn.Sigmoid())
----> 9 net.add(dropout())
     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/PyTorchHelpers.py in __init__(self, *args)
     18             self.luaclass = lua_classname
     19             if not _fromLua:
---> 20                 PyTorchAug.LuaClass.__init__(self, splitName, *args)
     21             else:
     22                 self.__dict__['__objectId'] = PyTorchAug.getNextObjectId()

/Users/amberedmundson/.local/lib/python3.5/site-packages/PyTorch-4.1.1_SNAPSHOT-py3.5-macosx-10.6-x86_64.egg/PyTorchAug.py in __init__(self, nameList, *args)
    253         if res != 0:
    254             errorMessage = popString(lua)
--> 255             raise Exception(errorMessage)
    256 #        lua.call(len(args), 1)
    257         registerObject(lua, self)

Exception: ./Dropout.lua:24: attempt to index field 'output' (a nil value)

In [1]:
import PyTorchHelpers

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

In [3]:
dropout(0,1,2)


Out[3]:
TorchModel

In [ ]: