# normal/centered RBM --> 0.0/0.01 update_offsets = 0.01 # Flipped/Normal MNIST --> True/False flipped = False # Set random seed (optional) numx.random.seed(42) # Input and hidden dimensionality v1 = v2 = 28 h1 = h2 = 4 # Load data (download is not existing) train_data, _, valid_data, _, test_data, _ = io.load_mnist( "mnist.pkl.gz", True) train_data = numx.vstack((train_data, valid_data)) # Flip the dataset if chosen if flipped: train_data = 1 - train_data test_data = 1 - test_data print("Flipped MNIST") else: print("Normal MNIST") # Training parameters batch_size = 100 epochs = 50 # Create centered or normal model
import numpy as numx import pydeep.fnn.model as MODEL import pydeep.fnn.layer as LAYER import pydeep.fnn.trainer as TRAINER import pydeep.base.activationfunction as ACT import pydeep.base.costfunction as COST import pydeep.base.corruptor as CORR import pydeep.misc.io as IO import pydeep.base.numpyextension as npExt # Set random seed (optional) numx.random.seed(42) # Load data and whiten it train_data, train_label, valid_data, valid_label, test_data, test_label = IO.load_mnist( "mnist.pkl.gz", False) train_data = numx.vstack((train_data, valid_data)) train_label = numx.hstack((train_label, valid_label)).T train_label = npExt.get_binary_label(train_label) test_label = npExt.get_binary_label(test_label) # Create model l1 = LAYER.FullConnLayer(input_dim=train_data.shape[1], output_dim=1000, activation_function=ACT.ExponentialLinear(), initial_weights='AUTO', initial_bias=0.0, initial_offset=numx.mean(train_data, axis=0).reshape( 1, train_data.shape[1]), connections=None, dtype=numx.float64)
import pydeep.misc.visualization as VIS import pydeep.misc.io as IO import pydeep.base.numpyextension as numxExt from pydeep.dbm.unit_layer import * from pydeep.dbm.weight_layer import * from pydeep.dbm.model import * # Set the same seed value for all algorithms numx.random.seed(42) # Load Data train_data = IO.load_mnist("mnist.pkl.gz", True)[0] # Set dimensions Layer 1-3 v11 = v12 = 28 v21 = v22 = 10 v31 = v32 = 10 N = v11 * v12 M = v21 * v22 O = v31 * v32 # Create weight layers, which connect the unit layers wl1 = Weight_layer(input_dim=N, output_dim=M, initial_weights=0.01, dtype=numx.float64) wl2 = Weight_layer(input_dim=M, output_dim=O, initial_weights=0.01, dtype=numx.float64)
# Import cost functions, activation function, Autencoder and trainer module import pydeep.base.activationfunction as act import pydeep.base.costfunction as cost import pydeep.ae.model as aeModel import pydeep.ae.trainer as aeTrainer # Set random seed (optional) numx.random.seed(42) # Input and hidden dimensionality v1 = v2 = 28 h1 = 10 h2 = 10 # Load data , get it from 'deeplearning.net/data/mnist/mnist.pkl.gz' train_data, _, _, _, test_data, _ = io.load_mnist("../../data/mnist.pkl.gz", False) # Set hyperparameters batchsize and number of epochs batch_size = 10 max_epochs = 10 # Create model with sigmoid hidden units, linear output units, and squared error loss. ae = aeModel.AutoEncoder(v1 * v2, h1 * h2, data=train_data, visible_activation_function=act.Sigmoid(), hidden_activation_function=act.Sigmoid(), cost_function=cost.CrossEntropyError(), initial_weights='AUTO', initial_visible_bias='AUTO', initial_hidden_bias='AUTO',