示例#1
0
	def train(self):

		#wb is a dictionary that stores the average Weight matrices and Bias matrices. The keys are where the 
		#files are stored 
		self.wb = {}



		"""
		For each user an RBM will be created. 
		"""
		for i in range(self.dataset.training_X.shape[1]):
			user = self.dataset.training_X[:,i]
			rbm = RBM(hidden_layer_n=HIDDEN_LAYER_N,iterations=ITERATIONS,dataset=user)
			rbm.run()

			#After the an RBM is run the weights and biases are re-added to complete  set. 
			self.all_weights.append(rbm.full_weights)
			self.all_bv.append(rbm.full_bv)
			self.all_bh.append(rbm.full_bh)

			print("RBM number: " + str(i))


		#Average all the weights and all the biases from all the RBM's (With each RBM corresponding to a user)
		self.wb[WEIGHTS_FILE] = self.average_matrices(self.all_weights)
		self.wb[VISIBLE_BIAS_FILE] = self.average_matrices(self.all_bv)
		self.wb[HIDDEN_BIAS_FILE] = self.average_matrices(self.all_bh)


		#Training can take a long time so we can save the weights and biases 
		self.save_matrix(WEIGHTS_FILE)
		self.save_matrix(VISIBLE_BIAS_FILE)
		self.save_matrix(HIDDEN_BIAS_FILE)