コード例 #1
0
ファイル: relayctl.c プロジェクト: appleorange1/bitrig
int
show_summary_msg(struct imsg *imsg, int type)
{
	struct rdr		*rdr;
	struct table		*table;
	struct host		*host;
	struct relay		*rlay;
	struct router		*rt;
	struct netroute		*nr;
	struct ctl_stats	 stats[RELAY_MAXPROC];
	char			 name[MAXHOSTNAMELEN];

	switch (imsg->hdr.type) {
	case IMSG_CTL_RDR:
		if (!(type == SHOW_SUM || type == SHOW_RDRS))
			break;
		rdr = imsg->data;
		printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
		    rdr->conf.id, "redirect", rdr->conf.name, "",
		    print_rdr_status(rdr->conf.flags));
		break;
	case IMSG_CTL_TABLE:
		if (!(type == SHOW_SUM || type == SHOW_HOSTS))
			break;
		table = imsg->data;
		printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
		    table->conf.id, "table", table->conf.name, "",
		    print_table_status(table->up, table->conf.flags));
		break;
	case IMSG_CTL_HOST:
		if (!(type == SHOW_SUM || type == SHOW_HOSTS))
			break;
		host = imsg->data;
		if (host->conf.parentid)
			snprintf(name, sizeof(name), "%s parent %u",
			    host->conf.name, host->conf.parentid);
		else
			strlcpy(name, host->conf.name, sizeof(name));
		printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
		    host->conf.id, "host", name,
		    print_availability(host->check_cnt, host->up_cnt),
		    print_host_status(host->up, host->flags));
		if (type == SHOW_HOSTS && host->check_cnt) {
			printf("\t%8s\ttotal: %lu/%lu checks",
			    "", host->up_cnt, host->check_cnt);
			if (host->retry_cnt)
				printf(", %d retries", host->retry_cnt);
			if (host->he && host->up == HOST_DOWN)
				printf(", error: %s", host_error(host->he));
			printf("\n");
		}
		break;
	case IMSG_CTL_RELAY:
		if (!(type == SHOW_SUM || type == SHOW_RELAYS))
			break;
		rlay = imsg->data;
		printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
		    rlay->rl_conf.id, "relay", rlay->rl_conf.name, "",
		    print_relay_status(rlay->rl_conf.flags));
		break;
	case IMSG_CTL_RDR_STATS:
		if (type != SHOW_RDRS)
			break;
		bcopy(imsg->data, &stats[0], sizeof(stats[0]));
		stats[1].id = EMPTY_ID;
		print_statistics(stats);
		break;
	case IMSG_CTL_RELAY_STATS:
		if (type != SHOW_RELAYS)
			break;
		bcopy(imsg->data, &stats, sizeof(stats));
		print_statistics(stats);
		break;
	case IMSG_CTL_ROUTER:
		if (!(type == SHOW_SUM || type == SHOW_ROUTERS))
			break;
		rt = imsg->data;
		printf("%-4u\t%-8s\t%-24s\t%-7s\t%s\n",
		    rt->rt_conf.id, "router", rt->rt_conf.name, "",
		    print_relay_status(rt->rt_conf.flags));
		if (type != SHOW_ROUTERS)
			break;
		if (rt->rt_conf.rtable)
			printf("\t%8s\trtable: %d\n", "", rt->rt_conf.rtable);
		if (strlen(rt->rt_conf.label))
			printf("\t%8s\trtlabel: %s\n", "", rt->rt_conf.label);
		break;
	case IMSG_CTL_NETROUTE:
		if (type != SHOW_ROUTERS)
			break;
		nr = imsg->data;
		(void)print_host(&nr->nr_conf.ss, name, sizeof(name));
		printf("\t%8s\troute: %s/%d\n",
		    "", name, nr->nr_conf.prefixlen);
		break;
	case IMSG_CTL_END:
		return (1);
	default:
		errx(1, "wrong message in summary: %u", imsg->hdr.type);
		break;
	}
	return (0);
}
コード例 #2
0
ファイル: backprop.cpp プロジェクト: ylou/catnip
  void BackpropTrainer::train(FeedForwardNetwork& network, LabeledDataset& ds, int epochs) {
    FeedForwardNetwork::LayerIterator lit;
    for (lit = network.layers_begin(); lit != network.layers_end(); ++lit) {
      int k = lit->get_k();

      sigmas_.push_back(lit->clone());
      outputs_.push_back(new viennacl::vector<float>(k));
      derivatives_.push_back(new viennacl::vector<float>(k));
    }

    std::vector<int> indexes;
    for (int i = 0; i < ds.size(); ++i) {
      indexes.push_back(i);
    }

    viennacl::vector<float> error;
    std::vector<float> host_error(ds.output_size(), 0);

    for (int i = 0; i < epochs; ++i) {
      float avg_rms_error = 0.0f;

      std::random_shuffle(indexes.begin(), indexes.end());
      for (std::vector<int>::iterator it = indexes.begin(); it != indexes.end(); ++it) {
        const viennacl::vector<float>& input = ds.get_input(*it);
        const viennacl::vector<float>& output = ds.get_output(*it);

        // Forward pass.
        network.get_input_layer().get_value() = input;
        for (int j = 0; j < network.get_num_connections(); ++j) {
          Layer& layer = network.get_layer(j);
          Layer& next_layer = network.get_layer(j + 1);
          Connection& conn = network.get_connection(j);

          layer.activate(derivatives_[j]);
          conn.layer_propogate(layer, next_layer);
          viennacl::ocl::get_queue().finish();
          
          outputs_[j] = layer.get_value();
        }
        Layer& output_layer = network.get_output_layer();
        output_layer.activate(derivatives_.back());

        // Backwards pass.
        error = output - output_layer.get_value();
        sigmas_.back().get_value() = viennacl::linalg::element_prod(derivatives_.back(), error); 
        for (int j = network.get_num_layers() - 1; j > 0; --j) {
          Layer& prev_layer = network.get_layer(j - 1);
          Layer& layer = network.get_layer(j);
          Connection& conn = network.get_connection(j - 1);

          delegate_->backpropogate(sigmas_[j - 1], conn, sigmas_[j], derivatives_[j - 1]);
          viennacl::ocl::get_queue().finish();

          delegate_->update(conn, sigmas_[j].get_value(), outputs_[j - 1]);
          viennacl::ocl::get_queue().finish();

          delegate_->update(layer, sigmas_[j].get_value());
          viennacl::ocl::get_queue().finish();
        } 

        fast_copy(error, host_error);

        float rms_error = 0.0f;
        for (size_t j = 0; j < host_error.size(); ++j) {
          rms_error += host_error[j] * host_error[j];
        }

        rms_error = sqrt(rms_error / host_error.size());
        avg_rms_error += rms_error;
      }

      avg_rms_error /= ds.size();

      std::cout << "Epoch=" << i << " Avg-RMS=" << avg_rms_error << std::endl;
    }
  }
