Example #1
0
number_t BaseVertex<D, T>::solveDirect(number_t lambda) {
  Eigen::Matrix<number_t, D, D, Eigen::ColMajor> tempA=_hessian + Eigen::Matrix<number_t, D, D, Eigen::ColMajor>::Identity()*lambda;
  number_t det=tempA.determinant();
  if (g2o_isnan(det) || det < std::numeric_limits<number_t>::epsilon())
    return det;
  Eigen::Matrix<number_t, D, 1, Eigen::ColMajor> dx=tempA.llt().solve(_b);
  oplus(&dx[0]);
  return det;
}
Example #2
0
double BaseVertex<D, T>::solveDirect(double lambda) {
  Matrix <double, D, D> tempA=_hessian + Matrix <double, D, D>::Identity()*lambda;
  double det=tempA.determinant();
  if (g2o_isnan(det) || det < std::numeric_limits<double>::epsilon())
    return det;
  Matrix <double, D, 1> dx=tempA.llt().solve(_b);
  oplus(&dx[0]);
  return det;
}
Example #3
0
inline bool Transformation::oplus(
    const Eigen::MatrixBase<Derived_delta> & delta,
    const Eigen::MatrixBase<Derived_jacobian> & jacobian) {
  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived_delta, 6);
  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived_jacobian, 7, 6);
  if (!oplus(delta)) {
    return false;
  }
  return oplusJacobian(jacobian);
}
Example #4
0
serie_ *oplusSerie(serie_ *s1, serie_ *s2) {
	return new serie(oplus(*(serie*)s1, *(serie*)s2));
}
Example #5
0
poly_ *oplusPoly(poly_ *p1, poly_ *p2) {
	return new poly(oplus(*(poly*)p1, *(poly*)p2));
}
Example #6
0
rgAssignment assignReadGroup(string &index1, 
			     string &index1q, 
			     string &index2,
			     string &index2q, 
			     double rgScoreCutoff,
			     double fracConflict,
			     int mismatchesTrie,
			     int qualOffset){
    //BEGIN DEBUG
    // cout<<"DEBUG"<<endl;
    // vector< int > * test1=new vector<int>();
    // indTrie1->searchMismatch("NTGNNNN",test1,2);
    // //    vector< matches<int> > * test2=indTrie2->searchForWordMismatch("CCGGTAC",0);
    // cout<<test1->size()<<endl;
    // //    cout<<test2->size()<<endl;

    // for(unsigned int j=0;j<test1->size();j++){
    // 	// list< int  >::const_iterator iter;		    
    // 	// for (iter  = (*test1)[j].listOfDeflinesOfMatches->begin(); 
    // 	//      iter != (*test1)[j].listOfDeflinesOfMatches->end(); 
    // 	//      iter++){
    // 	//     cout<<"test "<<*iter<<"\t"<<values.indices1[*iter]<<"\t"<<values.names[*iter]<<endl;
    // 	// }
    // 	cout<<"test "<< (*test1)[j] <<"\t"<<values.indices1[  (*test1)[j] ]<<"\t"<<values.names[ (*test1)[j] ]<<endl;
    // }
    // delete test1;
    //exit(1);
    //END DEBUG

    rgAssignment toReturn;

    vector<int> quals1;
    vector<int> quals2;

    //Find matches using the prefix trie

    vector< int > matchesind1, matchesind2;
    indTrie1->searchMismatch(      index1.c_str(),&matchesind1,mismatchesTrie);

    
    if(shiftByOne){       
	indTrie1->searchMismatch(     ("N"+index1.substr(0, index1.size() -1)     ).c_str(),&matchesind1,mismatchesTrie);
	indTrie1->searchMismatch(         (index1.substr(1, index1.size() -1)+"N" ).c_str(),&matchesind1,mismatchesTrie);
    }

    for(unsigned int i=0;i<index1q.length();i++){
	char tempCtocov   = char(index1q[i]);
	int tempIntTopush = (int( tempCtocov )-qualOffset);
	quals1.push_back(     max(tempIntTopush ,2)  )   ; //since qual scores less than 2 do not make sense
    }


    if(!index2.empty()){
	if(!values.isDoubleIndex){
	    if(!warnedForDouble){
		cerr<<"WARNING : THIS RUN IS DOUBLE INDEXED YET YOUR INDEX IS SINGLE INDEXED"<<endl;
		warnedForDouble=true;
	    }
	}else{
	    indTrie2->searchMismatch(  index2.c_str(),&matchesind2,mismatchesTrie);

	    if(shiftByOne){       
		indTrie2->searchMismatch( ("N"+index2.substr(0, index2.size() -1)     ).c_str(),&matchesind2,mismatchesTrie);
		indTrie2->searchMismatch(     (index2.substr(1, index2.size() -1)+"N" ).c_str(),&matchesind2,mismatchesTrie);
	    }
	
	    for(unsigned int i=0;i<index2q.length();i++){
		char tempCtocov   = char(index2q[i]);
		int tempIntTopush =(int(tempCtocov)-qualOffset);
		quals2.push_back( max( tempIntTopush ,2)  )   ;	//since qual scores less than 2 do not make sense
	    }
	}
    }


    set<int> foundIndices; //set of indices found

    double like1=0.0;
    double like2=0.0;

    vector< pair<int,double>  > sortedLikelihoodAll; //likelihood for both indices
    vector< pair<int,double>  > sortedLikelihood1;   //likelihood for index 1
    vector< pair<int,double>  > sortedLikelihood2;   //likelihood for index 1

    //putting all the index # into the set
    for(unsigned int j=0;j<matchesind1.size();j++)
        foundIndices.insert ( matchesind1[j]  );   

    for(unsigned int j=0;j<matchesind2.size();j++)
        foundIndices.insert ( matchesind2[j]  );   


    //for every # in the set, compute likelihood    
    for (set<int>::iterator sit=foundIndices.begin(); sit!=foundIndices.end(); sit++){

	like1      =  computeLike(index1,values.indices1[ *sit ],&quals1);
	
	if(shiftByOne){ //check if shifting by one improves the likelihood
	    like1      =  max(like1,
			      max(
				  computeLike( ("N"+index1.substr(0, index1.size() -1)     ), values.indices1[ *sit ],&quals1),
				  computeLike( (    index1.substr(1, index1.size() -1)+"N" ), values.indices1[ *sit ],&quals1)
				  )			      
			      );
	}

	sortedLikelihood1.push_back(     make_pair (*sit,like1) );

	if(!index2.empty()  && 	values.isDoubleIndex ){

	    like2  =  computeLike(index2,values.indices2[ *sit ],&quals2);

	    if(shiftByOne){ //check if shifting by one improves the likelihood
		like2      =  max(like2,
				  max(
				      computeLike( ("N"+index2.substr(0, index2.size() -1)     ), values.indices2[ *sit ], &quals2),
				      computeLike( (    index2.substr(1, index2.size() -1)+"N" ), values.indices2[ *sit ], &quals2)
				      )
				  );
	    }

	    sortedLikelihood2.push_back( make_pair (*sit,like2) );
	}else{
	    like2=0.0;
	}

	sortedLikelihoodAll.push_back( make_pair (*sit,like1+like2) ) ;      
    }

    //if nothing was found, unknown
    if(foundIndices.empty() ){
	toReturn.predictedGroup.clear();
	return toReturn;
    }
    //At this point, we will return a RG 

    //sorting by likelihood
    sort (sortedLikelihood1.begin(),   sortedLikelihood1.end(),   comparePair()); 
    sort (sortedLikelihood2.begin(),   sortedLikelihood2.end(),   comparePair()); 
    sort (sortedLikelihoodAll.begin(), sortedLikelihoodAll.end(), comparePair()); 

#ifdef DEBUG
    cerr<<endl;
    cerr<<"first:"<<endl;
    for(unsigned int j=0;j<sortedLikelihood1.size();j++){
    	cerr<< values.names[ sortedLikelihood1[j].first ]<<"\t"<< sortedLikelihood1[j].second<<endl;
    }
    cerr<<"second:"<<endl;
    for(unsigned int j=0;j<sortedLikelihood2.size();j++){
    	cerr<< values.names[ sortedLikelihood2[j].first ]<<"\t"<< sortedLikelihood2[j].second<<endl;
    }
    cerr<<"all:"<<endl;
    for(unsigned int j=0;j<sortedLikelihoodAll.size();j++){
    	cerr<< values.names[ sortedLikelihoodAll[j].first ]<<"\t"<< sortedLikelihoodAll[j].second<<"\t"<<pow(10.0,sortedLikelihoodAll[j].second)<<endl;
    }
    cerr<<endl;
    //exit(1);
#endif

    // DETECT WRONGS
    // Look for a wrong index.  Suppose the top indices do not match up,
    // then those give the likelihood for being wrong, which we compare
    // to that of the top correct pair.
    //
    // Suppose they do, then we have to find the highest scoring wrong
    // pair.  That's either the top first index with the runner-up
    // second index, or vice versa.  Could actually be both to some
    // extent, so we add them.

    if( (sortedLikelihood1.size()>1) && 
	(sortedLikelihood2.size()>1)   ){
        if(sortedLikelihood1[0].first != sortedLikelihood2[0].first) { // mismatch, we found the wrong pair
           
	    //find likelihood of p5 (in sortedLikelihood2)  for p7 top hit (sortedLikelihood1[0].first)
	    int  indexP5LikeForP7Top=-1;
	    for(unsigned int j=0;j<sortedLikelihood2.size();j++){
		if(sortedLikelihood2[j].first == sortedLikelihood1[0].first){
		    indexP5LikeForP7Top = int(j);
		    break;
		}
	    }

	    //find likelihood of p7 (in sortedLikelihood1)  for p5 top hit (sortedLikelihood2[0].first)
	    int  indexP7LikeForP5Top=-1;
	    for(unsigned int j=0;j<sortedLikelihood1.size();j++){
		if(sortedLikelihood1[j].first == sortedLikelihood2[0].first){
		    indexP7LikeForP5Top = int(j);
		    break;
		}
	    }

	    if(indexP7LikeForP5Top == -1 ||
	       indexP5LikeForP7Top == -1 ){
		cerr<<"Internal error, unable to trace back the likelihood for one of the index pairs"<<endl;
		exit(1);
	    }
	       
	  
	    
            toReturn.topWrongToTopCorrect =    1.0*(  sortedLikelihood1[                  0].second + sortedLikelihood2[                   0 ].second )
		                             + 0.3 
		                             - oplus( sortedLikelihood1[                  0].second + sortedLikelihood2[ indexP5LikeForP7Top ].second 
						      , 
						      sortedLikelihood1[indexP7LikeForP5Top].second + sortedLikelihood2[                   0 ].second ) ;
	    

#ifdef DEBUGMISPAIR
	    cout<<"conf\t"<<toReturn.topWrongToTopCorrect<<"\t"<<-10*toReturn.topWrongToTopCorrect<<endl;
#endif
        }else { //stem from the same sample
            // we compare one correct pair to two potentially wrong
            // ones; add 0.3 to make it fair
            toReturn.topWrongToTopCorrect = - 1.0* sortedLikelihoodAll[0].second 
                                 	    - 0.3 
		                            + oplus( sortedLikelihood1[0].second + sortedLikelihood2[1].second 
						     , 
						     sortedLikelihood1[1].second + sortedLikelihood2[0].second ) ;

#ifdef DEBUGMISPAIR
	    cout<<"same\t"<<toReturn.topWrongToTopCorrect<<"\t"<<-10*toReturn.topWrongToTopCorrect<<endl;
#endif
        }
    }else{
	toReturn.topWrongToTopCorrect = -1.0*1000000  ; // +infinity for practical purposes
    }

    // DETECT CONFLICTS
    // Checking likelihood of inferior hits; if the ratio is too low,
    // it's a conflict.  Checking the second best only is already a
    // useable approximation, adding all is more appropriate (and a bit
    // more expensive).
    double probRG    = sortedLikelihoodAll[0].second;
    toReturn.predictedGroup = values.names[ sortedLikelihoodAll[0].first ];
    toReturn.logLikelihoodScore = probRG;

    if(sortedLikelihoodAll.size() > 1){
	double probRG2nd    = sortedLikelihoodAll[1].second;
        for( size_t i = 2 ; i != sortedLikelihoodAll.size() ; ++i )
            probRG2nd = oplus( probRG2nd, sortedLikelihoodAll[i].second ) ; //oplus= log10( pow(10,x)+pow(10,y) )

	toReturn.logRatioTopToSecond = probRG2nd - oplus(probRG,probRG2nd) ;
	double temporaryD=-10.0*toReturn.logRatioTopToSecond;
	if(flag_ratioValues ) // && toReturn.logRatioTopToSecond > -5) //to avoid very small values
	    ratioValues->write( (char *)&(temporaryD), sizeof(toReturn.logRatioTopToSecond));
    }else{
	toReturn.logRatioTopToSecond = 1;
    }

    if(flag_rgqual){
	double temporaryD=-10.0*toReturn.logLikelihoodScore;
	rgqual->write( (char *)&(temporaryD), sizeof(toReturn.logLikelihoodScore));
    }


#ifdef DEBUG3    

    toReturn.numberOfMismatches      = computeMM(index1,values.indices1[ sortedLikelihoodAll[0].first ]);
    if(!index2.empty())
	toReturn.numberOfMismatches += computeMM(index2,values.indices2[ sortedLikelihoodAll[0].first ]);
    
    //cerr<<endl;
    // if(toReturn.numberOfMismatches!=0){
    // 	cerr<<toReturn.logLikelihoodScore<<endl;
    // cerr<<toReturn.topWrongToTopCorrect<<endl;
    // cerr<<toReturn.logRatioTopToSecond<<endl;
    //cerr<<"MM"<<toReturn.numberOfMismatches<<endl;
    //}
    //cerr<<toReturn.numberOfMismatches<<"\t"<<toReturn.logLikelihoodScore<<endl;
#endif
    
    return toReturn;
}