weight_decay=weight_decay_classifier, alpha_labeled=alpha_labeled, alpha_unlabeled=sym_alpha_unlabel_entropy, alpha_average=sym_alpha_unlabel_average, alpha_decay=alpha_decay) pretrain_cla_loss = categorical_crossentropy_ssl_separated(predictions_l=cla_out_y_l, targets=sym_y, predictions_u=cla_out_y, weight_decay=weight_decay_classifier, alpha_labeled=alpha_labeled, alpha_unlabeled=pre_alpha_unlabeled_entropy, alpha_average=pre_alpha_average, alpha_decay=alpha_decay) pretrain_cost = pretrain_cla_loss cla_cost_cla_g = categorical_crossentropy(predictions=cla_out_y_g, targets=sym_y_g) '''##################D1###################''' dis_cost = dis_cost_p + .5 * dis_cost_p_g + .5 * dis_cost_p_c + .5 * dis_cost_p_g_c dis_cost_list = [dis_cost] '''##################D2###################''' dis2_cost = .5 * dis2_cost_p_g + .5 * dis2_cost_p_c + .5 * dis2_cost_p_g_c dis2_cost_list = [dis2_cost] '''##################D3###################''' dis3_cost = .5 * dis3_cost_p_g + .5 * dis3_cost_p_c dis3_cost_list = [dis3_cost]
dis_cost_p = bce(dis_out_p, T.ones(dis_out_p.shape)).mean() # D distincts p dis_cost_p_g = bce(dis_out_p_g, T.zeros(dis_out_p_g.shape)).mean() # D distincts p_g gen_cost_p_g_1 = bce(dis_out_p_g, T.ones(dis_out_p_g.shape)).mean() # G fools D disxz_cost_p = bce(disxz_out_p, T.ones(disxz_out_p.shape)).mean() disxz_cost_p_g = bce(disxz_out_p_g, T.zeros(disxz_out_p_g.shape)).mean() inf_cost_p_i = bce(disxz_out_p, T.zeros(disxz_out_p.shape)).mean() gen_cost_p_g_2 = bce(disxz_out_p_g, T.ones(disxz_out_p_g.shape)).mean() cla_cost_l = T.mean(lasagne.objectives.categorical_crossentropy(cla_out_y_l, sym_y), dtype=theano.config.floatX, acc_dtype=theano.config.floatX) cla_cost_g = T.mean(lasagne.objectives.categorical_crossentropy(cla_out_y_m, sym_y_m), dtype=theano.config.floatX, acc_dtype=theano.config.floatX) * sym_w_g cla_cost_u = sym_unsup_weight * T.mean(lasagne.objectives.squared_error(cla_out_y, cla_out_y_rep), dtype=theano.config.floatX, acc_dtype=theano.config.floatX) rz = mean_squared_error(inf_z_g, sym_z_rand, n_z) ry = categorical_crossentropy(cla_out_y_g, sym_y_g) pretrain_cost = cla_cost_l + cla_cost_u cla_cost = cla_cost_l + cla_cost_u + cla_cost_g dis_cost = dis_cost_p + dis_cost_p_g disxz_cost = disxz_cost_p + disxz_cost_p_g inf_cost = inf_cost_p_i + rz gen_cost = gen_cost_p_g_1 + gen_cost_p_g_2 + rz + ry dis_cost_list=[dis_cost + disxz_cost, dis_cost, dis_cost_p, dis_cost_p_g, disxz_cost, disxz_cost_p, disxz_cost_p_g] gen_cost_list=[gen_cost, gen_cost_p_g_1, gen_cost_p_g_2, rz, ry] inf_cost_list=[inf_cost, inf_cost_p_i, rz] cla_cost_list=[cla_cost, cla_cost_l, cla_cost_u, cla_cost_g] # updates of D dis_params = ll.get_all_params(dis_layers, trainable=True) + ll.get_all_params(disxz_layers, trainable=True)
disxz_cost_p_g = bce(disxz_out_p_g, T.zeros(disxz_out_p_g.shape)).mean() inf_cost_p_i = bce(disxz_out_p, T.zeros(disxz_out_p.shape)).mean() gen_cost_p_g_2 = bce(disxz_out_p_g, T.ones(disxz_out_p_g.shape)).mean() weight_decay_classifier = lasagne.regularization.regularize_layer_params_weighted( {cla_layers[-1]: 1}, lasagne.regularization.l2) pretrain_cost = categorical_crossentropy_ssl_separated( predictions_l=cla_out_y_l, targets=sym_y, predictions_u=cla_out_y_d, weight_decay=weight_decay_classifier, alpha_labeled=alpha_labeled, alpha_unlabeled=alpha_unlabeled_entropy, alpha_average=alpha_average, alpha_decay=alpha_decay) cla_cost_g = sym_unsup_weight * categorical_crossentropy(cla_out_y_m, sym_y_m) cla_cost = pretrain_cost + cla_cost_g dis_cost = dis_cost_p + dis_cost_p_g disxz_cost = disxz_cost_p + disxz_cost_p_g rz = mean_squared_error(inf_z_g, sym_z_rand, n_z) ry = categorical_crossentropy(cla_out_y_g, sym_y_g) inf_cost = inf_cost_p_i + rz gen_cost = gen_cost_p_g_1 + gen_cost_p_g_2 + rz + ry dis_cost_list = [ dis_cost + disxz_cost, dis_cost, dis_cost_p, dis_cost_p_g, disxz_cost, disxz_cost_p, disxz_cost_p_g ] gen_cost_list = [gen_cost, gen_cost_p_g_1, gen_cost_p_g_2, rz, ry] inf_cost_list = [inf_cost, inf_cost_p_i, rz]