Exemplo n.º 1
0
	int operator()(const InputType &x, ValueType& fvec) const {
		m_decoder.Decode(m_rots, x);

		Vector3 v = sik.endPosition(m_rots);
		v -= m_goal;
		fvec.setZero();
		fvec.head<3>() = Eigen::Vector3f::Map(&v.x);

		// limit-exceed panelaty
		auto limpanl = fvec.tail(x.size());
		for (int i = 0; i < x.size(); i++)
		{
			if (x[i] < m_min[i])
				limpanl[i] = m_limitPanalty*(x[i] - m_min[i])*(x[i] - m_min[i]);
			else if (x[i] > m_max[i])
				limpanl[i] = m_limitPanalty*(x[i] - m_max[i])*(x[i] - m_max[i]);
		}

		if (m_useRef)
		{
			limpanl += m_refWeights *(x - m_ref);
		}

		return 0;
	}
Exemplo n.º 2
0
	int df(const InputType &x, JacobianType& fjac) {
		m_decoder.Decode(m_rots, x);

		fjac.setZero();

		m_jacb.resize(3, 3 * n);
		sik.endPositionJaccobiRespectEuler(m_rots, 
			array_view<Vector3>(reinterpret_cast<Vector3*>(m_jacb.data()),3*n));

		m_decoder.EncodeJacobi(m_rots, m_jacb);

		fjac.topRows<3>() = m_jacb;//Eigen::Matrix3Xf::Map(&m_jac[0].x, 3, 3 * n);

		// limit-exceed panelaty
		for (int i = 0; i < x.size(); i++)
		{
			if (x[i] < m_min[i])
				fjac(3 + i, i) = m_limitPanalty * (x[i] - m_min[i]);
			else if (x[i] > m_max[i])
				fjac(3 + i, i) = m_limitPanalty * (x[i] - m_max[i]);

			if (m_useRef)
			{
				fjac(3 + i, i) += m_refWeights;
			}
		}

		return 0;
	}
Exemplo n.º 3
0
 void num_diff(const boost::function<OutputType (const InputType& )>& f
             , const InputType& cur // current point
             , int m // output dimension
             , double epsilon
             , MatType* out
              ) {
   assert (out != nullptr);
   int n = cur.size();
   InputType x = cur;
   out->resize(m, n);
   for (int i = 0; i < n; ++i) {
     x(i) = cur(i) + epsilon;
     OutputType fplus = f(x);
     x(i) = cur(i) - epsilon;
     OutputType fminus = f(x);
     out->col(i) = (fplus - fminus) / (2 * epsilon);
     x(i) = cur(i);
   }
 }
std::vector<std::vector<int>> GetCombinationsIterative(const std::vector<int>& input)
{
	typedef std::vector<std::vector<int>> ResultType;
	typedef std::vector<int> InputType;
	typedef std::vector<std::tuple<int, InputType>> ProblemType;
	typedef std::map<int, ProblemType> ProblemListType;
	typedef std::queue<InputType> LevelResultsType;

	ResultType result;
	
	ProblemListType problemTree;

	int currentLevel = input.size();
	int startLevel = currentLevel;
	problemTree[currentLevel] = ProblemType
	{ 
		std::tuple<int, InputType> {0, input}
	};
	InputType temp = input;
	int nodeNr = 1;
	while (currentLevel > 2)
	{
		problemTree[currentLevel - 1] = ProblemType{};
		const auto& nodes = problemTree[currentLevel];
		for (const auto& node : nodes)
		{
			temp = std::get<1>(node);
			for (const auto& element : temp)
			{
				std::vector<int> diffSet = temp;
				diffSet.erase(std::find(diffSet.begin(), diffSet.end(), element));
				problemTree[currentLevel - 1].push_back(std::make_tuple(element, diffSet));
			}
		}
		currentLevel = currentLevel - 1;
	}

	LevelResultsType resultsCurrentLevel;
	LevelResultsType resultsPreviousLevel;
	
	while (currentLevel < startLevel)
	{
		resultsCurrentLevel = {};
		const auto& nodes = problemTree[currentLevel];
		int partitionSize = currentLevel == 2 ? 2 : resultsPreviousLevel.size() / nodes.size();
		for (const auto& node : nodes)
		{
			temp = std::get<1>(node);
			if (temp.size() == 2)
			{
				resultsPreviousLevel.push({ temp[0], temp[1] });
				resultsPreviousLevel.push({ temp[1], temp[0] });
			}
			for (int i = 0; i < partitionSize ; ++i)
			{
				auto& previousLevelResult = resultsPreviousLevel.front();
				previousLevelResult.insert(previousLevelResult.begin(), std::get<0>(node));
				resultsCurrentLevel.push(resultsPreviousLevel.front());
				resultsPreviousLevel.pop();
			}
		}
		resultsPreviousLevel = resultsCurrentLevel;
		++currentLevel;
	}

	while (!resultsCurrentLevel.empty())
	{
		result.push_back(resultsCurrentLevel.front());
		resultsCurrentLevel.pop();
	}

	return result;
}
void mitk::GroupDiffusionHeadersFilter::Update()
{
  InputType input =  static_cast<InputType>( this->GetInput( ) );
  this->SetNthOutput(0, input);

  InputType dwi;
  InputType zerodwi;
  InputType other;

  bool foundDWI = false;

  // check each series' first image
  unsigned int size = input.size();
  HeaderPointer header;
  HeaderPointer dwiHeader;
  for ( unsigned int i = 0 ; i < size ; ++i )
  {
    header = input[i];

    // list of files
    if( header->bValue > 0)
    {
      header->headerGroup = DHG_NonZeroDiffusionWeighted;
      if(!foundDWI)
        dwiHeader = header;
      foundDWI = true;
    }
    else
    {
      header->headerGroup = DHG_ZeroDiffusionWeighted;
    }
  }

  if(foundDWI)
  {
    for ( unsigned int i = 0 ; i < size ; ++i )
    {
      header = input[i];

      // list of files
      if( !header->isIdentical(dwiHeader))
      {
        header->headerGroup = DHG_Other;
      }
    }
  }
  else
  {
    for ( unsigned int i = 0 ; i < size ; ++i )
    {
      header = input[i];
      header->headerGroup = DHG_Other;
    }
  }

  for ( unsigned int i = 0 ; i < size ; ++i )
  {
    header = input[i];
    
    switch (header->headerGroup)
    {
    case DHG_Other:
      other.push_back(header);
      break;
    case DHG_ZeroDiffusionWeighted:
      zerodwi.push_back(header);
      break;
    case DHG_NonZeroDiffusionWeighted:
      dwi.push_back(header);
      break;
    case DHG_NotYetGrouped:
      break;
    }
  }

  this->SetNthOutput(1, dwi);
  this->SetNthOutput(2, zerodwi);
  this->SetNthOutput(3, other);

}