def train(data, mask): print('---------------------------------------------') print('Starting training') v_input = tf.placeholder('float', [None, param_rbm['num_v_nodes']]) v_mask = tf.placeholder('float', [None, param_rbm['num_v_nodes']]) epoch = tf.placeholder('float', [1]) loss_op = rbm(v_input, v_mask, epoch) init = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init) errsum = 0.0 for step in range(param_rbm['num_epochs']): for batch in range(1, 2016): start = (step * param_rbm['batch_size']) % 2015 end = min(start + param_rbm['batch_size'], 2015) x = data[start:end] m = mask[start:end] loss = sess.run(loss_op, feed_dict={v_input: x, v_mask: m, epoch: [step]}) errsum = errsum + loss print('epoch=%d, batch=%d, loss=%f' % (step, batch, loss)) print('epoch=%d, loss=%f' % (step, errsum / 2015)) print('Training Finished!') print('---------------------------------------------')
cRBMHidden = tf.nn.sigmoid(tf.add(tf.matmul(content_x,cw),cb)) cinarybRBMSample = tf.nn.relu(tf.sign(cRBMHidden - tf.random_uniform(tf.shape(cRBMHidden)))) tRBMHidden = tf.nn.sigmoid(tf.add(tf.matmul(traffic_x,tw),tb)) tinarybRBMSample = tf.nn.relu(tf.sign(tRBMHidden - tf.random_uniform(tf.shape(tRBMHidden)))) RBMSample = 0 with tf.Session() as sess: sess.run(tf.global_variables_initializer()) f2,f3 = sess.run([cinarybRBMSample,tinarybRBMSample], feed_dict={content_x: contentFeatures,traffic_x:trafficFeatures}) RBMSample = f2 RBMSample = np.hstack((RBMSample,f3)) BBRBM = rbm(70,50,learning_rate=0.001,momentum=0.8,rbm_type='bbrbm',relu_hidden = True,init_method= 'uniform') BBRBM.plot=True w2, b2, b3= BBRBM.pretrain(RBMSample,batch_size=100,n_epoches=100) #no_GBRBM = rbm(122,80,learning_rate=0.001,momentum=0.8,rbm_type='gbrbm',relu_hidden = True) #no_GBRBM.plot=True #w, b1, b2= no_GBRBM.pretrain(allFeatures,batch_size=100,n_epoches=100) #basic_GBRBM = rbm(90,70,learning_rate=0.001,momentum=0.8,rbm_type='gbrbm',relu_hidden = True) #basic_GBRBM.plot=True #w, b1, b2= basic_GBRBM.pretrain(basicFeatures,batch_size=100,n_epoches=100) #content_GBRBM = rbm(13,10,learning_rate=0.001,momentum=0.8,rbm_type='gbrbm',relu_hidden = True) #content_GBRBM.plot=True
wsavePath = 'E:/workspace for python/Experiment/multimodalExperiment/NSLKDD/RBMs/noModalityRBMPara/122_60_w.csv' b1savePath = 'E:/workspace for python/Experiment/multimodalExperiment/NSLKDD/RBMs/noModalityRBMPara/122_60_b1.csv' b2savePath = 'E:/workspace for python/Experiment/multimodalExperiment/NSLKDD/RBMs/noModalityRBMPara/122_60_b2.csv' #def writeCsv(savePath,data): # file = open(savePath, 'w', newline='') # csvWriter = csv.writer(file) # count = 0 # for row in data: # temp_row=np.array(row) # csvWriter.writerow(temp_row) # count +=1 # file.close() no_GBRBM = rbm(122, 60, learning_rate=0.001, momentum=0.8, rbm_type='gbrbm', relu_hidden=True) no_GBRBM.plot = True w, b1, b2 = no_GBRBM.pretrain(allFeatures, batch_size=100, n_epoches=100) #basic_GBRBM = rbm(90,70,learning_rate=0.001,momentum=0.8,rbm_type='gbrbm',relu_hidden = True) #basic_GBRBM.plot=True #w, b1, b2= basic_GBRBM.pretrain(basicFeatures,batch_size=100,n_epoches=100) #content_GBRBM = rbm(13,10,learning_rate=0.001,momentum=0.8,rbm_type='gbrbm',relu_hidden = True) #content_GBRBM.plot=True #w, b1, b2= content_GBRBM.pretrain(contentFeatures,batch_size=100,n_epoches=100) #traffic_GBRBM = rbm(19,15,learning_rate=0.001,momentum=0.8,rbm_type='gbrbm',relu_hidden = True) #traffic_GBRBM.plot=True