• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ublas::matrix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ublas::matrix的典型用法代码示例。如果您正苦于以下问题:C++ matrix类的具体用法?C++ matrix怎么用?C++ matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了matrix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: makeParityCheck

ublas::vector<int> makeParityCheck(const ublas::vector<int> &dSource, const ublas::matrix<int> &H, const ublas::matrix<int> &L, const ublas::matrix<int> &U) {
  // Get matrix dimensions
  const unsigned int M = H.size1();
  const unsigned int N = H.size2();

  // Find B.dsource
  const ublas::vector<int> z(mod2(ublas::prod(ublas::subrange(H, 0, M, N - M, N), dSource)));

  //std::cout << "z=" << std::endl;
  //printVector<int>(z);

  //std::cout << "L=" << std::endl;
  //printMatrix<int>(L);

  //std::cout << "U=" << std::endl;
  //printMatrix<int>(U);

  // Parity check vector found by solving sparse LU
  const ublas::vector<int> x1(solve(L, z));
  //std::cout << "x1=" << std::endl;
  //printVector<int>(x1);

  const ublas::vector<int> x2(solve(U, x1));
  //std::cout << "x2=" << std::endl;
  //printVector<int>(x2);

  const ublas::vector<int> c(mod2(x2));

  return c;
}
开发者ID:ericdegroot,项目名称:gr-ldpc_ece535a,代码行数:30,代码来源:ldpc_umfpack.cpp


示例2: initMatrix

void initMatrix(ublas::matrix<T> &A, const T data[]) {
  for (unsigned int i = 0; i < A.size1(); i++) {
    for (unsigned int j = 0; j < A.size2(); j++) {
      A(i, j) = data[i * A.size2() + j];
    }
  }
}
开发者ID:ericdegroot,项目名称:gr-ldpc_ece535a,代码行数:7,代码来源:ldpc_umfpack.cpp


示例3: dispMatrix

void dispMatrix(const ublas::matrix<float>& inMat, const int rowIndex) {
   cout << "Matrix [" << inMat.size1() << ", " << inMat.size2() << "]" << endl << "(";
   for (int m = 0; m < (int) inMat.size2(); m++) {
     cout << inMat(rowIndex,m) << " ";
   }
   cout << endl << "\b)" << endl;
}
开发者ID:chrisss,项目名称:ETH-SegReg,代码行数:7,代码来源:utilities.cpp


示例4: reorderRows

int reorderRows( ublas::matrix< double >& U, int start, int leftCol )
{
    int leftMostRow = start;
    int numReacs = U.size2() - U.size1();
    int newLeftCol = numReacs;
    for ( size_t i = start; i < U.size1(); ++i )
    {
        for ( int j = leftCol; j < numReacs; ++j )
        {
            if ( fabs( U(i,j )) > SteadyState::EPSILON )
            {
                if ( j < newLeftCol )
                {
                    newLeftCol = j;
                    leftMostRow = i;
                }
                break;
            }
        }
    }

    if ( leftMostRow != start )   // swap them.
        swapRows( U, start, leftMostRow );

    return newLeftCol;
}
开发者ID:2pysarthak,项目名称:moose-core-personal,代码行数:26,代码来源:SteadyStateBoost.cpp


示例5: asymmetric_pairs_distance

long int asymmetric_pairs_distance(const ublas::matrix<int>& M1,const ublas::matrix<int>& M2,
				    const vector< vector<int> >& column_indices2)
{
  int mismatch=0;

  for(int column=0;column<M1.size1();column++) 
    for(int i=0;i<M1.size2();i++)
      for(int j=0;j<i;j++)
      {
	if (M1(column,i) == alphabet::unknown or M1(column,j) == alphabet::unknown)
	  continue;

	if (M1(column,i) != alphabet::gap or M1(column,j)!= alphabet::gap) {
	  if (not A_match(M1,column,i,j,M2,column_indices2)) 
          {
	    if (M1(column,i) != alphabet::gap)
	      mismatch++;
	    if (M1(column,j) != alphabet::gap)
	      mismatch++;
	  }
	}
      }

  return mismatch;
}
开发者ID:sibonli,项目名称:BAli-Phy,代码行数:25,代码来源:alignment-util.C


