def initialize_everything(self): ### initialize matrices for cuda ### self.r_ =np.zeros(self.cfg.chains).astype('float32').copy('F') self.w = cp.dev_tensor_float_cm(self.w_.copy("F")) ### generate basemodel softened = (self.data.mean(axis=1) + 0.1) self.baserate_bias_= (np.log(softened) - np.log(1-softened)).astype('float32').copy('F') self.baserate_bias_.shape=(self.w.shape[0],1) ## start chains self.v_ = np.tile(sigm(self.baserate_bias_),(1,self.cfg.chains)) self.v_ = sample(self.v_,self.cfg['utype']).astype('float32').copy('F') self.v = cp.dev_tensor_float_cm(self.v_.copy("F")) self.h = cp.dev_tensor_float_cm([self.num_hids,self.cfg.chains]) self.baserate_bias = cp.dev_tensor_float_cm(self.baserate_bias_.copy("F")) self.r = cp.dev_tensor_float_cm(np.vstack(self.r_).copy("F")) cp.initialize_mersenne_twister_seeds(int(time.time()*1000) % 100000)
def initialize(cfg): cp.initCUDA(cfg.device) cp.initialize_mersenne_twister_seeds(cfg.seed)
import cuv_python as cp if __name__ == "__main__": try: if sys.argv[2] == "--host": switchtohost() except: pass try: mnist = MNIST_data(sys.argv[1]) except: print('Usage: %s {path of MNIST dataset} [--host]' % sys.argv[0]) sys.exit(1) cp.initialize_mersenne_twister_seeds(0) # obtain training/test data train_data, train_labels = mnist.get_train_data() test_data, test_labels = mnist.get_test_data() # set layer sizes sizes = [train_data.shape[0], 128, train_labels.shape[0]] print('Initializing MLP...') mlp = MLP(sizes, 100) print('Training MLP...') try: mlp.fit(train_data, train_labels, 200) except KeyboardInterrupt:
import numpy as np import cuv_python as cp if __name__ == "__main__": try: if sys.argv[2] == "--host": switchtohost() except: pass try: mnist = MNIST_data(sys.argv[1]); except: print('Usage: %s {path of MNIST dataset} [--host]' % sys.argv[0]) sys.exit(1) cp.initialize_mersenne_twister_seeds(0) # obtain training/test data train_data, train_labels = mnist.get_train_data() test_data, test_labels = mnist.get_test_data() # set layer sizes sizes = [train_data.shape[0], 128, train_labels.shape[0]] print('Initializing MLP...') mlp = MLP(sizes, 100) print('Training MLP...') try: mlp.fit(train_data, train_labels, 200) except KeyboardInterrupt: