本文整理汇总了C++中ublas::matrix类的典型用法代码示例。如果您正苦于以下问题:C++ matrix类的具体用法?C++ matrix怎么用?C++ matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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];
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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];
}
示例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 );
}
示例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));
}
}
}
示例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;
}
示例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;
}
示例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;
}