Skip to content

Commit ff4bd33

Browse files
committed
switching to T.sum when computing negative log likelihood (though T.mean should also be supported) for mlp and logistic_sgd. Second bug fixed was when initializing the weights, we need 6./(n_in+n_out) instead of 6/(n_in_n_out) [ this does division by ints].
1 parent a8926d3 commit ff4bd33

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

code/logistic_sgd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def negative_log_likelihood(self, y):
106106
:param y: corresponds to a vector that gives for each example the
107107
:correct label
108108
"""
109-
return -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]),y])
109+
return -T.sum(T.log(self.p_y_given_x)[T.arange(y.shape[0]),y])
110110

111111

112112

code/mlp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ def __init__(self, input, n_in, n_hidden, n_out):
7575
# the output of uniform if converted using asarray to dtype
7676
# theano.config.floatX so that the code is runable on GPU
7777
W1_values = numpy.asarray( numpy.random.uniform( \
78-
low = -numpy.sqrt(6/(n_in+n_hidden)), high = numpy.sqrt(6/(n_in+n_hidden)), \
78+
low = -numpy.sqrt(6./(n_in+n_hidden)), high = numpy.sqrt(6./(n_in+n_hidden)), \
7979
size = (n_in, n_hidden)), dtype = theano.config.floatX)
8080
# `W2` is initialized with `W2_values` which is uniformely sampled
8181
# from -1/sqrt(n_hidden) and 1/sqrt(n_hidden)
8282
# the output of uniform if converted using asarray to dtype
8383
# theano.config.floatX so that the code is runable on GPU
8484
W2_values = numpy.asarray( numpy.random.uniform(
85-
low = numpy.sqrt(6/(n_hidden+n_out)), high= numpy.sqrt(6/(n_hidden+n_out)),\
85+
low = numpy.sqrt(6./(n_hidden+n_out)), high= numpy.sqrt(6./(n_hidden+n_out)),\
8686
size= (n_hidden, n_out)), dtype = theano.config.floatX)
8787

8888
self.W1 = theano.shared( value = W1_values )
@@ -126,7 +126,7 @@ def negative_log_likelihood(self, y):
126126
:param y: corresponds to a vector that gives for each example the
127127
:correct label
128128
"""
129-
return -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]),y])
129+
return -T.sum(T.log(self.p_y_given_x)[T.arange(y.shape[0]),y])
130130

131131

132132

0 commit comments

Comments
 (0)