示例6: normalize_affinity

	ublas::matrix<double> normalize_affinity(ublas::matrix<double> input) {
		ublas::vector<double> ones = ublas::scalar_vector<double>(input.size1(), 1);
		ublas::vector<double> diag(input.size1());
		
		for (int i = 0; i < input.size1(); i++)
			diag[i] = input(i, i);
		
		return ublas::outer_prod(diag, ones) + ublas::outer_prod(ublas::trans(ones), ublas::trans(diag)) - input - ublas::trans(input);
	}
开发者ID:jithina,项目名称:sirens,代码行数:9,代码来源:matrix_support.cpp


示例7:

bool BenchmarkVienna<ScalarType>::is_equal(const ublas::matrix<ScalarType, orientation> &A,
                                           const ublas::matrix<ScalarType, orientation> &B) {
    for (std::size_t i = 0; i < A.size1(); ++i) {
        for (std::size_t j = 0; j < A.size2(); ++j) {
            if ( std::fabs(A(i,j) - B(i,j)) / B(i,j) > 1e-4 ) return false;
        }
    }
    return true;
}
开发者ID:lene,项目名称:lina,代码行数:9,代码来源:BenchmarkVienna.cpp


示例8: homologies_total

long int homologies_total(const ublas::matrix<int>& M1) 
{
  long int total=0;

  for(int column=0;column<M1.size1();column++) 
    for(int i=0;i<M1.size2();i++)
      if (M1(column,i) != alphabet::gap and M1(column,i) != alphabet::unknown)
	total++;

  return total;
}
开发者ID:sibonli,项目名称:BAli-Phy,代码行数:11,代码来源:alignment-util.C


示例9: recalcTotal

/**
 * @brief Utility funtion to doing scans for steady states.
 *
 * @param tot
 * @param g
 * @param S
 */
void recalcTotal( vector< double >& tot, ublas::matrix<double>& g, const double* S )
{
    assert( g.size1() == tot.size() );
    for ( size_t i = 0; i < g.size1(); ++i ) 
    {
        double t = 0.0;
        for ( unsigned int j = 0; j < g.size2(); ++j )
            t += g( i, j ) * S[j];
        tot[ i ] = t;
    }
}
开发者ID:2pysarthak,项目名称:moose-core-personal,代码行数:18,代码来源:SteadyStateBoost.cpp


示例10: swapRows

/**
 * @brief Swap row r1 and r2.
 *
 * @param mat Matrix input
 * @param r1 index of row 1
 * @param r2 index of row 2
 */
void swapRows( ublas::matrix< double >& mat, unsigned int r1, unsigned int r2)
{
    ublas::vector<value_type> temp( mat.size2() );
    for (size_t i = 0; i < mat.size2(); i++) 
    {
        temp[i] = mat(r1, i );
        mat(r1, i ) = mat(r2, i );
    }

    for (size_t i = 0; i < mat.size2(); i++) 
        mat(r2, i) = temp[i]; 
}
开发者ID:2pysarthak,项目名称:moose-core-personal,代码行数:19,代码来源:SteadyStateBoost.cpp


示例11: cond2

T cond2( ublas::matrix<T> const& M )
{
    gmm::dense_matrix<T> Q( M.size1(), M.size2() );

    for ( int_type i=0; i < M.size1(); ++i )
        for ( int_type j=0; j < M.size2(); ++j )
        {
            Q( i,j ) = M( i,j );
        }

    return gmm::condition_number( Q );
}
开发者ID:LANTZT,项目名称:feelpp,代码行数:12,代码来源:test_spectral_2D.cpp


