Skip to content

Commit

Permalink
add untested manifold function
Browse files Browse the repository at this point in the history
  • Loading branch information
y0ast committed May 1, 2014
1 parent eb27dc0 commit d05ae79
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
15 changes: 15 additions & 0 deletions binaryva.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ require 'LinearVA'
--For loading data files
require 'load'

--For saving weights and biases
require 'hdf5'

require 'adagrad'

data = load28('datasets/mnist.hdf5')
Expand Down Expand Up @@ -74,6 +77,7 @@ opfunc = function(batch)
de_dw = KLD:backward(va:get(1).output, batch)
encoder:backward(batch,de_dw)


lowerbound = err + KLDerr
weights, grads = va:parameters()

Expand Down Expand Up @@ -107,4 +111,15 @@ while true do
end

print("\nEpoch: " .. epoch .. " Lowerbound: " .. lowerbound/data.train:size(1) .. " time: " .. sys.clock() - time)
if epoch % 2 == 0 then
local myFile = hdf5.open('params/epoch_' .. epoch .. '.hdf5', 'w')

myFile:write('weighttanh', va:get(3).weight)
myFile:write('biastanh', va:get(3).bias)
myFile:write('weightsigmoid', va:get(5).weight)
myFile:write('biassigmoid', va:get(5).bias)

myFile:close()
end

end
40 changes: 31 additions & 9 deletions plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,38 @@
"""
Code for creating manifold later!
z = np.matrix([sp.norm.ppf(gridValues[i]),sp.norm.ppf(gridValues[j])]).T
if continuous:
h_decoder = np.log(1 + np.exp(np.dot(W4,z) + b4))
y = 1 / (1 + np.exp(-(W5.dot(h_decoder) + b5)))
else:
h_encoder = np.tanh(W4.dot(z) + b4)
y = 1 / (1 + np.exp(-(W5.dot(h_encoder) + b5)))
"""

def manifold(gridSize, epoch):
f = h5py.File('params/epoch_' + epoch + '.hdf5','r')

wtanh = np.array(f["wtanh"])
btanh = np.array(f["btanh"])
wsig = np.array(f["wsig"])
bsig = np.array(f["bsig"])

wb = (wtanh,btanh,wsig,bsig)
gridValues = np.linspace(0.05,0.95,gridSize)

z = lambda i,j: np.matrix([sp.norm.ppf(gridValues[i]),sp.norm.ppf(gridValues[j])]).T

if continuous:
h_decoder = np.log(1 + np.exp(np.dot(W4,z) + b4))
y = 1 / (1 + np.exp(-(W5.dot(h_decoder) + b5)))

image = np.vstack([np.hstack([activation_binary(z(i+j),wb).reshape(shape) for j in xrange(numcols)]) for i in columns])

plt.imshow(image, interpolation='nearest', cmap='Greys')
plt.axis('off')
plt.show()

def activation_binary(z, wb):
wtanh, btanh, wsig, bsig = wb
h = np.tanh(wtanh.dot(z) + btanh)
y = 1 / (1 + np.exp(-(wsig.dot(h) + bsig)))

return y

def plotdigits(numcols):
f = h5py.File('datasets/mnist.hdf5','r')
data = np.array(f["x_train"])
Expand All @@ -31,5 +54,4 @@ def plotdigits(numcols):
plt.axis('off')
plt.show()

plotdigits(5)

manifold(10,5)

0 comments on commit d05ae79

Please sign in to comment.