Skip to content

Commit d542a89

Browse files
author
Michael Lou
committed
format
1 parent acc42ff commit d542a89

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

display_network.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from math import sqrt, ceil, floor
2+
3+
import numpy as np
24
import matplotlib.pyplot as plt
35
import matplotlib.cm as cm
4-
import numpy as np
56

67

78
def display_network(data, cols=-1, opt_normalize=True, opt_graycolor=True):

sample_images.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
__author__ = 'ylou'
1+
from random import randint
22

3-
import scipy.io
3+
from scipy.io import loadmat
44
import numpy as np
5-
from random import randint
65
#from matplotlib import pyplot as plt
76

87

@@ -31,7 +30,7 @@ def sample_images():
3130
:return: 10000 patches for training
3231
"""
3332
## Get IMAGES.mat from http://ufldl.stanford.edu/wiki/resources/sparseae_exercise.zip
34-
images = scipy.io.loadmat('IMAGES.mat')['IMAGES'] # load images from disk
33+
images = loadmat('IMAGES.mat')['IMAGES'] # load images from disk
3534
num_images = images.shape[2]
3635

3736
patch_size = 8 # we'll use 8x8 patches
@@ -58,4 +57,4 @@ def sample_images():
5857
# the range of pixel values is also bounded between [0,1]
5958
patches = normalize_data(patches)
6059

61-
return patches
60+
return patches

sparse_autoencoder_cost.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import numpy as np
32

43

@@ -65,4 +64,4 @@ def sparse_autoencoder_cost(theta, visible_size, hidden_size, decay_lambda, spar
6564

6665
grad = np.concatenate((w1grad.flatten(), w2grad.flatten(), b1grad.flatten(), b2grad.flatten()))
6766

68-
return cost, grad
67+
return cost, grad

train.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
__author__ = 'ylou'
1+
from random import randint
2+
from math import sqrt
3+
4+
import numpy as np
25

36
from sample_images import sample_images
47
from display_network import display_network
58
from sparse_autoencoder_cost import sparse_autoencoder_cost
6-
from math import sqrt
7-
import random
8-
import numpy as np
99

1010

1111
def initialize_parameters(hidden_size, visible_size):
@@ -43,7 +43,7 @@ def train():
4343
# display a random sample of 200 patches from the dataset
4444

4545
patches = sample_images()
46-
list = [random.randint(0, patches.shape[0]-1) for i in xrange(64)]
46+
list = [randint(0, patches.shape[0]-1) for i in xrange(64)]
4747
display_network(patches[list, :], 8)
4848

4949
# Obtain random parameters theta
@@ -81,4 +81,4 @@ def train():
8181

8282

8383
if __name__ == "__main__":
84-
train()
84+
train()

0 commit comments

Comments
 (0)