These are chat archives for dmlc/mxnet

16th
Oct 2017
Andre Bieler
@abieler
Oct 16 2017 11:58
FYI @haehn i saw last week that mxnet now supports h5py data sets with NDArrayIter https://mxnet.incubator.apache.org/api/python/io.html#mxnet.io.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 productmx.sym.dot(X, 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 = mx.io.NDArrayIter(data={'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 = mx.sym.dot(X, w)

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

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


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

np.mean(pred - labels)