本文整理汇总了C++中ublas::matrix::size1方法的典型用法代码示例。如果您正苦于以下问题:C++ matrix::size1方法的具体用法?C++ matrix::size1怎么用?C++ matrix::size1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ublas::matrix
的用法示例。
在下文中一共展示了matrix::size1方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: peel_n_mutations
void peel_n_mutations(const alphabet& a, const vector<int>& letters, const SequenceTree& T,
const ublas::matrix<B>& cost,ublas::matrix<B>& n_muts,
const vector<const_branchview>& branches)
{
const int A = a.size();
assert(letters.size() == T.n_leaves());
assert(cost.size1() == A);
assert(cost.size2() == A);
// we need a scratch row in the matrix
assert(n_muts.size1() == T.n_nodes());
assert(n_muts.size2() == A);
// compute the max cost -- is this approach a good idea?
// Well... this apparently doesn't work.
B max_cost = 0;
for(int i=0;i<A;i++)
for(int j=0;j<A;j++)
max_cost = std::max(cost(i,j)+1, max_cost);
// clear the length matrix.
for(int i=0;i<n_muts.size1();i++)
for(int j=0;j<n_muts.size2();j++)
n_muts(i,j)=0;
// set the leaf costs
for(int s=0;s<T.n_leaves();s++)
{
int L = letters[s];
if (a.is_letter_class(L))
for(int l=0;l<A;l++)
if (a.matches(l,L))
n_muts(s,l) = 0;
else
n_muts(s,l) = max_cost;
}
// compute the costs for letters at each node
for(int i=0;i<branches.size();i++)
{
int s = branches[i].source();
int t = branches[i].target();
// for each letter l of node target...
for(int l=0;l<A;l++)
{
// compute minimum treelength for data behind source.
B temp = n_muts(s,0)+cost(0,l);
for(int k=1;k<A;k++)
temp = min(temp, n_muts(s,k)+cost(k,l) );
// add it to treelengths for data behind target
n_muts(t,l) += temp;
}
}
}
示例3: outer_prod
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);
}
示例4: dispMatrix
void dispMatrix(const ublas::matrix<float>& inMat) {
cout << "Matrix [" << inMat.size1() << ", " << inMat.size2() << "]" << endl << "(";
for (int n = 0; n < (int) inMat.size1(); n++) {
for (int m = 0; m < (int) inMat.size2(); m++) {
cout << inMat(n,m) << " ";
}
cout << endl;
}
cout << "\b)" << endl;
}
示例5: 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;
}
}
示例6: 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 );
}
示例7: 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;
}
示例8: if
// 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;
}
示例9: D
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;
}
示例10: 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;
}
示例11: 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];
}
}
}
示例12: 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;
}
示例13: printMatrix
void printMatrix(const ublas::matrix<T> &A) {
for (unsigned int i = 0; i < A.size1(); i++) {
for (unsigned int j = 0; j < A.size2(); j++) {
std::cout << A(i, j);
if (j + 1 < A.size2()) {
std::cout << ", ";
}
}
if (i + 1 < A.size1()) {
std::cout << ";";
}
std::cout << std::endl;
}
}
示例14:
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;
}
示例15: check_matrices
int check_matrices(const ublas::matrix< ScalarType >& ref_mat, const ublas::matrix< ScalarType >& mat) {
std::size_t size1, size2;
ScalarType eps = 0.00001;
size1 = ref_mat.size1(); size2 = ref_mat.size2();
if( (size1 != mat.size1()) || (size2 != mat.size2()) )
return EXIT_FAILURE;
for (unsigned int i = 0; i < size1; i++)
for (unsigned int j = 0; j < size2; j++)
if ( abs(ref_mat(i,j) - mat(i,j)) > eps ) {
std::cout << "!!Verification failed at " << i <<" : "<< j
<< "(expected: " << ref_mat(i,j) << " get: " << mat(i,j) << " )" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Everything went well!" << std::endl;
return EXIT_SUCCESS;
}