model_gamma = Sequential() # First compute the kernel model_gamma.add( Dense(var_dic['gamma'].shape[1], use_bias=False, activation=alt_softmax, kernel_initializer=gamma_initializer, kernel_constraint=LowerDiagWeight())) model_gamma.compile(loss=GCM.pos_log_loss, optimizer=RMSprop()) model_tau = Sequential() model_tau.add( Dense(var_dic['tau'].shape[1], input_dim=var_dic['tau'].shape[1], activation=None, use_bias=False, kernel_initializer=Identity(), trainable=False)) model_tau.compile('rmsprop', 'binary_crossentropy' ) # No trainable weights, so doesn't really matter var_models = {'phi_A': model_phi_A, 'gamma': model_gamma, 'tau': model_tau} res = GCM.runEM(click_mat.to_numpy(), var_dic, var_models, item_pos_mat.to_numpy(), model_def, verbose=True) print(res[2])
.pivot(index='session', columns='item_order', values='click') \ .to_numpy() item_pos_mat = click_data.loc[:, ['session', 'item_order', 'item']] \ .pivot(index='session', columns='item_order', values='item') \ .to_numpy() # Ensure that the order is correct item_feature_mat_A = pd.get_dummies( click_data['item'].sort_values().unique()) model_phi_A = Sequential() model_phi_A.add( Dense(1, input_dim=item_feature_mat_A.shape[1], activation='sigmoid', use_bias=False)) model_phi_A.compile(loss=GCM.pos_log_loss, optimizer=RMSprop()) var_dic = {'phi_A': item_feature_mat_A} var_models = {'phi_A': model_phi_A} res = GCM.runEM(click_mat, var_dic, var_models, item_pos_mat, model_def, verbose=True, n_jobs=1) print(res[2])
use_bias=False)) model_phi_A.compile(loss=GCM.pos_log_loss, optimizer=Adagrad()) model_gamma = Sequential() # First compute the kernel model_gamma.add( Dense(1, input_dim=item_feature_mat_gamma.shape[1], activation='sigmoid', use_bias=False)) model_gamma.add(RepeatVector(no_states**2)) model_gamma.compile(loss=GCM.pos_log_loss, optimizer=Adagrad()) var_dic = {'phi_A': item_feature_mat_A, 'gamma': item_feature_mat_gamma} var_models = {'phi_A': model_phi_A, 'gamma': model_gamma} res = GCM.runEM(click_mat, var_dic, var_models, item_pos_mat, model_def, verbose=True, earlystop_patience=10, n_jobs=1) pl.dump(res[1], open("./data/small_example/state_prob.pl", "wb")) pl.dump(res[2], open("./data/small_example/convergence.pl", "wb")) pl.dump(res[3], open("./data/small_example/click_probs.pl", "wb")) print(res[2])