Esempio n. 1
0
MatrixXd MinEnFilter::integratePImplicit(const LieAlgebra & grad, const MatrixXd & Hessian) {
	
	const double eps = 1e-8;
	int dim = order * 6;
	
	MatrixXd A(dim,dim);
	MatrixXd D = MatrixXd::Zero(dim,dim);
	MatrixXd Gamma = MatrixXd::Zero(dim,dim);
	MatrixXd Id = MatrixXd::Identity(dim,dim);
	LieAlgebra FG;
	MatrixXd B(6,6);
	MatrixXd C = invW;

	// define function that applies a function to each row of a matrix
	if (order == 1) {
		A = -tildeGammaAst(grad.E);
// 		cout << "\n\n Matrix A: \n\n" << A << endl;
// 		cout << "\n\n tildeGamma(grad.E): \n\n" << tildeGamma(grad.E) << endl;
		D = (tildeGamma(grad.E) + Hessian);
// 		cout << "\n\n Matrix D: \n\n" << D << endl;
	} else if ( order>=2 ) {
		Gamma.topLeftCorner(6,6) = tildeGammaAst(grad.E);
		FG = MotionPrior(currG);
		B = MEFcommon::adjoint(FG.E); // kronSE(FG.e.mat, eye(4)) - kronSE(eye(4),FG.e.mat);
		A.topLeftCorner(6,6) = -B;
		A.block(0, 5, dim-6 ,dim-6) = MatrixXd::Identity(dim-6,dim-6);
		A = A-Gamma;
		D.topLeftCorner(6,6) = tildeGamma(grad.E) + Hessian;
	} else {
		cerr << "Parameter order must be positive" << endl;
		exit(1);
	}

	D = 0.5 * (D + D.transpose());
	MatrixXd tildeQ = currP + delta * C;
	MatrixXd tildeA = (delta * A - (1+delta*alpha)/2 * Id).transpose();
	
	Eigen::LLT<MatrixXd> lltOfD(D);
	MatrixXd cholD = lltOfD.matrixL();
	MatrixXd tildeB = sqrt(delta)*cholD;

   // solve algebraic Riccati equation to find solution of implicit Euler scheme, i.e.
   return care(tildeA, tildeB, tildeQ); 

}
Esempio n. 2
0
//***********************************************************************
// main function for outputing the graph
//***********************************************************************
void EasyXmlDumper::dumpLimaData(std::ostream& os,
                                  const LinguisticGraphVertex& begin,
                                  const LinguisticGraphVertex& end,
                                  const AnalysisGraph& anaGraph,
                                  const AnalysisGraph& posGraph,
                                  const AnnotationData& annotationData,
                                  const SyntacticData& syntacticData,
                                  const std::string& graphId,
                                  std::vector< bool >& alreadyDumpedTokens,
                                  std::map< LinguisticAnalysisStructure::Token*, uint64_t >& fullTokens,
                                  std::string sentIdPrefix) const
{

  DUMPERLOGINIT;
  LDEBUG << "EasyXmlDumper:: dumpLimaData parameters: ";
  LDEBUG << "EasyXmlDumper::   begin = " << begin;
  LDEBUG << "EasyXmlDumper::   end = " << end;
  LDEBUG << "EasyXmlDumper::   posgraph first vertex = " << posGraph.firstVertex();
  LDEBUG << "EasyXmlDumper::   posgraph last vertex = " << posGraph.lastVertex();
  LDEBUG << "EasyXmlDumper::   graphId = " << graphId;
  LDEBUG << "EasyXmlDumper::   sentIdPrefix = " << sentIdPrefix;

  // just in case we want to check alreadt dumped tokens' array
  for (uint64_t i = 0; i<alreadyDumpedTokens.size(); i++)
  {
    if (alreadyDumpedTokens[i])
    {
      LDEBUG << "EasyXmlDumper:: already_dumped_tokens[" << i << "] =" << alreadyDumpedTokens[i];
    }
  }

  std::string sentIdStr = sentIdPrefix;
  if(find(m_sentIds.begin(), m_sentIds.end(), sentIdStr) != m_sentIds.end() || sentIdStr == "E" )
  {
    uint64_t sentIdsuffix = 0;
    do{
      sentIdsuffix++;
      std::stringstream sentIdStream;
      sentIdStream << sentIdPrefix << sentIdsuffix;
      sentIdStr = sentIdStream.str();
    }while(find(m_sentIds.begin(), m_sentIds.end(), sentIdStr) != m_sentIds.end());
  }

  LDEBUG << "EasyXmlDumper:: searching and extracting vertices and relations";
  LinguisticGraph* anaGraphL = const_cast<LinguisticGraph*>(anaGraph.getGraph());
  LinguisticGraph* posGraphL = const_cast<LinguisticGraph*>(posGraph.getGraph());
  ConstituantAndRelationExtractor care(m_propertyCodeManager);
  care.visitBoostGraph(begin,
                       end,
                       *anaGraphL,
                       *posGraphL,
                       annotationData,
                       syntacticData,
                       fullTokens,
                       alreadyDumpedTokens,
                       m_language);

  LDEBUG << "EasyXmlDumper:: all found vertices and relations extracted";
  care.replaceSEWithCompounds();
  care.constructionDesRelationsEntrantes();
  care.splitCompoundTenses();
  care.constructionDesGroupes();
  care.addLastFormsInGroups();

  EasyDumper ed(care, m_typeMapping, m_srcTag, m_tgtTag, sentIdStr);
  std::stringstream sentEasyStream;
  ed.dump(sentEasyStream);
  if(sentEasyStream.str().length() > 0)
  {
    // Makes object mutable for adding sentence ID
    EasyXmlDumper* self = const_cast<EasyXmlDumper*>(this);
    self->m_sentIds.push_back(sentIdStr);
    os << "<E id=\"" << sentIdStr << "\">" << std::endl;
    os << sentEasyStream.str();
    os << "</E>" << std::endl;
  }

}