示例#1
0
int FCBF(DATA_SET & data, double min_threshold, std::string class_column, std::vector<std::string> & best_features) 
{
	PROB_HASH probs;
	PROB_GIVEN_HASH given_probs;
	std::vector<std::string> feature_names;
	std::list<std::pair<std::string, double>> list;
	GetKeys(data, feature_names);
	CalculateProbabilities(data, probs, given_probs, class_column);

	for(auto it = feature_names.begin(); it != feature_names.end(); ++it)
	{
		if(*it != class_column)
		{
			std::pair<std::string, double> tuple;
			tuple.first = *it;
			tuple.second = SU(data, probs, given_probs, class_column, *it);

			if(tuple.second > min_threshold) 
			{
				list.push_back(tuple);
			}
		}
	}

	list.sort(TupleCompare);

	auto F_j = list.begin();

	while (F_j != list.end())
	{
		auto F_i = F_j;
		++F_i;

		while (F_i != list.end())
		{
			double su_ij = SU(data, probs, given_probs, F_j->first, F_i->first);
			if(su_ij >= F_i->second)
			{
				F_i = list.erase(F_i);
			}
			else
			{
				++F_i;
			}
		}
		++F_j;
	}

	best_features.clear();
	best_features.reserve(list.size());
	for(auto it = list.begin(); it != list.end(); ++it)
	{
		best_features.push_back(it->first);
	}

	return 0;
}
autoPtr<lcsMomentumSourcePluginFunction::dimVectorField>
coalCloudMomentumSourcePluginFunction::internalEvaluate()
{
    // pick up the first fitting class
#ifdef FOAM_REACTINGCLOUD_TEMPLATED
    tryCall(dimVectorField,constThermoCoalCloud,reactingMultiphaseCloud,SU());
    tryCall(dimVectorField,thermoCoalCloud,reactingMultiphaseCloud,SU());
    tryCall(dimVectorField,icoPoly8ThermoCoalCloud,reactingMultiphaseCloud,SU());
#else
    tryCall(dimVectorField,coalCloud,reactingMultiphaseCloud,UTrans());
#endif

    return lcsMomentumSourcePluginFunction::internalEvaluate();
}
示例#3
0
int
print_info (gnutls_session_t session, int print_cert)
{
    const char *tmp;
    gnutls_credentials_type_t cred;
    gnutls_kx_algorithm_t kx;
    unsigned char session_id[33];
    size_t session_id_size = sizeof (session_id);

    /* print session ID */
    gnutls_session_get_id (session, session_id, &session_id_size);
    printf ("- Session ID: %s\n",
            raw_to_string (session_id, session_id_size));

    /* print the key exchange's algorithm name
     */
    kx = gnutls_kx_get (session);

    cred = gnutls_auth_get_type (session);
    switch (cred)
      {
#ifdef ENABLE_ANON
      case GNUTLS_CRD_ANON:
          if (kx == GNUTLS_KX_ANON_ECDH)
              print_ecdh_info (session, "Anonymous ");
          else
              print_dh_info (session, "Anonymous ", verbose);
          break;
#endif
#ifdef ENABLE_SRP
      case GNUTLS_CRD_SRP:
          /* This should be only called in server
           * side.
           */
          if (gnutls_srp_server_get_username (session) != NULL)
              printf ("- SRP authentication. Connected as '%s'\n",
                      gnutls_srp_server_get_username (session));
          break;
#endif
#ifdef ENABLE_PSK
      case GNUTLS_CRD_PSK:
          /* This returns NULL in server side.
           */
          if (gnutls_psk_client_get_hint (session) != NULL)
              printf ("- PSK authentication. PSK hint '%s'\n",
                      gnutls_psk_client_get_hint (session));
          /* This returns NULL in client side.
           */
          if (gnutls_psk_server_get_username (session) != NULL)
              printf ("- PSK authentication. Connected as '%s'\n",
                      gnutls_psk_server_get_username (session));
          if (kx == GNUTLS_KX_DHE_PSK)
              print_dh_info (session, "Ephemeral ", verbose);
          if (kx == GNUTLS_KX_ECDHE_PSK)
              print_ecdh_info (session, "Ephemeral ");
          break;
#endif
      case GNUTLS_CRD_IA:
          printf ("- TLS/IA authentication\n");
          break;
      case GNUTLS_CRD_CERTIFICATE:
          {
              char dns[256];
              size_t dns_size = sizeof (dns);
              unsigned int type;

              /* This fails in client side */
              if (gnutls_server_name_get
                  (session, dns, &dns_size, &type, 0) == 0)
                {
                    printf ("- Given server name[%d]: %s\n", type, dns);
                }
          }

          print_cert_info (session, 
                           verbose?GNUTLS_CRT_PRINT_FULL:GNUTLS_CRT_PRINT_COMPACT, 
                           print_cert);

          if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
              print_dh_info (session, "Ephemeral ", verbose);
          else if (kx == GNUTLS_KX_ECDHE_RSA
                   || kx == GNUTLS_KX_ECDHE_ECDSA)
              print_ecdh_info (session, "Ephemeral ");
      }

    tmp =
        SU (gnutls_protocol_get_name
            (gnutls_protocol_get_version (session)));
    printf ("- Version: %s\n", tmp);

    tmp = SU (gnutls_kx_get_name (kx));
    printf ("- Key Exchange: %s\n", tmp);

    tmp = SU (gnutls_cipher_get_name (gnutls_cipher_get (session)));
    printf ("- Cipher: %s\n", tmp);

    tmp = SU (gnutls_mac_get_name (gnutls_mac_get (session)));
    printf ("- MAC: %s\n", tmp);

    tmp =
        SU (gnutls_compression_get_name
            (gnutls_compression_get (session)));
    printf ("- Compression: %s\n", tmp);

    if (verbose)
      {
          gnutls_datum_t cb;
          int rc;

          rc = gnutls_session_channel_binding (session,
                                               GNUTLS_CB_TLS_UNIQUE, &cb);
          if (rc)
              fprintf (stderr, "Channel binding error: %s\n",
                       gnutls_strerror (rc));
          else
            {
                size_t i;

                printf ("- Channel binding 'tls-unique': ");
                for (i = 0; i < cb.size; i++)
                    printf ("%02x", cb.data[i]);
                printf ("\n");
            }
      }

    /* Warning: Do not print anything more here. The 'Compression:'
       output MUST be the last non-verbose output.  This is used by
       Emacs starttls.el code. */

    fflush (stdout);

    return 0;
}
示例#4
0
int
main (int argc, char **argv)
{
  bool vmem_perfdata = false;
  int c, status, err;
  int shift = k_shift;
  char *critical = NULL, *warning = NULL;
  char *units = NULL;
  char *status_msg;
  char *perfdata_swap_msg, *perfdata_vmem_msg = NULL;
  float percent_used = 0;
  thresholds *my_threshold = NULL;

  struct proc_sysmem *sysmem = NULL;
  unsigned long kb_swap_cached;
  unsigned long kb_swap_free;
  unsigned long kb_swap_total;
  unsigned long kb_swap_used;

  struct proc_vmem *vmem = NULL;
  unsigned long dpswpin, dpswpout;
  unsigned long kb_swap_pageins[2];
  unsigned long kb_swap_pageouts[2];

  set_program_name (argv[0]);

  while ((c = getopt_long (argc, argv, "sc:w:bkmg" GETOPT_HELP_VERSION_STRING,
                           longopts, NULL)) != -1)
    {
      switch (c)
        {
        default:
          usage (stderr);
        case 's':
          vmem_perfdata = true;
          break;
        case 'c':
          critical = optarg;
          break;
        case 'w':
          warning = optarg;
          break;
        case 'b': shift = b_shift; units = xstrdup ("B"); break;
        case 'k': shift = k_shift; units = xstrdup ("kB"); break;
        case 'm': shift = m_shift; units = xstrdup ("MB"); break;
        case 'g': shift = g_shift; units = xstrdup ("GB"); break;

        case_GETOPT_HELP_CHAR
        case_GETOPT_VERSION_CHAR

        }
    }

  status = set_thresholds (&my_threshold, warning, critical);
  if (status == NP_RANGE_UNPARSEABLE)
    usage (stderr);

  /* output in kilobytes by default */
  if (units == NULL)
    units = xstrdup ("kB");

  err = proc_sysmem_new (&sysmem);
  if (err < 0)
    plugin_error (STATE_UNKNOWN, err, "memory exhausted");

  proc_sysmem_read (sysmem);

  kb_swap_cached = proc_sysmem_get_swap_cached (sysmem);
  kb_swap_free = proc_sysmem_get_swap_free (sysmem);
  kb_swap_total = proc_sysmem_get_swap_total (sysmem);
  kb_swap_used = proc_sysmem_get_swap_used (sysmem);

  if (vmem_perfdata)
    {
      err = proc_vmem_new (&vmem);
      if (err < 0)
        plugin_error (STATE_UNKNOWN, err, "memory exhausted");

      proc_vmem_read (vmem);
      kb_swap_pageins[0] = proc_vmem_get_pswpin (vmem);
      kb_swap_pageouts[0] = proc_vmem_get_pswpout (vmem);

      sleep (1);

      proc_vmem_read (vmem);
      kb_swap_pageins[1] = proc_vmem_get_pswpin (vmem);
      kb_swap_pageouts[1] = proc_vmem_get_pswpout (vmem);

      dpswpin = kb_swap_pageins[1] - kb_swap_pageins[0];
      dpswpout = kb_swap_pageouts[1] - kb_swap_pageouts[0];

      perfdata_vmem_msg =
	xasprintf (" swap_pageins/s=%lu swap_pageouts/s=%lu",
		   dpswpin, dpswpout);
    }

  if (kb_swap_total != 0)
    percent_used = (kb_swap_used * 100.0 / kb_swap_total);

  status = get_status (percent_used, my_threshold);
  free (my_threshold);

  status_msg = xasprintf ("%s: %.2f%% (%Lu %s) used", state_text (status),
			  percent_used, SU (kb_swap_used));

  perfdata_swap_msg =
    xasprintf ("swap_total=%Lu%s swap_used=%Lu%s swap_free=%Lu%s "
	       /* The amount of swap, in kB, used as cache memory */
	       "swap_cached=%Lu%s", SU (kb_swap_total), SU (kb_swap_used),
	       SU (kb_swap_free), SU (kb_swap_cached));

  printf ("%s %s | %s%s\n", "SWAP", status_msg, perfdata_swap_msg,
	  vmem_perfdata ? perfdata_vmem_msg : "");

  proc_vmem_unref (vmem);
  proc_sysmem_unref (sysmem);

  return status;
}
int
main (int argc, char **argv)
{
  bool vmem_perfdata = false;
  int c, status, err;
  int shift = k_shift;
  char *critical = NULL, *warning = NULL;
  char *units = NULL;
  char *status_msg, *perfdata_mem_msg,
       *perfdata_vmem_msg = "", *perfdata_memavailable_msg = "";
  float mem_percent = 0;
  thresholds *my_threshold = NULL;

  struct proc_sysmem *sysmem = NULL;
  unsigned long kb_mem_main_available;
  unsigned long kb_mem_main_buffers;
  unsigned long kb_mem_main_cached;
  unsigned long kb_mem_main_free;
  unsigned long kb_mem_main_shared;
  unsigned long kb_mem_main_total;
  unsigned long kb_mem_main_used;
  unsigned long kb_mem_active;
  unsigned long kb_mem_anon_pages;
  unsigned long kb_mem_committed_as;
  unsigned long kb_mem_dirty;
  unsigned long kb_mem_inactive;

  struct proc_vmem *vmem = NULL;
  unsigned long dpgpgin, dpgpgout, dpgmajfault;
  unsigned long nr_vmem_pgpgin[2];
  unsigned long nr_vmem_pgpgout[2];
  unsigned long nr_vmem_pgmajfault[2];

  /* by default we display the memory used */
  unsigned long *kb_mem_monitored = &kb_mem_main_used;

  set_program_name (argv[0]);

  while ((c = getopt_long (argc, argv,
                           "aMSCsc:w:bkmg" GETOPT_HELP_VERSION_STRING,
                           longopts, NULL)) != -1)
    {
      switch (c)
        {
        default:
          usage (stderr);
	case 'a':
	  kb_mem_monitored = &kb_mem_main_available;
          break;
        case 'C':
          /* does nothing, exists for compatibility */
          break;
        case 's':
          vmem_perfdata = true;
          break;
        case 'c':
          critical = optarg;
          break;
        case 'w':
          warning = optarg;
          break;
        case 'b': shift = b_shift; units = xstrdup ("B"); break;
        case 'k': shift = k_shift; units = xstrdup ("kB"); break;
        case 'm': shift = m_shift; units = xstrdup ("MB"); break;
        case 'g': shift = g_shift; units = xstrdup ("GB"); break;

        case_GETOPT_HELP_CHAR
        case_GETOPT_VERSION_CHAR

	}
    }

  status = set_thresholds (&my_threshold, warning, critical);
  if (status == NP_RANGE_UNPARSEABLE)
    usage (stderr);

  /* output in kilobytes by default */
  if (units == NULL)
    units = xstrdup ("kB");

  err = proc_sysmem_new (&sysmem);
  if (err < 0)
    plugin_error (STATE_UNKNOWN, err, "memory exhausted");

  proc_sysmem_read (sysmem);

  kb_mem_active       = proc_sysmem_get_active (sysmem);
  kb_mem_anon_pages   = proc_sysmem_get_anon_pages (sysmem);
  kb_mem_committed_as = proc_sysmem_get_committed_as (sysmem);
  kb_mem_dirty        = proc_sysmem_get_dirty (sysmem);
  kb_mem_inactive     = proc_sysmem_get_inactive (sysmem);
  kb_mem_main_available = proc_sysmem_get_main_available (sysmem);
  kb_mem_main_buffers = proc_sysmem_get_main_buffers (sysmem);
  kb_mem_main_cached  = proc_sysmem_get_main_cached (sysmem);
  kb_mem_main_free    = proc_sysmem_get_main_free (sysmem);
  kb_mem_main_shared  = proc_sysmem_get_main_shared (sysmem);
  kb_mem_main_total   = proc_sysmem_get_main_total (sysmem);
  kb_mem_main_used    = proc_sysmem_get_main_used (sysmem);

  if (vmem_perfdata)
    {
      err = proc_vmem_new (&vmem);
      if (err < 0)
	plugin_error (STATE_UNKNOWN, err, "memory exhausted");

      proc_vmem_read (vmem);
      nr_vmem_pgpgin[0] = proc_vmem_get_pgpgin (vmem);
      nr_vmem_pgpgout[0] = proc_vmem_get_pgpgout (vmem);
      nr_vmem_pgmajfault[0] = proc_vmem_get_pgmajfault (vmem);

      sleep (1);

      proc_vmem_read (vmem);
      nr_vmem_pgpgin[1] = proc_vmem_get_pgpgin (vmem);
      nr_vmem_pgpgout[1] = proc_vmem_get_pgpgout (vmem);
      nr_vmem_pgmajfault[1] = proc_vmem_get_pgmajfault (vmem);

      dpgpgin = nr_vmem_pgpgin[1] - nr_vmem_pgpgin[0];
      dpgpgout = nr_vmem_pgpgout[1] - nr_vmem_pgpgout[0];
      dpgmajfault = nr_vmem_pgmajfault[1] - nr_vmem_pgmajfault[0];

      perfdata_vmem_msg =
	xasprintf (", vmem_pageins/s=%lu, vmem_pageouts/s=%lu, "
		   "vmem_pgmajfault/s=%lu", dpgpgin, dpgpgout, dpgmajfault);
    }

  /* Note: we should perhaps implement the following tests instead: 
   *  1. The Main Memory Test
   *     (MemFree + Buffers + Cached) / MemTotal < threshold
   *  2. The Page Fault Test 
   *     Major pagefaults > threshold 
   *
   * See. http://doc.qt.digia.com/qtextended4.4/syscust-oom.html	*/

  if (kb_mem_main_total != 0)
    mem_percent = ((*kb_mem_monitored) * 100.0 / kb_mem_main_total);
  status = get_status (mem_percent, my_threshold);

  perfdata_memavailable_msg =
    xasprintf ("mem_available=%Lu%s ", SU (kb_mem_main_available));

  status_msg =
    xasprintf ("%s: %.2f%% (%Lu %s) %s",
	       state_text (status), mem_percent, SU (*kb_mem_monitored),
	       (kb_mem_monitored == &kb_mem_main_available) ?
		 "available" : "used");

  free (my_threshold);

  perfdata_mem_msg =
    xasprintf ("mem_total=%Lu%s mem_used=%Lu%s mem_free=%Lu%s "
	       "mem_shared=%Lu%s mem_buffers=%Lu%s mem_cached=%Lu%s %s"
	       "mem_active=%Lu%s mem_anonpages=%Lu%s mem_committed=%Lu%s "
	       "mem_dirty=%Lu%s mem_inactive=%Lu%s"
	       , SU (kb_mem_main_total)
	       , SU (kb_mem_main_used)
	       , SU (kb_mem_main_free)
	       , SU (kb_mem_main_shared)
	       , SU (kb_mem_main_buffers)
	       , SU (kb_mem_main_cached)
	       , perfdata_memavailable_msg
	       , SU (kb_mem_active)
	       , SU (kb_mem_anon_pages)
	       , SU (kb_mem_committed_as)
	       , SU (kb_mem_dirty)
	       , SU (kb_mem_inactive));

  printf ("%s %s | %s%s\n", program_name_short, status_msg,
	  perfdata_mem_msg, perfdata_vmem_msg);

  proc_sysmem_unref (sysmem);
  proc_vmem_unref (vmem);

  return status;
}
示例#6
0
int
print_info (gnutls_session_t session, const char *hostname, int insecure)
{
  const char *tmp;
  gnutls_credentials_type_t cred;
  gnutls_kx_algorithm_t kx;


  /* print the key exchange's algorithm name
   */
  kx = gnutls_kx_get (session);

  cred = gnutls_auth_get_type (session);
  switch (cred)
    {
#ifdef ENABLE_ANON
    case GNUTLS_CRD_ANON:
      print_dh_info (session, "Anonymous ");
      break;
#endif
#ifdef ENABLE_SRP
    case GNUTLS_CRD_SRP:
      /* This should be only called in server
       * side.
       */
      if (gnutls_srp_server_get_username (session) != NULL)
	printf ("- SRP authentication. Connected as '%s'\n",
		gnutls_srp_server_get_username (session));
      break;
#endif
#ifdef ENABLE_PSK
    case GNUTLS_CRD_PSK:
      /* This returns NULL in server side.
       */
      if (gnutls_psk_client_get_hint (session) != NULL)
	printf ("- PSK authentication. PSK hint '%s'\n",
		gnutls_psk_client_get_hint (session));
      /* This returns NULL in client side.
       */
      if (gnutls_psk_server_get_username (session) != NULL)
	printf ("- PSK authentication. Connected as '%s'\n",
		gnutls_psk_server_get_username (session));
      if (kx == GNUTLS_KX_DHE_PSK)
	print_dh_info (session, "Ephemeral ");
      break;
#endif
    case GNUTLS_CRD_IA:
      printf ("- TLS/IA authentication\n");
      break;
    case GNUTLS_CRD_CERTIFICATE:
      {
	char dns[256];
	size_t dns_size = sizeof (dns);
	unsigned int type;

	/* This fails in client side */
	if (gnutls_server_name_get (session, dns, &dns_size, &type, 0) == 0)
	  {
	    printf ("- Given server name[%d]: %s\n", type, dns);
	  }
      }

      if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
	print_dh_info (session, "Ephemeral ");

      print_cert_info (session, hostname, insecure);

      print_cert_vrfy (session);

    }

  tmp = SU (gnutls_protocol_get_name (gnutls_protocol_get_version (session)));
  printf ("- Version: %s\n", tmp);

  tmp = SU (gnutls_kx_get_name (kx));
  printf ("- Key Exchange: %s\n", tmp);

  tmp = SU (gnutls_cipher_get_name (gnutls_cipher_get (session)));
  printf ("- Cipher: %s\n", tmp);

  tmp = SU (gnutls_mac_get_name (gnutls_mac_get (session)));
  printf ("- MAC: %s\n", tmp);

  tmp = SU (gnutls_compression_get_name (gnutls_compression_get (session)));
  printf ("- Compression: %s\n", tmp);

  if (verbose)
    {
      char id[32];
      size_t id_size = sizeof (id);
      gnutls_session_get_id (session, id, &id_size);
      printf ("- Session ID: %s\n", raw_to_string (id, id_size));
    }


  fflush (stdout);

  return 0;
}