def objective(args): n_epochs = 10 rho = 0.01 lamb = 5 noise_std = 0.2 hidshape = (50, 50) rflen, rate, clip = args rfshape = (rflen, rflen) clip = (-clip, clip) layer = SparseAutoencoder( visshape=imshape, hidshape=hidshape, rfshape=rfshape, f=noisylif, g=linear) train_params = {'rho': rho, 'lamb': lamb, 'noise_std': noise_std} trainer = SparseTrainer(layer, **train_params) stats = sgd(trainer, patches, n_epochs=n_epochs, rate=rate, clip=clip, show=False) cost = stats['cost'][-1] filename = 'results/layer_opt_vh_cost=%0.3e.npz' % cost layer.to_file(filename) return cost
layer = SparseAutoencoder(visshape=imshape, hidshape=(50,50), rfshape=(11,11), f=noisylif, g=linear) # train_params = {'rho': 0.01, 'lamb': 25, 'noise_std': 0.2} # train_params = {'rho': 0.01, 'lamb': 5, 'noise_std': 0.2} train_params = {'rho': 0.05, 'lamb': 5, 'noise_std': 0.2} trainer = SparseTrainer(layer, **train_params) plt.figure(101) raw_input("Please place the figure...") sgd(trainer, patches, n_epochs=30, rate=0.05, vlims=(-2,2)) if 'filename' in locals(): layer.to_file(filename) else: layer = deepnet.CacheObject.from_file(filename) print "loaded layer from file: %s" % filename ### untied training if 1: if layer.tied: layer.untie() train_params = {'rho': 0.05, 'lamb': 5, 'noise_std': 0} trainer = SparseTrainer(layer, **train_params) lbfgs(trainer, patches, n_evals=30, vlims=(-2,2))