Exemple #1
0
static void
update_limit(struct um_user *user, jobj_t obj)
{
    update_online(user, obj, max);
    update_online(user, obj, idle);
    update_online(user, obj, numerator);
    update_online(user, obj, denominator);
    
    updata_flow(user, obj, max);
    updata_flow(user, obj, numerator);
    updata_flow(user, obj, denominator);
    
    updata_rate(user, obj, max);
    updata_rate(user, obj, avg);
}
Exemple #2
0
static void
dhcpcd_if_cb(DHCPCD_IF *i, _unused void *data)
{
	DHCPCD_CONNECTION *con;
	char *msg;
	const char *icon;
	bool new_msg;

	/* We should ignore renew and stop so we don't annoy the user */
	if (g_strcmp0(i->reason, "RENEW") &&
	    g_strcmp0(i->reason, "STOP") &&
	    g_strcmp0(i->reason, "STOPPED"))
	{
		msg = dhcpcd_if_message(i, &new_msg);
		if (msg) {
			g_message("%s", msg);
			if (new_msg) {
				if (i->up)
					icon = "network-transmit-receive";
				//else
				//	icon = "network-transmit";
				if (!i->up)
					icon = "network-offline";
				notify(_("Network event"), msg, icon);
			}
			g_free(msg);
		}
	}

	/* Update the tooltip with connection information */
	con = dhcpcd_if_connection(i);
	update_online(con, false);
}
Exemple #3
0
static void
dhcpcd_status_cb(DHCPCD_CONNECTION *con, const char *status,
    _unused void *data)
{
	static char *last = NULL;
	const char *msg;
	bool refresh;
	WI_SCAN *w;

	g_message("Status changed to %s", status);
	if (g_strcmp0(status, "down") == 0) {
		msg = N_(last ?
		    "Connection to dhcpcd lost" : "dhcpcd not running");
		if (ani_timer != 0) {
			g_source_remove(ani_timer);
			ani_timer = 0;
			ani_counter = 0;
		}
		online = carrier = false;
		gtk_status_icon_set_from_icon_name(status_icon,
		    "network-offline");
		gtk_status_icon_set_tooltip_text(status_icon, msg);
		dhcpcd_prefs_abort();
		while (wi_scans) {
			w = wi_scans->next;
			dhcpcd_wi_scans_free(wi_scans->scans);
			g_free(wi_scans);
			wi_scans = w;
		}
		dhcpcd_unwatch(-1, con);
		g_timeout_add(DHCPCD_RETRYOPEN, dhcpcd_try_open, con);
	} else {
		if ((last == NULL || g_strcmp0(last, "down") == 0)) {
			g_message(_("Connected to %s-%s"), "dhcpcd",
			    dhcpcd_version(con));
			refresh = true;
		} else
			refresh = g_strcmp0(last, "opened") ? false : true;
		update_online(con, refresh);
	}

	g_free(last);
	last = g_strdup(status);
}
Exemple #4
0
// Stochastic Gradient Descent (SGD) Optimization
int LR::train_sgd( int max_loop, double loss_thrd, float learn_rate, float lambda, int avg)
{
	int id = 0;
	double loss = 0.0;
	double loss_pre = 0.0;
	vector< vector<float> > omega_pre=omega;
	float acc=0.0;

	vector< vector<float> > omega_sum(omega);

    //最多迭代(最大循环 * 训练样本类别个数)次
	while (id <= max_loop*(int)samp_class_vec.size())
	{
		if (id%samp_class_vec.size() == 0)	// 完成一次迭代,预处理工作。
		{
			int loop = id/(int)samp_class_vec.size();               //check loss
		    loss = 0.0;
		    acc = 0.0;

			calc_loss(&loss, &acc); //计算损失
			cout.setf(ios::left);
			cout << "Iter: " << setw(8) << loop << "Loss: " << setw(18) << loss << "Acc: " << setw(8) << acc << endl;
			//如果损失值小于阈值,停止迭代
			if ((loss_pre - loss) < loss_thrd && loss_pre >= loss && id != 0)
			{
				cout << "Reaching the minimal loss decrease!" << endl;
				break;
			}
			loss_pre = loss;    //保留上次损失值
			if (id)            //表示第一次不做正则项计算
			{
				for (int i=0;i!=omega_pre.size();i++)
					for (int j=0;j!=omega_pre[i].size();j++)
						omega[i][j]+=omega_pre[i][j]*lambda;   //lambda为权重衰减项
			}
			omega_pre=omega;
		}
		// update omega
		//随机选择样本
		int r = (int)(rand()%samp_class_vec.size());
		sparse_feat samp_feat = samp_feat_vec[r];    //随机样本的特征
		int samp_class = samp_class_vec[r];    //随机样本的类别

		update_online(samp_class, samp_feat, learn_rate, lambda);

		if (avg == 1 && id%samp_class_vec.size() == 0)
		{
			for (int i = 0; i < feat_set_size; i++)
			{
				for (int j = 0; j < class_set_size; j++)
				{
					omega_sum[i][j] += omega[i][j];
				}
			}
		}
		id++;
	} //迭代结束
	if (avg == 1)
	{
		for (int i = 0; i < feat_set_size; i++)
		{
			for (int j = 0; j < class_set_size; j++)
			{
				omega[i][j] = (float)omega_sum[i][j] / id;
			}
		}
	}
	return 1;
}