These are chat archives for dmlc/mxnet

Oct 2017
Andre Bieler
Oct 16 2017 11:58
FYI @haehn i saw last week that mxnet now supports h5py data sets with NDArrayIter

On a different topic:

I tried to put together a linear regression toy example, which is easy enough. However, I would like to replace mx.sym.FullyConnected() by the dot, w) for educational purposes. Not sure how to achieve that the optimizer recognizes to optimize w in this case. Full example below:

m = 1000
batch_size = 100
nVars = 4
data = np.random.normal(0,1, (m, nVars))
labels = -10 * data[:,0] + data[:,1]*np.pi + 5 * np.sqrt(abs(data[:,2])) - data[:,3] + np.random.normal(0,1, m)*2

train_iter ={'data':data}, label={'labels':labels}, batch_size=batch_size)

X = mx.sym.Variable('data', shape=(batch_size, nVars))
y = mx.sym.Variable('labels', shape=(batch_size))
w = mx.sym.var(name='theta', shape=(nVars), init=mx.initializer.Normal())

fc = mx.sym.FullyConnected(data=X, name='fc1', num_hidden=1)
fc_dot =, w)

yhat = mx.sym.LinearRegressionOutput(fc, label=y, name='yhat')
yhat_dot = mx.sym.LinearRegressionOutput(fc_dot, label=y, name='yhat')

model = mx.mod.Module(symbol=yhat, data_names=['data'], label_names=['labels']), num_epoch=10)
pred = model.predict(train_iter).asnumpy().flatten()

model_dot = mx.mod.Module(symbol=yhat_dot, data_names=['data'], label_names=['labels']), num_epoch=10)
pred_dot = model_dot.predict(train_iter).asnumpy().flatten()

np.mean(pred - labels)