Exemplo n.º 1
0
void Connector::event_loop(struct rdma_event_channel* ec_, bool exit_on_disconn)
{
  struct rdma_cm_event* event_ = NULL;
  struct rdma_conn_param cm_param;

  build_param(&cm_param);
  while (rdma_get_cm_event(ec_, &event_) == 0) {
    struct rdma_cm_event event_copy;
    memcpy(&event_copy, event_, sizeof(*event_) );
    rdma_ack_cm_event(event_);
    if (event_copy.event == RDMA_CM_EVENT_ADDR_RESOLVED) {
      build_conn(event_copy.id);
      
      ib_end_->on_pre_conn(event_copy.id);
      
      TEST_NZ(rdma_resolve_route(event_copy.id, TIMEOUT_IN_MS) )
    } 
    else if (event_copy.event == RDMA_CM_EVENT_ROUTE_RESOLVED) {
Exemplo n.º 2
0
int GisTrainer::train (
        DataReader& data_reader, LinearModel& model,
        int iter, float tol, float sigma2) {

    int ret = 0;
    int correct_num = 0;
    float log_likelihood = 0.0;
    char  file_name[MAX_PATH_LEN];

    if (sigma2 < 0.0) {
        log_warn ("gauss prior should be greater than zero.");
        return -1;
    }

    ret = build_param(data_reader, model);
    if (ret != 0) {
        log_warn("build parameter failed.");
        return -1;
    }

    ret = init_train(data_reader);
    if (ret != 0) {
        log_warn("init train failed.");
        return -1;
    }

    log_notice("start GIS iterations...");
    log_notice("number of feature:      %d.", _feat_num);
    log_notice("number of label:        %d.", _label_num);
    log_notice("Tolerance:              %E.", tol);
    log_notice("Gaussian Penalty:       %s", (sigma2?"on":"off"));
    log_notice("objective: min sum {-log p(y|x)} + 1/(2*sigma2)*||w||^2");


    log_notice("iters   loglikelihood    training accuracy");
    log_notice("==========================================");

    for (int cur_iter=0; cur_iter<iter; cur_iter++) {

        ret = cmpt_estimated(data_reader, model, correct_num, log_likelihood);
        if (ret != 0) {
            log_warn("compute estimated failed.");
            return -1;
        }
        log_notice("%3d\t%f\t  %.3f%%", cur_iter, log_likelihood/_tot_event_count, 
                        (float)correct_num/_tot_event_count*100);
        

        //update parameter
        if (sigma2) {
            float* weight_mat = model._weight_mat;
            float delta = 0.0;

            for (int feat_id=0; feat_id<_feat_num; feat_id++) {
                for (int label_id=0; label_id<_label_num; label_id++) {
                    ret = newton(_estimated[feat_id*_label_num + label_id],
                                _observed[feat_id*_label_num + label_id],
                                weight_mat[feat_id*_label_num + label_id],
                                sigma2, delta);
                    if (ret != 0) {
                        log_warn("newton method failed.");
                        return -1;
                    }

                    weight_mat[feat_id*_label_num + label_id] += delta;
                }
            }
        } else {

            float* weight_mat = model._weight_mat;
            float  log_observed  = 0.0;
            float  log_estimated = 0.0;

            for (int feat_id=0; feat_id<_feat_num; feat_id++) {
                for (int label_id=0; label_id<_label_num; label_id++) {
                    //unseen feature
                    if (_observed[feat_id*_label_num + label_id] == 0.0) {
                        continue;
                    }

                    log_observed  = log(_observed[feat_id*_label_num + label_id]);

                    log_estimated = _estimated[feat_id*_label_num + label_id]==0 ? LOG_ZERO 
                                    : log(_estimated[feat_id*_label_num + label_id]);

                    weight_mat[feat_id*_label_num + label_id] += (log_observed-log_estimated)/_correct_constant;
                }
            }
        }

    }

    log_notice ("train by gis_trainer success.");
    return 0;
}
Exemplo n.º 3
0
/**
 * Shot data of a test case.
 *
 * @param i Number of test case
 * @param phis Physical record number of this test case. If you do not know
 * it, set it to zero (so that Proteum look for this data by itself).
 */
int
ListaTCase(int i, int phis)
{
	int	n, j, k, t;
	struct vetfunc	*p;
	char c;

   k = i;
   if (! phis) 
      k = ltofis_tcase(&testSet, i);
   if (k == ERRO)
	return;
   if (le_tcase_reg(&testSet, k) == ERRO)
	return;

   printf("\nTeste Case # %d %d", i, k);
   printf("\nLabel:\t%s", TREG(&testSet).label);
   printf("\n\t%s", TAB_FIS(&testSet)[k].desabili? "DISABLED": "ENABLED");
   if (TAB_FIS(&testSet)[k].error)
	printf("\n\tTest case caused an ERROR");
   printf("\n\tExec. Time (CPU): %ld", TREG(&testSet).exetempo); 
   printf("\n\tExec. Time (total): %ld", TREG(&testSet).totaltempo);
   printf("\n\tReturn Code: %d", TREG(&testSet).retcode);
   if (TAB_FIS(&testSet)[k].error)
	printf(" (Failure with test case)");
   printf("\n\tParameters: %s", (char *) build_param(TREG(&testSet).param));
   printf("\n\tInput Size: %d", TREG(&testSet).tamanho_ent);
   printf("\n\tOutput Size: %d", TREG(&testSet).tamanho_sai);
   printf("\n\tStderr Size: %d", TREG(&testSet).tamanho_err);

   printf("\n\tInput:\n");
   posiciona(TFILEIO(&testSet), TREG(&testSet).apont_ent);
   for (j = 0; j < TREG(&testSet).tamanho_ent; j++)
   {
	fscanf(TFILEIO(&testSet), "%c", &c);
	printf("%c", c);
   }

/*   copy_file(TFILEIO(&testSet), TREG(&testSet).apont_ent, 
				TREG(&testSet).tamanho_ent, stdout); */

   t = TREG(&testSet).tamanho_ent;
   printf("\n\tOutput:\n");
   copy_file(TFILEIO(&testSet), TREG(&testSet).apont_ent + t, 
				TREG(&testSet).tamanho_sai, stdout);
   t += TREG(&testSet).tamanho_sai;
   printf("\n\tStderr:\n");
   copy_file(TFILEIO(&testSet), TREG(&testSet).apont_ent + t, 
				TREG(&testSet).tamanho_err, stdout);
   printf("\nTravessed blocks:");
   tcase_get_log(&testSet, -1, -1);
   if ( testSet.log != NULL)
      for (n = 0; n < testSet.log->nfunction; n++)
      {
	 p = &(testSet.log->vetfunc[n]);
	 printf("\n\tFunction: %ld\n\tBlocks: ", p->function);
	 for (j = 1; j <= p->nnode; j++)
	 {
	   if (get_log_bit(p->nodes, j))
		printf("%d ", j);
	 }
      }

   printf("\n");

}