示例#1
0
static void
tracker_extract_finalize (GObject *object)
{
	TrackerExtractPrivate *priv;

	priv = TRACKER_EXTRACT_GET_PRIVATE (object);

	/* FIXME: Shutdown modules? */

	g_hash_table_destroy (priv->single_thread_extractors);
	g_thread_pool_free (priv->thread_pool, TRUE, FALSE);

	if (!priv->disable_summary_on_finalize) {
		report_statistics (object);
	}

#ifdef HAVE_LIBSTREAMANALYZER
	tracker_topanalyzer_shutdown ();
#endif /* HAVE_STREAMANALYZER */

	g_hash_table_destroy (priv->statistics_data);

	g_mutex_clear (&priv->task_mutex);

	G_OBJECT_CLASS (tracker_extract_parent_class)->finalize (object);
}
示例#2
0
int main() {
  bool error = false;

  std::chrono::seconds seconds(std::chrono::seconds::zero());
  {
    smt::NonReentrantTimer<std::chrono::seconds> timer(seconds);

    do {
      // global array ought to be initially nondeterministic
      crv::make_any(aux);
  
      crv_main();
  
      error |= smt::sat == dfs_checker().check();
    } while (dfs_checker().find_next_path() && !error);
  }

  if (error)
    std::cout << "Found bug!" << std::endl;
  else
    std::cout << "Could not find any bugs." << std::endl;

  report_statistics(dfs_checker().solver().stats(), dfs_checker().stats(), seconds);

  return error;
}
示例#3
0
int main() {
  bool error = false;

  std::chrono::seconds seconds(std::chrono::seconds::zero());
  {
    smt::NonReentrantTimer<std::chrono::seconds> timer(seconds);

    do {
      crv_main();
  
#ifndef FORCE_BRANCH
      error |= smt::sat == dfs_checker().check();
#endif
    } while (dfs_checker().find_next_path() && !error);
  }

  if (error)
    std::cout << "Found bug!" << std::endl;
  else
    std::cout << "Could not find any bugs." << std::endl;

  report_statistics(dfs_checker().solver().stats(), dfs_checker().stats(), seconds);

  return error;
}
示例#4
0
path_searcht::resultt path_searcht::operator()(
  const goto_functionst &goto_functions)
{
#ifdef PATH_SYMEX_FORK
  // Disable output because there is no meaningful way
  // to write text when multiple path_search processes
  // run concurrently. This could be remedied by piping
  // to individual files or inter-process communication,
  // a performance bottleneck, however.
  *messaget::mstream.message_handler=NULL;
#endif

  locst locs(ns);
  var_mapt var_map(ns);
  
  locs.build(goto_functions);

  // this is the container for the history-forest  
  path_symex_historyt history;
  
  queue.push_back(initial_state(var_map, locs, history));
  
  // set up the statistics
  number_of_paths=0;
  number_of_instructions=0;
  number_of_dropped_states=0;
  number_of_VCCs=0;
  number_of_VCCs_after_simplification=0;
  number_of_failed_properties=0;
  number_of_fast_forward_steps=0;

  // stop the time
  start_time=current_time();
  
  initialize_property_map(goto_functions);
  
  while(!queue.empty())
  {
    // Pick a state from the queue,
    // according to some heuristic.
    queuet::iterator state=pick_state();

    // fast forwarding required?
    if(state->is_lazy())
    {
      assert(state->is_executable());
      assert(state->history.is_nil());

      // keep allocated memory, this is faster than
      // instantiating a new empty vector and map
      history.clear();
      var_map.clear();
      state->history=path_symex_step_reft(history);

      // restore all fields of a lazy state by symbolic
      // execution along previously recorded branches
      const queuet::size_type queue_size=queue.size();
      do
      {
        number_of_fast_forward_steps++;

        path_symex(*state, queue);
#ifdef PATH_SYMEX_OUTPUT
        status() << "Fast forward thread " << state->get_current_thread()
                 << "/" << state->threads.size()
                 << " PC " << state->pc() << messaget::eom;
#endif
      }
      while(state->is_lazy() && state->is_executable());
      assert(queue.size() == queue_size);
    }
    
    // TODO: check lazy states before fast forwarding, or perhaps it
    // is better to even check before inserting into queue
    if(drop_state(*state))
    {
      number_of_dropped_states++;
      queue.erase(state);
      continue;
    }
    
    if(!state->is_executable())
    {
      queue.erase(state);
      continue;
    }
    
    // count only executable instructions
    number_of_instructions++;

#ifdef PATH_SYMEX_OUTPUT
    status() << "Queue " << queue.size()
             << " thread " << state->get_current_thread()
             << "/" << state->threads.size()
             << " PC " << state->pc() << messaget::eom;
#endif

    // an error, possibly?
    if(state->get_instruction()->is_assert())
    {
      if(show_vcc)
        do_show_vcc(*state, ns);
      else
      {
        check_assertion(*state, ns);
        
        // all assertions failed?
        if(number_of_failed_properties==property_map.size())
          break;
      }
    }

#ifdef PATH_SYMEX_FORK
    if(try_await())
    {
      debug() << "Child process has terminated "
                 "so exit parent" << messaget::eom;
      break;
    }
#endif

    // execute and record whether a "branch" occurred
    const queuet::size_type queue_size = queue.size();
    path_symex(*state, queue);

    assert(queue_size <= queue.size());
    number_of_paths += (queue.size() - queue_size);
  }

#ifdef PATH_SYMEX_FORK
  int exit_status=await();
  if(exit_status==0 && number_of_failed_properties!=0)
  {
    // the eldest child process (if any) reports found bugs
    report_statistics();
    return UNSAFE;
  }
  else
  {
    // either a child found and reported a bug or
    // the parent's search partition is safe
    switch (exit_status)
    {
    case 0: return SAFE;
    case 10: return UNSAFE;
    default: return ERROR;
    }
  }
#else
  report_statistics();

  return number_of_failed_properties==0?SAFE:UNSAFE;
#endif
}
int LbfgsbOptimizer::solve()
{
    // Solution vector
    ap::real_1d_array x0;
    x0.setbounds(1, x.dim);

    // copy current x into x0
    for(size_t i = 0; i < x.dim; i++)
    {
        x0(i+1) = x.val[i];
    }

    ap::integer_1d_array nbd;
    ap::real_1d_array l;
    ap::real_1d_array u;
    nbd.setbounds(1, x.dim);
    l.setbounds(1, x.dim);
    u.setbounds(1, x.dim);

    // Set bounds
    if(binary)
    {
        bounds_binary(nbd, l, u);
    }
    else
    {
        bounds(nbd, l, u);
    }

    // Lancelot: gamma_bar = 0.1
    double gamma_bar = 0.1; // < 1 :

    // Lancelot: tau = 0.1
    double tau = 0.1; // # < 1

    // Lancelot: alpha_eta = 0.1
    double alpha_eta = 0.01; // # min(1, self._alpha_omega)

    //Lancelot: beta_eta = 0.9
    double beta_eta = 0.9; // # min(1, self._beta_omega)

    //Lancelot: alpha_omega = 1.0
    double alpha_omega = 4.0;

    //Lancelot: beta_omega = 1.0
    double beta_omega = 4.0;

    // Lancelot: omega_bar = firtsg/pow(std::min(mu, gamma_bar), alpha_omega);
    double omega_bar = 0.5;

    // Lancelot: eta_bar = firtsc/pow(std::min(mu, gamma_bar), alpha_eta);
    double eta_bar = 1.0;

    double mu_bar = 0.9; // must be <= 1

    mu = mu_bar;

    // Lancelot: alpha  = min(mu, gamma_bar)
    double alpha = std::min(mu, gamma_bar);

    // Lancelot: eta = max(etamin, eta_bar*pow(alpha, alpha_eta))
    // svnvish: BUGBUG what is etamin?
    // etamin is the minimum norm of the constraint violation
    double eta = eta_bar*pow(alpha, alpha_eta);

    // Lancelot: omega = max(omemin, omega_bar*pow(alpha, alpha_omega))
    // svnvish: BUGBUG what is omemin?
    // omemin is the tolerance for kkt gap
    double omega = omega_bar*pow(alpha, alpha_omega);

    DenseVector W;
    W.val = x.val;
    W.dim = num_weak_learners;

    for(size_t iteration = 0; iteration < LBFGSB::max_iterations; iteration++)
    {
        double epsg = omega;
        double epsf = 0;
        double epsx = 0;
        int info;

        lbfgsbminimize(x.dim,
                       std::min(x.dim, LBFGSB::lbfgsb_m),
                       x0,
                       epsg,
                       epsf,
                       epsx,
                       LBFGSB::lbfgsb_max_iterations,
                       nbd,
                       l,
                       u,
                       (void*) this,
                       info);

        // copy current solution into x
        for(size_t i = 0; i < x.dim; i++)
        {
            x.val[i] = x0(i+1);
        }

        const double w_gap = sum(W) - 1.0;

        // std::cout << "info: " << info << std::endl;
        // assert(info > 0);
        assert(info == 4);

        if(std::abs(w_gap) < eta)
        {

            if(std::abs(w_gap) < Optimizer::wt_sum_tol)
            {

                if(duality_gap_met())
                {
                    // // svnvish: BUGBUG
                    // // Extra gradient computation happening here
                    // // Better to use norm gaps
                    // dvec gradk = grad();

                    // if(converged(grad())){
                    report_statistics();
                    break;
                }
            }

            lambda = lambda - (w_gap/mu);
            //mu = mu;
            alpha = mu;
            eta = eta*pow(alpha, beta_eta);
            omega = omega*pow(alpha, beta_omega);

        }
        else
        {
            //lambda = lambda;
            mu *= tau;
            alpha = mu*gamma_bar;
            eta = eta_bar*pow(alpha, beta_eta);
            omega = omega_bar*pow(alpha, beta_omega);
        }

    } // end of "for each iteration"

    // This is not a memory leak!
    W.val = NULL;
    W.dim = 0;

    return 0;
} // end of LbfgsbOptimizer::solve()
示例#6
0
文件: multiPCav.c 项目: oneminot/wsp
void *Consume (void *arg)
/* Consumer thread function. */
{
	msg_block_t *pmb;
	statistics_t * ps;
	int my_number, tstatus;
	struct timespec timeout, delta;
	
	delta.tv_sec = 2;
	delta.tv_nsec = 0;
		
	/* Create thread-specific storage key */
	tstatus = pthread_once (&once_control, once_init_function);
	if (tstatus != 0) err_abort (tstatus, "One time init failed");

	pmb = (msg_block_t *)arg;

	/* Allocate storage for thread-specific statistics */
	ps = calloc (sizeof(statistics_t), 1);
	if (ps == NULL) errno_abort ("Cannot allocate memory");
	tstatus = pthread_setspecific (ts_key, ps);
	if (tstatus != 0) err_abort (tstatus, "Error setting ts storage");
	ps->pmblock = pmb;
	/* Give this thread a unique number */
	/* Note that the mutex is "overloaded" to protect data	*/
	/* outside the message block structure			*/
	tstatus = pthread_mutex_lock (&pmb->nGuard);
	if (tstatus != 0) err_abort (tstatus, "Lock error");
	ps->th_number = thread_number++;
	tstatus = pthread_mutex_unlock (&pmb->nGuard);
	if (tstatus != 0) err_abort (tstatus, "Unlock error");
	
	/* Consume the NEXT message when prompted by the user */
	while (!pmb->fStop) { /* This is the only thread accessing stdin, stdout */
		tstatus = pthread_mutex_lock (&pmb->nGuard);
		if (tstatus != 0) err_abort (tstatus, "Lock error");
		/* Get the next message. Use a timed wait so as to be able	*/
		/* to sample the stop flag peridically.				*/
		do { 
			pthread_get_expiration_np (&delta, &timeout);
			tstatus = pthread_cond_timedwait 
				(&pmb->mReady, &pmb->nGuard, &timeout);
			if (tstatus != 0 && tstatus != ETIMEDOUT) 
				err_abort (tstatus, "CV wait error");
		} while (!pmb->f_ready && !pmb->fStop);
		if (!pmb->fStop) {
/*			printf ("Message received\n"); */
			accumulate_statistics ();
			pmb->f_consumed = 1;
			pmb->f_ready = 0;
		}
		tstatus = pthread_cond_signal (&pmb->mconsumed);
		if (tstatus != 0) err_abort (tstatus, "Signal error");
		tstatus = pthread_mutex_unlock (&pmb->nGuard);
		if (tstatus != 0) err_abort (tstatus, "Unlock error");
	}
	
	/* Shutdown. Report the statistics */
	tstatus = pthread_mutex_lock (&pmb->nGuard);
	if (tstatus != 0) err_abort (tstatus, "Lock error");
	report_statistics ();	
	tstatus = pthread_mutex_unlock (&pmb->nGuard);
	if (tstatus != 0) err_abort (tstatus, "Unlock error");

	/* Terminate the consumer thread. The destructor will 	*/
	/* free the memory allocated for the statistics		*/
	return NULL;		
}
示例#7
0
path_searcht::resultt path_searcht::operator()(
  const goto_functionst &goto_functions)
{
  locst locs(ns);
  var_mapt var_map(ns);
  
  locs.build(goto_functions);

  // this is the container for the history-forest  
  path_symex_historyt history;
  
  queue.push_back(initial_state(var_map, locs, history));
  
  // set up the statistics
  number_of_dropped_states=0;
  number_of_paths=0;
  number_of_VCCs=0;
  number_of_steps=0;
  number_of_feasible_paths=0;
  number_of_infeasible_paths=0;
  number_of_VCCs_after_simplification=0;
  number_of_failed_properties=0;
  number_of_locs=locs.size();

  // stop the time
  start_time=current_time();
  
  initialize_property_map(goto_functions);
  
  while(!queue.empty())
  {
    number_of_steps++;
  
    // Pick a state from the queue,
    // according to some heuristic.
    // The state moves to the head of the queue.
    pick_state();
    
    // move into temporary queue
    queuet tmp_queue;
    tmp_queue.splice(
      tmp_queue.begin(), queue, queue.begin(), ++queue.begin());
    
    try
    {
      statet &state=tmp_queue.front();
      
      // record we have seen it
      loc_data[state.get_pc().loc_number].visited=true;

      debug() << "Loc: #" << state.get_pc().loc_number
              << ", queue: " << queue.size()
              << ", depth: " << state.get_depth();
      for(const auto & s : queue)
        debug() << ' ' << s.get_depth();
        
      debug() << eom;
    
      if(drop_state(state))
      {
        number_of_dropped_states++;
        number_of_paths++;
        continue;
      }
      
      if(!state.is_executable())
      {
        number_of_paths++;
        continue;
      }

      if(eager_infeasibility &&
         state.last_was_branch() &&
         !is_feasible(state))
      {
        number_of_infeasible_paths++;
        number_of_paths++;
        continue;
      }
      
      if(number_of_steps%1000==0)
      {
        status() << "Queue " << queue.size()
                 << " thread " << state.get_current_thread()
                 << '/' << state.threads.size()
                 << " PC " << state.pc() << messaget::eom;
      }

      // an error, possibly?
      if(state.get_instruction()->is_assert())
      {
        if(show_vcc)
          do_show_vcc(state);
        else
        {
          check_assertion(state);
          
          // all assertions failed?
          if(number_of_failed_properties==property_map.size())
            break;
        }
      }

      // execute
      path_symex(state, tmp_queue);
      
      // put at head of main queue
      queue.splice(queue.begin(), tmp_queue);
    }
    catch(const std::string &e)
    {
      error() << e << eom;
      number_of_dropped_states++;
    }
    catch(const char *e)
    {
      error() << e << eom;
      number_of_dropped_states++;
    }
    catch(int)
    {
      number_of_dropped_states++;
    }
  }
  
  report_statistics();
  
  return number_of_failed_properties==0?SAFE:UNSAFE;
}
示例#8
0
void measure_difference(ghog::lib::HogDescriptor* hog1,
	ghog::lib::HogDescriptor* hog2,
	std::string hog_name1,
	std::string hog_name2,
	std::vector< std::string > image_list,
	cv::Size img_size,
	cv::Size window_size,
	int num_experiments,
	boost::random::mt19937 random_gen)
{
	std::cout << "Running difference experiment on descriptors " << hog_name1
		<< " and " << hog_name2 << ", with " << image_list.size()
		<< " images, using " << num_experiments << " windows of size "
		<< window_size << std::endl;

	cv::Size descriptor_size(hog1->get_descriptor_size(), 1);

	cv::Mat input_img1;
	cv::Mat normalized_img1;
	cv::Mat grad_mag1;
	cv::Mat grad_phase1;
	cv::Mat descriptor1;

	hog1->alloc_buffer(img_size, CV_32FC3, input_img1);
	hog1->alloc_buffer(window_size, CV_32FC3, normalized_img1);
	hog1->alloc_buffer(window_size, CV_32FC1, grad_mag1);
	hog1->alloc_buffer(window_size, CV_32FC1, grad_phase1);
	hog1->alloc_buffer(descriptor_size, CV_32FC1, descriptor1);

	cv::Mat input_img2;
	cv::Mat normalized_img2;
	cv::Mat grad_mag2;
	cv::Mat grad_phase2;
	cv::Mat descriptor2;

	hog2->alloc_buffer(img_size, CV_32FC3, input_img2);
	hog2->alloc_buffer(window_size, CV_32FC3, normalized_img2);
	hog2->alloc_buffer(window_size, CV_32FC1, grad_mag2);
	hog2->alloc_buffer(window_size, CV_32FC1, grad_phase2);
	hog2->alloc_buffer(descriptor_size, CV_32FC1, descriptor2);

	boost::random::uniform_smallint< int > dist_w(1,
		input_img1.cols - window_size.width - 2);
	boost::random::uniform_smallint< int > dist_h(1,
		input_img1.rows - window_size.height - 2);

	std::vector< double > errors_normalization;
	std::vector< double > magnitude_similarity;
	std::vector< double > phase_similarity;
	std::vector< double > descriptor_similarity;
	std::vector< double > total_similarity;

	std::cout << "Calculating partial difference" << std::endl;

	for(int i = 0; i < image_list.size(); ++i)
	{
		cv::imread(image_list[i], CV_LOAD_IMAGE_COLOR).convertTo(input_img1,
			CV_32FC3);
		cv::imread(image_list[i], CV_LOAD_IMAGE_COLOR).convertTo(input_img2,
			CV_32FC3);
		input_img1 /= 256.0;
		input_img2 /= 256.0;

		for(int j = 0; j < num_experiments; ++j)
		{
			int pos_x = dist_w(random_gen);
			int pos_y = dist_h(random_gen);

			input_img1.rowRange(pos_y, pos_y + window_size.height).colRange(
				pos_x, pos_x + window_size.width).copyTo(normalized_img1);
			input_img2.rowRange(pos_y, pos_y + window_size.height).colRange(
				pos_x, pos_x + window_size.width).copyTo(normalized_img2);

			hog1->image_normalization_sync(normalized_img1);
			hog2->image_normalization_sync(normalized_img2);
			errors_normalization.push_back(
				compare_matrices(normalized_img1, normalized_img2));

			normalized_img1.copyTo(normalized_img2);

			hog1->calc_gradient_sync(normalized_img1, grad_mag1, grad_phase1);
			hog2->calc_gradient_sync(normalized_img2, grad_mag2, grad_phase2);
			magnitude_similarity.push_back(
				compare_matrices(grad_mag1, grad_mag2));
			phase_similarity.push_back(
				compare_matrices(grad_phase1, grad_phase2));

			grad_mag1.copyTo(grad_mag2);
			grad_phase1.copyTo(grad_phase2);

			hog1->create_descriptor_sync(grad_mag1, grad_phase1, descriptor1);
			hog2->create_descriptor_sync(grad_mag2, grad_phase2, descriptor2);

			descriptor_similarity.push_back(
				compare_matrices(descriptor1, descriptor2));
		}
	}

	std::cout << "Error on image normalization:" << std::endl;
	report_statistics(errors_normalization, 1, "normalized euclidian distance");
	std::cout << "Error on magnitude calculation:" << std::endl;
	report_statistics(magnitude_similarity, 1, "normalized euclidian distance");
	std::cout << "Error on phase calculation:" << std::endl;
	report_statistics(phase_similarity, 1, "normalized euclidian distance");
	std::cout << "Error on descriptor calculation:" << std::endl;
	report_statistics(descriptor_similarity, 1,
		"normalized euclidian distance");

	std::cout << "Calculating complete difference" << std::endl;

	for(int i = 0; i < image_list.size(); ++i)
	{
		cv::imread(image_list[i], CV_LOAD_IMAGE_COLOR).convertTo(input_img1,
			CV_32FC3);
		cv::imread(image_list[i], CV_LOAD_IMAGE_COLOR).convertTo(input_img2,
			CV_32FC3);
		input_img1 /= 256.0;
		input_img2 /= 256.0;

		for(int j = 0; j < num_experiments; ++j)
		{
			int pos_x = dist_w(random_gen);
			int pos_y = dist_h(random_gen);

			input_img1.rowRange(pos_y, pos_y + window_size.height).colRange(
				pos_x, pos_x + window_size.width).copyTo(normalized_img1);
			input_img2.rowRange(pos_y, pos_y + window_size.height).colRange(
				pos_x, pos_x + window_size.width).copyTo(normalized_img2);

			hog1->image_normalization_sync(input_img1);
			hog1->calc_gradient_sync(normalized_img1, grad_mag1, grad_phase1);
			hog1->create_descriptor_sync(grad_mag1, grad_phase1, descriptor1);

			hog2->image_normalization_sync(input_img2);
			hog2->calc_gradient_sync(normalized_img2, grad_mag2, grad_phase2);
			hog2->create_descriptor_sync(grad_mag2, grad_phase2, descriptor2);

			total_similarity.push_back(
				compare_matrices(descriptor1, descriptor2));
		}
	}

	std::cout << "Total similarity :" << std::endl;
	report_statistics(total_similarity, 1, "normalized euclidian distance");
	std::cout << std::endl;
}