Exemplo n.º 1
0
//==============================================================================
static void read_range(const String& input, BoolVector& range,
		uint_t min_value, uint_t max_value)
{
	boost::cmatch what;
	boost::regex exp("(\\d{1,})-(\\d{1,})");

	StringVector list;
	boost::split(list, input, boost::is_any_of(","));

	foreach(const String& item, list)
	{
		uint_t n = 0;
		uint_t r1, r2;
		if (string_to_number(item, n))
			r1 = r2 = n;
		else
		{
			if (!boost::regex_match(item.c_str(), what, exp))
				throw std::runtime_error("read_range: incorrect input");
			string_to_number(what[1].str(), r1);
			string_to_number(what[2].str(), r2);
			if (r1 > r2)
				std::swap(r1, r2);
		}
		if (r2 > max_value || r1 < min_value)
			throw std::runtime_error("read_range: value is out of range");

		if (range.size() <= r2)
			range.resize(r2 + 1, false);
		for (; r1 <= r2; r1++)
			range[r1] = true;
	}
Exemplo n.º 2
0
void removeInvalidMeans(
  const Vector3fVector& means,
  const BoolVector& valid,
  Vector3fVector& means_f)
{
  unsigned int size = valid.size(); 
  for(unsigned int i = 0; i < size; ++i)
  {
    if (valid[i])
    {
      const Vector3f& mean = means[i];
      means_f.push_back(mean);
    }
  }
}
Exemplo n.º 3
0
void removeInvalidDistributions(
  const Vector3fVector& means,
  const Matrix3fVector& covariances,
  const BoolVector& valid,
  Vector3fVector& means_f,
  Matrix3fVector& covariances_f)
{
  unsigned int size = valid.size(); 
  for(unsigned int i = 0; i < size; ++i)
  {
    if (valid[i])
    {
      const Vector3f& mean = means[i];
      const Matrix3f& cov  = covariances[i];

      means_f.push_back(mean);
      covariances_f.push_back(cov);
    }
  }
}
Exemplo n.º 4
0
void ADFun<Base>::for_hes_sparsity(
	const BoolVector&            select_domain    ,
	const BoolVector&            select_range     ,
	bool                         internal_bool    ,
	sparse_rc<SizeVector>&       pattern_out      )
{	size_t n  = Domain();
	size_t m  = Range();
	//
	CPPAD_ASSERT_KNOWN(
		size_t( select_domain.size() ) == n,
		"for_hes_sparsity: size of select_domain is not equal to "
		"number of independent variables"
	);
	CPPAD_ASSERT_KNOWN(
		size_t( select_range.size() ) == m,
		"for_hes_sparsity: size of select_range is not equal to "
		"number of dependent variables"
	);
	// do not need transpose or depenency
	bool transpose  = false;
	bool dependency = false;
	//
	sparse_rc<SizeVector> pattern_tmp;
	if( internal_bool )
	{	// forward Jacobian sparsity pattern for independent variables
		local::sparse_pack internal_for_jac;
		internal_for_jac.resize(num_var_tape_, n + 1 );
		for(size_t j = 0; j < n; j++) if( select_domain[j] )
		{	CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < n + 1 );
			internal_for_jac.add_element( ind_taddr_[j] , ind_taddr_[j] );
		}
		// forward Jacobian sparsity for all variables on tape
		local::ForJacSweep(
			dependency,
			n,
			num_var_tape_,
			&play_,
			internal_for_jac
		);
		// reverse Jacobian sparsity pattern for select_range
		local::sparse_pack internal_rev_jac;
		internal_rev_jac.resize(num_var_tape_, 1);
		for(size_t i = 0; i < m; i++) if( select_range[i] )
		{	CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
			internal_rev_jac.add_element( dep_taddr_[i] , 0 );
		}
		// reverse Jacobian sparsity for all variables on tape
		local::RevJacSweep(
			dependency,
			n,
			num_var_tape_,
			&play_,
			internal_rev_jac
		);
		// internal vector of sets that will hold Hessian
		local::sparse_pack internal_for_hes;
		internal_for_hes.resize(n + 1, n + 1);
		//
		// compute forward Hessian sparsity pattern
		local::ForHesSweep(
			n,
			num_var_tape_,
			&play_,
			internal_for_jac,
			internal_rev_jac,
			internal_for_hes
		);
		//
		// put the result in pattern_tmp
		get_internal_sparsity(
			transpose, ind_taddr_, internal_for_hes, pattern_tmp
		);
	}
	else
	{	// forward Jacobian sparsity pattern for independent variables
		// (corresponds to D)
		local::sparse_list internal_for_jac;
		internal_for_jac.resize(num_var_tape_, n + 1 );
		for(size_t j = 0; j < n; j++) if( select_domain[j] )
		{	CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < n + 1 );
			internal_for_jac.add_element( ind_taddr_[j] , ind_taddr_[j] );
		}
		// forward Jacobian sparsity for all variables on tape
		local::ForJacSweep(
			dependency,
			n,
			num_var_tape_,
			&play_,
			internal_for_jac
		);
		// reverse Jacobian sparsity pattern for select_range
		// (corresponds to s)
		local::sparse_list internal_rev_jac;
		internal_rev_jac.resize(num_var_tape_, 1);
		for(size_t i = 0; i < m; i++) if( select_range[i] )
		{	CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
			internal_rev_jac.add_element( dep_taddr_[i] , 0 );
		}
		// reverse Jacobian sparsity for all variables on tape
		local::RevJacSweep(
			dependency,
			n,
			num_var_tape_,
			&play_,
			internal_rev_jac
		);
		// internal vector of sets that will hold Hessian
		local::sparse_list internal_for_hes;
		internal_for_hes.resize(n + 1, n + 1);
		//
		// compute forward Hessian sparsity pattern
		local::ForHesSweep(
			n,
			num_var_tape_,
			&play_,
			internal_for_jac,
			internal_rev_jac,
			internal_for_hes
		);
		//
		// put the result in pattern_tmp
		get_internal_sparsity(
			transpose, ind_taddr_, internal_for_hes, pattern_tmp
		);
	}
	// subtract 1 from all column values
	CPPAD_ASSERT_UNKNOWN( pattern_tmp.nr() == n );
	CPPAD_ASSERT_UNKNOWN( pattern_tmp.nc() == n + 1 );
	const SizeVector& row( pattern_tmp.row() );
	const SizeVector& col( pattern_tmp.col() );
	size_t nr   = n;
	size_t nc   = n;
	size_t nnz  = pattern_tmp.nnz();
	pattern_out.resize(nr, nc, nnz);
	for(size_t k = 0; k < nnz; k++)
	{	CPPAD_ASSERT_UNKNOWN( 0 < col[k] );
		pattern_out.set(k, row[k], col[k] - 1);
	}
	return;
}