コード例 #3
0
ファイル: virtual.c プロジェクト: chunhualiu/OpenNT
/*
   Entry point from Windows 386 Virtual Device Driver (INSIGNIA.386) - Provide
   virtualising services as required.
 */
GLOBAL void
virtual_device_trap IFN0()
   {
   int new_vb;

   switch ( getEAX() )
      {
   case VxD_Device_Init:
      /* We can check that the Intel version is valid */

      insignia_386_version = getDX();

      always_trace2("386 VxD: Device_Init version %d.%02d",
		    insignia_386_version / 100,
		    insignia_386_version % 100);

      /* pm selectors for virtualisation are in ebx and ecx */

      if ((getBX() !=0) && (getCX() !=0))
	sas_init_pm_selectors (getBX(), getCX());
      else
	always_trace0("386 VxD: Device_Init. Failed to get pm selectors!!");

      /* Compatibility test:
       * Return in top half of EDX the the "current" Intel version of the driver.
       * This allows an incompatible future driver to reject an old SoftWindows.
       */
#define INTEL_VERSION	102
      setEDX(INTEL_VERSION << 16);
      break;

   case VxD_Sys_VM_Init:
      always_trace0("386 VxD: Sys_VM_Init.");

      /* As safety measure undo anything which may be currently active */
      deallocate_all_NIDDB();
      restore_snapshot();

      /* Lock out Insignia Device Driver requests */
      allocation_allowed = FALSE;

      /* Form new instance */
      if ( allocate_NIDDB(getEBX(), &new_vb) )
	 {
	 /* Make new instance active (for create callback) */
	 swap_NIDDB(new_vb);

	 /* Copy instance data and action create callback */
	 copy_instance_data(vrecs[new_vb].vr_pinst_tbl, snapshot_ptrs);

	 /* Return virtualising byte to INSIGNIA.386 */
	 setEAX(new_vb);
	 }
      else
	 {
	 /* We can't do it */
	 setCF(1);   /* Inform Windows that Virtual Machine can't be created */
	 host_error(EG_MALLOC_FAILURE, ERR_CONT , "");
	 }
      break;

   case VxD_VM_Init:
      always_trace0("386 VxD: VM_Init.");
      /* Form new instance */
      if ( allocate_NIDDB(getEBX(), &new_vb) )
	 {
	 /* Make new instance active (for create callback) */
	 swap_NIDDB(new_vb);

	 /* Copy instance data and action create callback */
	 copy_instance_data(vrecs[new_vb].vr_pinst_tbl, snapshot_ptrs);

	 /* Return virtualising byte to INSIGNIA.386 */
	 setEAX(new_vb);
	 }
      else
	 {
	 /* We can't do it */
	 setCF(1);   /* Inform Windows that Virtual Machine can't be created */
	 host_error(EG_MALLOC_FAILURE, ERR_CONT , "");
	 }
      break;

   case VxD_VM_Not_Executeable:
      always_trace0("386 VxD: VM_Not_Executeable.");
      deallocate_specific_NIDDB(getEBX());
      break;

   case VxD_Device_Reboot_Notify:
      always_trace0("386 VxD: Device_Reboot_Notify.");
      deallocate_all_NIDDB();
      restore_snapshot();

      /* Clear our version number in case we are changing disks */
      insignia_386_version = 0;
      break;

   case VxD_System_Exit:
      always_trace0("386 VxD: System_Exit.");
      deallocate_all_NIDDB();
      restore_snapshot();
      ClearInstanceDataMarking();

#ifndef NTVDM
      host_mswin_disable();
#endif /* ! NTVDM */

      /* Clear our version number in case we are changing disks */
      insignia_386_version = 0;
      break;

   default:
      always_trace1("386 VxD: Unrecognised Control Message. 0x%02x", getEAX());
      }
   }