示例12: ublas_to_vector

void ublas_to_vector(const ublas::matrix<float> &mat, std::vector<double> &vec)
{
  vec.clear();
  for (size_t i=0; i < mat.size1(); i++)
  {
    for (size_t j=0; j < mat.size2(); j++)
    {
      vec.push_back(mat(i,j));
    }
  }

}
开发者ID:sjavdani,项目名称:statsproj,代码行数:12,代码来源:FeatureImageHandler.cpp


示例13: colSums

double colSums(const ublas::matrix<long double>& A, vector<long double>& sums)
{
	long double total = 0.0;
	sums = vector<long double>(A.size2(),0.0);
	for (size_t i = 0; i < A.size1(); ++i)
		for (size_t j = 0; j < A.size2(); ++j)
		{
			sums[j] += A(i,j);
			total += A(i,j);
		}
	return total;
}
开发者ID:zzj,项目名称:Cufflinks,代码行数:12,代码来源:biascorrection.cpp


示例14: fourSums

double fourSums(const ublas::matrix<long double>& A, ublas::matrix<long double>& sums)
{
	long double total = 0.0;
	sums = ublas::zero_matrix<long double>(A.size1(), A.size2()/4);
	for (size_t i = 0; i < A.size1(); ++i)
		for (size_t j = 0; j < A.size2(); ++j)
		{
			sums(i,j/4) += A(i,j);
			total += A(i,j);
		}
	
	return total;
}
开发者ID:zzj,项目名称:Cufflinks,代码行数:13,代码来源:biascorrection.cpp


示例15: mvnormpdf

ublas::vector<double> mvnormpdf(const ublas::matrix<double>& x, const  ublas::vector<double>& mu, const ublas::matrix<double>& Omega) {
  //! Multivariate normal density
  size_t p = x.size1();
  size_t n = x.size2();
  
  double f = sqrt(det(Omega))/pow(2.0*PI, p/2.0);
  // cout << "O: " << Omega << "\n";
  // cout << "f: " << f << "\n";
  ublas::matrix<double> e(p, n);
  e.assign(x - outer_prod(mu, ublas::scalar_vector<double>(n, 1)));
  e = element_prod(e, prod(Omega, e));

  return ublas::apply_to_all<functor::exp<double> > (-(ublas::matrix_sum(e, 0))/2.0)*f;
}
开发者ID:cliburn,项目名称:flow,代码行数:14,代码来源:distributions.cpp


示例16: reorderHMatrix

void reorderHMatrix(ublas::matrix<int> &H, ublas::matrix<int> &L, ublas::matrix<int> &U) {
  // Get matrix dimensions
  const unsigned int M = H.size1();
  const unsigned int N = H.size2();

  // Set a new matrix F for LU decomposition
  ublas::matrix<int> F(H);

  // Re-order the M x (N - M) submatrix
  for (unsigned int i = 0; i < M; i++) {
    int chosenCol = 0;

    // Create diagonally structured matrix using 'First' strategy
    for (unsigned int j = i; j < N; j++) {
      if (F(i, j) != 0) {
        chosenCol = j;
        break;
      }
    }

    //std::cout << "chosenCol=" << chosenCol << std::endl;
    //printMatrix<int>(H);

    // Re-ordering columns of F
    const ublas::vector<int> tmp1(ublas::column(F, i));
    ublas::column(F, i) = ublas::column(F, chosenCol);
    ublas::column(F, chosenCol) = tmp1;

    // Re-ordering columns of H
    const ublas::vector<int> tmp2(ublas::column(H, i));
    ublas::column(H, i) = ublas::column(H, chosenCol);
    ublas::column(H, chosenCol) = tmp2;

    // Fill the LU matrices column by column
    ublas::subrange(L, i, M, i, i + 1) = ublas::subrange(F, i, M, i, i + 1);
    ublas::subrange(U, 0, i + 1, i, i + 1) = ublas::subrange(F, 0, i + 1, i, i + 1);

    // There will be no rows operation at the last row
    if (i < M - 1) {
      // Find the later rows with non-zero elements in column i
      for (unsigned int k = i + 1; k < M; k++) {
        if (F(k, i) != 0) {
          // Add current row to the later rows which have a 1 in column i
	  ublas::row(F, k) = mod2(ublas::row(F, k) + ublas::row(F, i));
        }
      }
    }
  }  
}
开发者ID:ericdegroot,项目名称:gr-ldpc_ece535a,代码行数:49,代码来源:ldpc_umfpack.cpp


