本文整理汇总了C++中mat类的典型用法代码示例。如果您正苦于以下问题:C++ mat类的具体用法?C++ mat怎么用?C++ mat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sub_m_v_vT
// m=m-m*v*v'
void sub_m_v_vT(mat &m, const vec &v)
{
vec v2(m.rows());
double tmp, *v2p;
const double *vp;
int i, j;
it_assert(v.size() == m.cols(), "sub_m_v_vT()");
v2p = v2._data();
for (i = 0; i < m.rows(); i++) {
tmp = 0.0;
vp = v._data();
for (j = 0; j < m.cols(); j++)
tmp += *(vp++) * m._elem(i, j);
*(v2p++) = tmp;
}
v2p = v2._data();
for (i = 0; i < m.rows(); i++) {
vp = v._data();
for (j = 0; j < m.cols(); j++)
m._elem(i, j) -= *v2p * *(vp++);
v2p++;
}
}
开发者ID:c304728539,项目名称:itpp-fastica,代码行数:27,代码来源:fastmath.cpp
示例2: produit
// fonction retournant le produit d'une matrice et d'un vecteur
vec Calculs::produit(mat MM, vec V)
{
VV.resize(MM.size());
for(kk=0;kk<MM.size();kk++)
{
som = 0;
for(ll=0;ll<V.size();ll++)
{
som = som+MM[kk][ll]*V[ll];
}
VV[kk] = som;
}
return VV;
}
开发者ID:configithub,项目名称:internship-liama-corn-optimization,代码行数:15,代码来源:Calculst.cpp
示例3: update_WtA
inline void update_WtA(mat & WtA, const mat & W, const mat & W1, const mat & H2, const mat & A)
{
// compute WtA = (W[:, 0:k-1], W1)^T (A - W[, k:end] H2^T)
if (H2.empty())
update_WtA(WtA, W, W1, A);
else
{
int k = W.n_cols - H2.n_cols;
//std::cout << "1.3" << std::endl;
//A.print("A = ");
//(W.cols(k, W.n_cols-1) * H2.t()).print("W[, k:] = ");
update_WtA(WtA, W.cols(0, k-1), W1, A - W.cols(k, W.n_cols-1) * H2.t());
}
}
开发者ID:n7wilson,项目名称:NNLM,代码行数:14,代码来源:nnls_solver.cpp
示例4: medianFilter
//! get gravity and body acc. components of the window
//! @param[in] &window reference to the window
//! @param[out] &gravity reference to the gravity comp. extracted from the window
//! @param[out] &body reference to the body acc. comp. extracted from the window
void Classifier::analyzeWindow(mat &window, mat &gravity, mat &body)
{
// perform median filtering to reduce the noise
int n = 3;
mat clean_window = window.t();
medianFilter(clean_window, n);
clean_window = clean_window.t();
// discriminate between gravity and body acc. components
mat tempgr = clean_window.t();
gravity = ChebyshevFilter(tempgr);
gravity = gravity.t();
body = clean_window - gravity;
}
开发者ID:enriquecoronadozu,项目名称:HMPdetector,代码行数:18,代码来源:classifier.cpp
示例5: mat2Blob
// convertion
void mat2Blob(mat& mA, shared_ptr<Blob>& out, int c, int h, int w) {
int n = mA.n_rows;
assert(mA.n_cols == c*h*w);
mA = mA.t();
if (out) {
out.reset();
}
out.reset(new Blob(n, c, h, w));
for (int i = 0; i < n; ++i) {
(*out)[i] = cube(mA.colptr(i), h, w, c);
}
return;
}
开发者ID:xenron,项目名称:sandbox-da-Caffe,代码行数:15,代码来源:blob.cpp
示例6: getRatio
double Jastrow::getRatio(const int &particleNum, const mat &rNew, const mat &rOld){
double argument = 0;
double fNew = 0;
double fOld = 0;
double r12 = 0;
for (int i = 0; i < particleNum; i++){
r12Vec = rNew.row(particleNum) - rNew.row(i);
r12 = sqrt(r12Vec(0)*r12Vec(0) + r12Vec(1)*r12Vec(1) + r12Vec(2)*r12Vec(2));
fNew = f(r12, particleNum, i);
r12Vec = rOld.row(particleNum) - rOld.row(i);
r12 = sqrt(r12Vec(0)*r12Vec(0) + r12Vec(1)*r12Vec(1) + r12Vec(2)*r12Vec(2));
fOld = f(r12, particleNum, i);
argument += fNew - fOld;
}
for (int i = particleNum + 1; i < nParticles; i++){
r12Vec = rNew.row(particleNum) - rNew.row(i);
r12 = sqrt(r12Vec(0)*r12Vec(0) + r12Vec(1)*r12Vec(1) + r12Vec(2)*r12Vec(2));
fNew = f(r12, particleNum, i);
r12Vec = rOld.row(particleNum) - rOld.row(i);
r12 = sqrt(r12Vec(0)*r12Vec(0) + r12Vec(1)*r12Vec(1) + r12Vec(2)*r12Vec(2));
fOld = f(r12, particleNum, i);
argument += fNew - fOld;
}
return exp(argument);
}
开发者ID:henrikei,项目名称:FYS4411,代码行数:29,代码来源:jastrow.cpp
示例7: generate_meas
//used for both spheric and hybrid multilateration
static
bool generate_meas(vec &meas, const bvec &method, const mat &bs_pos, const vec &ms_pos)
{
unsigned int method_len = length(method);
unsigned int nb_bs = bs_pos.cols();
bool column = true;
if(3 == nb_bs) {
nb_bs = bs_pos.rows();
column = false;
}
if((nb_bs < method_len) || (3 != length(ms_pos))) {
return false;
}
meas.set_size(method_len);
vec pos(3);
vec pos_ref(3);
pos_ref = column ? bs_pos.get_col(0) : bs_pos.get_row(0);
for(unsigned int k = 0; k < method_len; ++k) {
if(bin(1) == method[k]) { /* hyperbolic */
pos = column ? bs_pos.get_col(k + 1) : bs_pos.get_row(k + 1);
meas[k] = get_dist(pos, ms_pos) - get_dist(pos_ref, ms_pos);
}
else { /* spherical */
pos = column ? bs_pos.get_col(k) : bs_pos.get_row(k);
meas[k] = get_dist(pos, ms_pos);
}
}
return true;
}
开发者ID:snikulov,项目名称:mirror.itpp,代码行数:30,代码来源:multilateration_test.cpp
示例8: bb_shift_relative
mat bb_shift_relative(mat bb,pair<double,double>shift)
{
bb.row(1) = bb.row(1)+(bb.row(3)-bb.row(1)+1)*shift.first;
bb.row(2) = bb.row(2)+(bb.row(4)-bb.row(2)+1)*shift.second;
bb.row(3) = bb.row(3)+(bb.row(3)-bb.row(1)+1)*shift.first;
bb.row(4) = bb.row(4)+(bb.row(4)-bb.row(2)+1)*shift.second;
}
开发者ID:shllhs,项目名称:tracking,代码行数:7,代码来源:bb_shift_relative.cpp
示例9: forward_substitution
void forward_substitution(const mat &L, int p, const vec &b, vec &x)
{
assert( L.rows() == L.cols() && L.cols() == b.size() && b.size() == x.size() && p <= L.rows()/2 );
int n = L.rows(), i, j;
x=b;
for (j=0;j<n;j++) {
x(j)/=L(j,j);
for (i=j+1;i<MIN(j+p+1,n);i++) {
x(i)-=L(i,j)*x(j);
}
}
}
开发者ID:mbillingr,项目名称:tools4bci-unibuild,代码行数:14,代码来源:ls_solve.cpp
示例10: backslash
mat backslash(const mat &A, const mat &B)
{
mat ls_solve(const mat &A, const mat &b);
mat ls_solve_od(const mat &A, const mat &b);
int m=A.rows(), n=A.cols();
if (m == n)
return ls_solve(A,B);
else if (m > n)
return ls_solve_od(A,B);
//it_error("Cannot solve under-determined linear equation systems!");
return vec(0);
}
开发者ID:mbillingr,项目名称:tools4bci-unibuild,代码行数:14,代码来源:ls_solve.cpp
示例11: Gradient
//Beregning av enkeltderiverte til orbitalene
rowvec3 Wavefunction::Gradient(const mat &r, const int number_particle, const int &Orbital_number, double alpha, int atom_nr)
{
double Sum_I_Eksponenten = 0;
rowvec3 Gradienten;
Gradienten(0)=0; Gradienten(1)=0; Gradienten(2)=0;
for (int k = 0; k < dimension; k++)
{
Sum_I_Eksponenten += (r(number_particle, k) - R(atom_nr, k)) * (r(number_particle, k) - R(atom_nr, k));
}
Sum_I_Eksponenten = sqrt(Sum_I_Eksponenten);
if (Orbital_number == 0)
{
Gradienten = -(alpha * (r.row(number_particle)-R.row(atom_nr)) / Sum_I_Eksponenten) * exp(-alpha*Sum_I_Eksponenten);
}
if (Orbital_number == 1)
{
Gradienten = (alpha*(r.row(number_particle) - R.row(atom_nr))*(alpha*Sum_I_Eksponenten-4) / (4*Sum_I_Eksponenten)) * exp(-alpha*Sum_I_Eksponenten/2);
}
if (Orbital_number == 2)
{
Gradienten(0) = -alpha*(r(number_particle, 0)-R(atom_nr, 0)) * (r(number_particle ,0)-R(atom_nr, 0)) + 2*Sum_I_Eksponenten;
Gradienten(1) = -alpha*(r(number_particle, 0)-R(atom_nr,0)) * (r(number_particle ,1)-R(atom_nr,1));
Gradienten(2) = -alpha*(r(number_particle, 0)-R(atom_nr,0)) * (r(number_particle ,2)-R(atom_nr,2));
Gradienten = Gradienten * exp(-alpha*Sum_I_Eksponenten / 2) / (2*Sum_I_Eksponenten);
}
if (Orbital_number == 3)
{
Gradienten(0) = -alpha*(r(number_particle, 1)-R(atom_nr,1)) * (r(number_particle ,0)-R(atom_nr, 0));
Gradienten(1) = -alpha*(r(number_particle, 1)-R(atom_nr,1)) * (r(number_particle ,1)-R(atom_nr,1)) + 2*Sum_I_Eksponenten;
Gradienten(2) = -alpha*(r(number_particle, 1)-R(atom_nr,1)) * (r(number_particle ,2)-R(atom_nr,2));
Gradienten = Gradienten * exp(-alpha*Sum_I_Eksponenten / 2) / (2*Sum_I_Eksponenten);
}
if (Orbital_number == 4)
{
Gradienten(0) = -alpha*(r(number_particle, 2)-R(atom_nr,2)) * (r(number_particle ,0)-R(atom_nr, 0));
Gradienten(1) = -alpha*(r(number_particle, 2)-R(atom_nr,2)) * (r(number_particle ,1)-R(atom_nr,1));
Gradienten(2) = -alpha*(r(number_particle, 1)-R(atom_nr,1)) * (r(number_particle ,2)-R(atom_nr,2)) + 2*Sum_I_Eksponenten;
Gradienten = Gradienten * exp(-alpha*Sum_I_Eksponenten / 2) / (2*Sum_I_Eksponenten);
}
return Gradienten;
}
开发者ID:otnorli,项目名称:Variational-Monte-Carlo,代码行数:50,代码来源:wavefunction.cpp
示例12: randselect
void randselect(mat X, mat y, int n, mat &outX, mat &outy) {
std::vector<int> indeces;
for (int i = 0; i < (int)X.n_rows; i++) {
indeces.push_back(i);
}
random_shuffle(indeces.begin(), indeces.end());
mat _X_ = X;
mat _y_ = y;
outX = mat(n, X.n_cols);
outy = mat(n, 1);
for (int i = 0; i < n; i++) {
outX.row(i) = _X_.row(indeces[i]);
outy.row(i) = _y_.row(indeces[i]);
}
}
开发者ID:timrobot,项目名称:aiml,代码行数:15,代码来源:perceptron_train.cpp
示例13: mul
mat mul(mat &A, mat &B) //A: m*n, B: n*p
{
mat C(A.size(), vec(B[0].size())); //C: m:p
for (int i = 0; i < A.size(); i++)
{
for (int k = 0; k < B.size(); k++)
{
for (int j = 0; j < B[0].size(); j++)
{
C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
}
}
}
return C;
}
开发者ID:handong1587,项目名称:OJ,代码行数:15,代码来源:1242_nth_item_of_Fibonacci.cpp
示例14: pow
mat pow(mat A, ll n)
{
mat B(A.size(),vec(A.size()));
for(int i=0;i<A.size();i++)
{
B[i][i]=1ll;
}
while(n>0)
{
if(n&1)B = mul(B,A);
A = mul(A,A);
n >>= 1;
}
return B;
}
开发者ID:okuraofvegetable,项目名称:Library-for-PCK,代码行数:15,代码来源:matrix.cpp
示例15: mul
mat mul(mat &A,mat &B)
{
mat C(A.size(),vec(B[0].size()));
for(int i=0;i<A.size();i++)
{
for(int k=0;k<B.size();k++)
{
for(int j=0;j<B[0].size();j++)
{
C[i][j]=(C[i][j]+A[i][k]*B[k][j])%MOD;
}
}
}
return C;
}
开发者ID:okuraofvegetable,项目名称:Library-for-PCK,代码行数:15,代码来源:matrix.cpp
示例16: pow
mat pow(mat A, LL n)
{
int i, j;
mat B(A.size(), vec(A.size()));
for(i = 0; i < A.size(); i++)
B[i][i] = 1;
while(n > 0)
{
if(n&1)
B = mul(B, A);
A = mul(A, A);
n = n >> 1;
}
return B;
}
开发者ID:yjwudi,项目名称:oj,代码行数:15,代码来源:3734.cpp
示例17: GenoStd
mat FMRLasso::GenoStd(mat& geno)
{
assert(geno.n_rows == mN);
assert(geno.n_cols == mP);
double q;
for ( unsigned int j = 0; j < mP; j++)
{
q = sum(geno.col(j)) / (2.0 * mN); // BE CAREFUL FOR A VECTOR 0 INDEX
//cout << q << endl;
geno.col(j) = (geno.col(j) - 2.0 * q) / sqrt(2.0 * q * (1.0 - q));
}
return geno;
}
开发者ID:lukelloydjones,项目名称:LMLR,代码行数:15,代码来源:fmr_lasso.cpp
示例18: covarianceGradient
void ConstantCF::covarianceGradient(mat& grad, const int parameterNumber, const mat& X) const
{
assert(parameterNumber == 0);
Transform* t = getTransform(parameterNumber);
double gradientTransform = t->gradientTransform(getParameter(parameterNumber));
switch(parameterNumber)
{
case 0 :
{
grad = gradientTransform * ones(X.rows(), X.rows());
}
}
}
开发者ID:abdullah38rcc,项目名称:swarmlabatwork,代码行数:15,代码来源:ConstantCF.cpp
示例19: traduceD
void tlin::traduceD(const mat &m, SuperMatrix *&A)
{
int rows = m.rows(), cols = m.cols();
if (!A)
allocD(A, rows, cols);
int lda;
double *Avalues = 0;
readDN(A, lda, Avalues);
assert(A->nrow == rows && A->ncol == cols && lda == rows);
memcpy(Avalues, m.values(), rows * cols * sizeof(double));
}
开发者ID:ArseniyShestakov,项目名称:opentoonz,代码行数:15,代码来源:tlin_superlu_wrap.cpp
示例20: useObservations
void SeqOls::useObservations(mat X, mat Y // A n x p matrix with n responses,
// one response per row
) {
if (X.size() != Y.size()) {
cout << " The predictor/response matrices should have the same size";
cout << endl;
}
n = X.n_rows;
p = X.n_cols;
X = join_rows(X, ones(n, 1));
P = inv((X.t()) * X);
B = P * (X.t() * Y);
G = inv(B.rows(0, p - 1));
}
开发者ID:vidalalcala,项目名称:sopt-ols,代码行数:15,代码来源:seqols.cpp
注:本文中的mat类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论