void setTrajectoryKeyPosition(double * trajectoryKeyPositions, int * size1, int * size2)
{
  if (TRAJECTORYKEYPOSITIONS.size1()*TRAJECTORYKEYPOSITIONS.size2() != 0)
  {
    std::cout << "You are reinitializing TrajectoryKeyPositions...\n" ;
    TRAJECTORYKEYPOSITIONS.resize(0, 0);
  }

  TRAJECTORYKEYPOSITIONS.resize(*size1, *size2);
  for (int i = 0; i < *size1 * (*size2); i++)
    TRAJECTORYKEYPOSITIONS(i % (*size1), i / (*size1)) = trajectoryKeyPositions[i];
}
void setTrajectoryKeyPosition(double * trajectoryKeyPositions, int * size1, int * size2)
{
  if (TRAJECTORYKEYPOSITIONS.size() != 0)
  {
    std::cout << "You are reinitializing TrajectoryKeyPositions...\n" ;
    for (unsigned int i = 0; i < TRAJECTORYKEYPOSITIONS.size(); i++)
      TRAJECTORYKEYPOSITIONS[i].resize(0);
    TRAJECTORYKEYPOSITIONS.resize(0);
  }

  TRAJECTORYKEYPOSITIONS.resize(*size1);
  for (int i = 0; i < *size1; i++)
  {
    TRAJECTORYKEYPOSITIONS[i].resize(*size2);
    for (int j = 0; j < *size2; j++)
      TRAJECTORYKEYPOSITIONS[i][j] = trajectoryKeyPositions[i * (*size2) + j];
  }
}
示例#3
0
	void similarity(
		const orca::Orca &oa,
		const orca::Orca &ob,
		boost::numeric::ublas::matrix<float> &sim
	) {
		if(oa.graphletSize() != ob.graphletSize()) {
			throw std::invalid_argument("Orca instances now of same size");
		}
		int graphlet_size = oa.graphletSize();
		const size_t orbits = orca::ORBITS[graphlet_size];
		const size_t na = oa.getOrbits().size1();
		const size_t nb = ob.getOrbits().size1();

		std::vector<float> weights(orbits);
		if(orbits > 1) {
			for(size_t k = 0; k < orbits; ++k) {
				weights[k] = 1.0f - log(AFFECTED[k]) / log(orbits);
			}
		} else {
			weights[0] = 1.0f;
		}
		float weights_sum = std::accumulate(weights.begin(), weights.end(), 0.0f);

		sim.resize(na, nb);

		for(size_t i = 0; i < na; ++i) {
			for(size_t j = 0; j < nb; ++j) {
				float D = 0.0f;
				for(size_t k = 0; k < orbits; ++k) {
					int64_t aik = oa.getOrbits()(i, k);
					int64_t bjk = ob.getOrbits()(j, k);

					float num = fabs(log(aik + 1.0f) - log(bjk + 1.0f));
					float denom = log(std::max(aik, bjk) + 2.0f);
					D += weights[k] * num / denom;
				}

				sim(i, j) = 1.0f - D / weights_sum;
			}
		}
	}
示例#4
0
bool read_matrix(FILE* file, boost::numeric::ublas::matrix<T, boost::numeric::ublas::column_major>& m) {
  unsigned magic, rowCount, columnCount;
  if (fread(&magic, sizeof(unsigned), 1, file) != 1)
    return false;
  if (!check_magic<T>(magic))
    return false;

  if (fread(&rowCount, sizeof(unsigned), 1, file) != 1)
    return false;
  if (fread(&columnCount, sizeof(unsigned), 1, file) != 1)
    return false;

  const unsigned count = rowCount * columnCount;
  if (rowCount != m.size1() || columnCount != m.size2())
    m.resize(rowCount, columnCount, false);
  T* buffer = new T[count];
  if (fread(buffer, sizeof(T), count, file) != count)
    return false;

  std::copy(buffer, buffer + count, m.data().begin());

  return true;
}
示例#5
0
void  getReactionMatrix(std::vector<std::string> vsSimpleReactions,std::map<std::string,int> mSpecies, ublas::matrix<int>& mNmatrix)
{//   std::vector< std::vector<int> > vviMatrix;

// ublas::matrix<int> cN(mSpecies.size(),vsSimpleReactions.size());
    
    mNmatrix.resize(mSpecies.size(),vsSimpleReactions.size());
    
    std::vector<int> viReactionVector;

    std::cout << " Matrix size is " << mNmatrix.size1() << "," << mNmatrix.size2() << std::endl;

    fillVector(viReactionVector,0,mSpecies.size());

    for(int i=0;i<vsSimpleReactions.size();i++)
    {
        
        std::cout << " For reaction " << vsSimpleReactions[i] << std::endl;
        
        function(vsSimpleReactions[i],mSpecies,viReactionVector);
        //     vviMatrix.push_back(viReactionVector);
        insertVectorToMatrix(mNmatrix,i,viReactionVector);
        //     function(vsSimpleReactions,mSpecies,viReactionVector);  
    }
}
示例#6
0
 static void resize( boost::numeric::ublas::matrix< T , L , A > &m ,
                     const boost::numeric::ublas::vector< T_V , A_V > &v )
 {
     m.resize( v.size() , v.size() );
 }
示例#7
0
 static void resize( boost::numeric::ublas::matrix< T , L , A > &m1 ,
                     const boost::numeric::ublas::matrix< T2 , L2 , A2 > &m2 )
 {
     m1.resize( m2.size1() , m2.size2() );
 }