예제 #1
0
def run(n_obs, loss, reg, amount):
    print 'Starting run of MNIST.py'

    mnist_train = sio.loadmat('./data/mnist/MNIST_train.mat')
    mnist_test = sio.loadmat('./data/mnist/MNIST_test.mat')

    X_train = mnist_train['X'][0][0][2].transpose()
    y_train = mnist_train['y']
    X_test = mnist_test['Xtest'].transpose()
    y_test = mnist_test['ytest']
    dim = X_train.shape[1]

    ## Dictionary
    if loss == "l1":
        dictmod = adadictl1.AdaDictL1(dim, DICT_ACC, reg, amount)
    elif loss == "nl":
        dictmod = adadictnolearning.AdaDictNL(dim, DICT_ACC, reg, amount)
    else:
        dictmod = adadictl2.AdaDictL2(dim, DICT_ACC, reg, amount)


    # Train model
    dictmod.batchtrain(X_train[range(n_obs)])

    # Find reconstructions
    al1_train, err = dictmod.batchreconstruction(X_train[range(n_obs)],
        'mnist_train')
    al1_test, err = dictmod.batchreconstruction(X_test,
        'mnist_test')
    print dictmod.getnatoms()
    ## Classification
    ogd = multiOGD(10, dictmod.getnatoms(), 0.001)
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.seteta(0.0005)
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.seteta(0.0001)
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.seteta(0.00001)
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.seteta(0.000001)
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])
    ogd.train(al1_train , y_train[range(n_obs)])

    ogd.predict(al1_test, y_test)
    imagenm = "mnist_%d" % n_obs
    #dictmod.dimagesave((28,28), imagenm)

    print 'Run of MNIST.py is complete!\n\n'
예제 #2
0
"""

X_train = mnist_train["X"][0][0][2].transpose()
X_test = mnist_test["Xtest"].transpose()

n_obs = 60000

X_train = X_train[range(n_obs)]
y_train = y_train[range(n_obs)]

print "Loading complete"

print "\t\t\t====== Dictionary ======"

# train model
dictmod = multiOGD(10, 784, 0.001)
dictmod.train(X_train, y_train)
dictmod.seteta(0.0005)
dictmod.train(X_train, y_train)
dictmod.seteta(0.0001)
dictmod.train(X_train, y_train)
dictmod.seteta(0.00001)
dictmod.train(X_train, y_train)
dictmod.train(X_train, y_train)
dictmod.seteta(0.000001)
dictmod.train(X_train, y_train)
dictmod.train(X_train, y_train)


# predict
dictmod.predict(X_train, y_train)
예제 #3
0
y_train = mnist_train['y']
X_test = mnist_test['Xtest'].transpose()
y_test = mnist_test['ytest']
dim = X_train.shape[1]

## Dictionary
lasso_d = dictionary.Dictionary(dim, DICT_ATOMS, DICT_FIT, DICT_REG, \
		DICT_INIT)

lasso_d.batchtrain(X_train

# Save dictionary atoms as images
#lasso_d.dimagesave((28, 28), 'mnist')

# Find reconstructions
alphas_train = lasso_d.batchreconstruction(X_train, \
		'mnist_train_s')
alphas_test = lasso_d.batchreconstruction(X_test, \
		'mnist_test_s')

## Classification
ogd_m = multiOGD(10, DICT_ATOMS, MOD_REG)
ogd_m.train(alphas_train, y_train)
ogd_m.predict(alphas_test, y_test)

print 'Run of MNIST.py is complete!'
'''
Atoms: 200
Reg: 0.05  too much
'''