示例17: matrix_sum

  // ublas::matrix<T> matrix_sum(ublas::matrix<T>& m, int index) {
  ublas::vector<T> matrix_sum(const ublas::matrix<T>& m, int index) {
    using namespace boost::numeric::ublas;
    ublas::vector<T> result;
    if (index == 0) {
      result.resize(m.size2());
      for (size_t i=0; i<m.size2(); ++i)
	result(i) = sum(column(m, i));
    }
    else if (index == 1) {
      result.resize(m.size1());
      for (size_t i=0; i<m.size1(); ++i)
	result(i) = sum(row(m, i));
    }
    return result;
  }
开发者ID:cliburn,项目名称:flow,代码行数:16,代码来源:ublas_utils.hpp


示例18: row_min

B row_min(const ublas::matrix<B>& M,int row)
{
  B min=M(row,0);
  for(int i=1;i<M.size2();i++)
    min = std::min(min,M(row,i));
  return min;
}
开发者ID:sibonli,项目名称:BAli-Phy,代码行数:7,代码来源:parsimony.C


示例19: wishart_rnd

ublas::vector<ublas::matrix<double> > wishart_rnd(const int df, ublas::matrix<double>& S, const int mc) {
  //! inverse Wishart random matrix
  //! does not correct for poorly conditioned matrix 
  size_t p = S.size1();
  ublas::vector<double> D(p);
  ublas::matrix<double> P(p, p);
  ublas::matrix<double> F(p, p);
  F = ublas::zero_matrix<double>(p, p);

  // make copy of S
  // ublas::matrix<double> SS(S);

  lapack::gesvd('A', 'A', S, D, P, F);
  // svd0(S, P, D, F);
  
  P = prod(trans(P), diagm(ublas::apply_to_all<functor::inv_sqrt<double> >(D)));
  // rprod does not seem any faster than diagonalizing D before multiplication
  // P = rprod(P, ublas::apply_to_all<functor::inv_sqrt<double> >(D));

  // generate mc samples
  ublas::vector<ublas::matrix<double> > K(mc);
  for (int i=0; i<mc; ++i)
    K(i) = wishart_1(df, P, p, p);
  return K;
}
开发者ID:cliburn,项目名称:flow,代码行数:25,代码来源:distributions.cpp


示例20: InvertMatrix

bool InvertMatrix(const ublas::matrix<T>& input, ublas::matrix<T>& inverse) 
{
	using namespace boost::numeric::ublas;
	typedef permutation_matrix<std::size_t> pmatrix;
	// create a working copy of the input
	matrix<T> A(input);
	// create a permutation matrix for the LU-factorization
	pmatrix pm(A.size1());


	// perform LU-factorization
	int res = lu_factorize(A,pm);
	if( res != 0 ) return false;


	// create identity matrix of "inverse"
	inverse.assign(ublas::identity_matrix<T>(A.size1()));


	// backsubstitute to get the inverse
	lu_substitute(A, pm, inverse);


	return true;
}
开发者ID:AriehTal,项目名称:EC14-HyperNEAT,代码行数:25,代码来源:LeastSquares.cpp



注:本文中的ublas::matrix类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ublas::vector类代码示例发布时间:2022-05-31
下一篇:
C++ uavcan::ServiceCallResult类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap