def make_records(self): # record all the results' details into files _, Decoder, l1, l2 = self.sess.run( [self.cost, self.Decoder, self.pre_cost3, self.pre_cost4], feed_dict={ self.input_R_U: self.train_R, self.input_R_I: self.train_R, self.input_OH_U: self.U_OH_mat, self.input_OH_I: self.I_OH_mat, self.input_P_cor: [[0, 0]], self.input_N_cor: [[0, 0]], self.row_idx: np.reshape(range(self.num_rows), (self.num_rows, 1)), self.col_idx: np.reshape(range(self.num_cols), (self.num_cols, 1)) }) if self.base == 'i': [precision, recall, f_score, NDCG, r_f_table] = utility.test_model_all(Decoder.T, self.vali_R.T, self.train_R.T) else: [precision, recall, f_score, NDCG, r_f_table] = utility.test_model_all(Decoder, self.vali_R, self.train_R) utility.metric_record(precision, recall, f_score, NDCG, self.args, self.metric_path) utility.test_model_factor(Decoder, self.vali_R, self.train_R) print("******** max_epoch ********") print(self.max_epoch) return precision, recall, f_score, NDCG
def make_records(self): # record all the results' details into files _, Decoder = self.sess.run( [self.cost, self.Decoder], feed_dict={ self.input_R_U: self.train_R, self.input_R_U_index: self.U_OH_mat, self.is_training_ph: 0, self.anneal_ph: 0.2, self.row_idx: np.reshape(range(self.num_rows), (self.num_rows, 1)) }) if self.base == 'i': [precision, recall, f_score, NDCG, r_f_table] = utility.test_model_all(Decoder.T, self.vali_R.T, self.train_R.T) else: [precision, recall, f_score, NDCG, r_f_table] = utility.test_model_all(Decoder, self.vali_R, self.train_R) utility.metric_record(precision, recall, f_score, NDCG, self.args, self.metric_path) utility.test_model_factor(Decoder, self.vali_R, self.train_R) print("******** max_epoch ********") print(self.max_epoch) return precision, recall, f_score, NDCG
def make_records(self): # record all the results' details into files print("in make record. we will calculate metrics after here.") _, Decoder = self.sess.run( [self.cost, self.Decoder], feed_dict={ self.input_R_U: self.train_R, self.input_R_I: self.train_R, self.input_OH_I: self.I_OH_mat, self.input_P_cor: [[0, 0]], self.input_N_cor: [[0, 0]], self.row_idx: np.reshape(xrange(self.num_rows), (self.num_rows, 1)), self.col_idx: np.reshape(xrange(self.num_cols), (self.num_cols, 1)) }) if self.base == 'i': [precision, recall, f_score, NDCG] = utility.test_model_all(Decoder.T, self.vali_R.T, self.train_R.T, self.price_R.T, 'save_intermediate_results') else: [precision, recall, f_score, NDCG] = utility.test_model_all(Decoder, self.vali_R, self.train_R, self.price_R, 'save_intermediate_results') utility.metric_record(precision, recall, f_score, NDCG, self.args, self.metric_path) utility.test_model_factor(Decoder, self.vali_R, self.train_R) return precision, recall, f_score, NDCG
def test_model( self, itr): # calculate the cost and rmse of testing set in each epoch start_time = time.time() corruption_R = np.random.binomial(1, 1 - self.corruption_ratio, (self.num_rows, self.num_cols)) _, plot1, plot2, scaling, Decoder = self.sess.run( [ self.cost, self.plotting, self.plotting2, self.scaling, self.Decoder ], feed_dict={ self.input_R_U: self.train_R, self.input_R_U_index: self.U_OH_mat, self.corrupted_R: corruption_R, self.input_P_cor: [[0, 0]], self.input_N_cor: [[0, 0]], self.row_idx: np.reshape(range(self.num_rows), (self.num_rows, 1)), self.col_idx: np.reshape(range(self.num_cols), (self.num_cols, 1)) }) if itr % self.display_step == 0: pre_numerator = np.multiply((Decoder - self.vali_R), self.vali_R) numerator = np.sum(np.square(pre_numerator)) denominator = self.num_test_ratings RMSE = np.sqrt(numerator / float(denominator)) if itr % 1 == 0: if self.base == 'i': [precision, recall, f_score, NDCG, r_f_table ] = utility.test_model_all(Decoder.T, self.vali_R.T, self.train_R.T) else: [precision, recall, f_score, NDCG, r_f_table ] = utility.test_model_all(Decoder, self.vali_R, self.train_R) if self.max_f1_avg < f_score[2]: self.max_f1_avg = f_score[2] self.max_r_f_table = r_f_table self.max_epoch = itr self.max_embedded_x = plot1 self.max_embedded2_x = plot2 self.max_scaling = scaling print("Testing //", "Epoch %d //" % itr, " Total cost = {:.2f}".format(numerator), " RMSE = {:.5f}".format(RMSE), "Elapsed time : %d sec" % (time.time() - start_time)) print("=" * 100)
def test_model( self, itr): # calculate the cost and rmse of testing set in each epoch start_time = time.time() _, Encoder, Decoder = self.sess.run( [ self.cost, self.U_Encoder[:, :self.U_hidden_neuron], self.Decoder ], feed_dict={ self.input_R_U: self.train_R, self.input_R_U_index: self.U_OH_mat, self.is_training_ph: 0, self.anneal_ph: 0.2, self.row_idx: np.reshape(range(self.num_rows), (self.num_rows, 1)) }) if itr % self.display_step == 0: pre_numerator = np.multiply((Decoder - self.vali_R), self.vali_R) numerator = np.sum(np.square(pre_numerator)) denominator = self.num_test_ratings RMSE = np.sqrt(numerator / float(denominator)) if itr % 1 == 0: if self.base == 'i': [precision, recall, f_score, NDCG, r_f_table ] = utility.test_model_all(Decoder.T, self.vali_R.T, self.train_R.T) else: [precision, recall, f_score, NDCG, r_f_table ] = utility.test_model_all(Decoder, self.vali_R, self.train_R) if self.max_f1_avg < f_score[2]: self.max_f1_avg = f_score[2] self.max_r_f_table = r_f_table self.max_epoch = itr self.max_embedded_x = Encoder print("Testing //", "Epoch %d //" % itr, " Total cost = {:.2f}".format(numerator), " RMSE = {:.5f}".format(RMSE), "Elapsed time : %d sec" % (time.time() - start_time)) print("=" * 100)
def test_model( self, itr): # calculate the cost and rmse of testing set in each epoch start_time = time.time() _, Decoder = self.sess.run( [self.cost, self.Decoder], feed_dict={ self.input_R_U: self.train_R, self.input_R_I: self.train_R, self.input_OH_I: self.I_OH_mat, self.input_P_cor: [[0, 0]], self.input_N_cor: [[0, 0]], self.row_idx: np.reshape(xrange(self.num_rows), (self.num_rows, 1)), self.col_idx: np.reshape(xrange(self.num_cols), (self.num_cols, 1)) }) if itr % self.display_step == 0: pre_numerator = np.multiply((Decoder - self.vali_R), self.vali_R) numerator = np.sum(np.square(pre_numerator)) denominator = self.num_test_ratings RMSE = np.sqrt(numerator / float(denominator)) if itr % 1 == 0: if self.base == 'i': [precision, recall, f_score, NDCG] = utility.test_model_all(Decoder.T, self.vali_R.T, self.train_R.T, self.price_R.T) else: [precision, recall, f_score, NDCG] = utility.test_model_all(Decoder, self.vali_R, self.train_R, self.price_R) print("Testing //", "Epoch %d //" % itr, " Total cost = {:.2f}".format(numerator), " RMSE = {:.5f}".format(RMSE), "Elapsed time : %d sec" % (time.time() - start_time)) print("=" * 100)
def test_model(self, itr): # calculate the cost and rmse of testing set in each epoch if itr % self.display_step == 0: start_time = time.time() * 1000.0 P, Q = self.sess.run([self.P, self.Q]) Rec = np.matmul(P, Q.T) [precision, recall, f_score, NDCG] = utility.test_model_all(Rec, self.vali_df, self.train_df) utility.ranking_analysis(Rec, self.vali_df, self.train_df, self.key_genre, self.item_genre_list, self.user_genre_count) print(( "Testing //", "Epoch %d //" % itr, "Testing time : %d ms" % (time.time() * 1000.0 - start_time))) print(("=" * 200))
def make_records(self): # record all the results' details into files P, Q = self.sess.run([self.P, self.Q]) Rec = np.matmul(P, Q.T) [precision, recall, f_score, NDCG] = utility.test_model_all(Rec, self.vali_df, self.train_df) return precision, recall, f_score, NDCG, Rec