本文整理汇总了C++中arma::mat::is_finite方法的典型用法代码示例。如果您正苦于以下问题:C++ mat::is_finite方法的具体用法?C++ mat::is_finite怎么用?C++ mat::is_finite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::mat
的用法示例。
在下文中一共展示了mat::is_finite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
void
HMM::cacheProbabilities(const arma::mat & data) {
for (unsigned int i = 0; i < N_; ++i) {
arma::vec weights = BModels_[i].getWeights();
for (unsigned int l = 0; l < weights.n_elem; ++l) {
const GM & gm = BModels_[i].getGM(l);
gammaLts_[i].col(l) = weights(l) * arma::trans(gm.getDataProb(data));
}
B_.col(i) = arma::sum(gammaLts_[i],1);
}
if (!B_.is_finite()) {
//B_.print("B");
for (unsigned int i = 0; i < N_; ++i) {
arma::vec test = B_.col(i);
if (!test.is_finite()) {
arma::vec weights = BModels_[i].getWeights();
for (unsigned l = 0; l < weights.n_elem; ++l) {
arma::vec test2 = gammaLts_[i].col(l);
if (!test2.is_finite()) {
const GM & gm = BModels_[i].getGM(l);
gm.print("gm");
arma::vec test3 = arma::trans(gm.getDataProb(data));
//test3.print("test3");
}
}
}
}
throw std::runtime_error("probabilities not finite");
}
}
示例2: sanityCheck
/** For debugging reasons*/
bool sanityCheck() const {
bool sane = false;
if (D_ == 0 || arma::det(sigma_) == 0 || !invSigma_.is_finite()) sane = false;
if (!sane) {
std::cout << "coeff: " << coeff_ << std::endl;
std::cout << "D: " << D_ << std::endl;
sigma_.print("sigma");
invSigma_.print("invSigma");
throw std::logic_error("Something is wrong with the GM");
}
return sane;
}
示例3: optCoef
unsigned int optCoef(arma::mat& weights, const arma::icube& obs, const arma::cube& emission,
const arma::mat& initk, const arma::cube& beta, const arma::mat& scales, arma::mat& coef,
const arma::mat& X, const arma::ivec& cumsumstate, const arma::ivec& numberOfStates,
int trace) {
int iter = 0;
double change = 1.0;
while ((change > 1e-10) & (iter < 100)) {
arma::vec tmpvec(X.n_cols * (weights.n_rows - 1));
bool solve_ok = arma::solve(tmpvec, hCoef(weights, X),
gCoef(obs, beta, scales, emission, initk, weights, X, cumsumstate, numberOfStates));
if (solve_ok == false) {
return (4);
}
arma::mat coefnew(coef.n_rows, coef.n_cols - 1);
for (unsigned int i = 0; i < (weights.n_rows - 1); i++) {
coefnew.col(i) = coef.col(i + 1) - tmpvec.subvec(i * X.n_cols, (i + 1) * X.n_cols - 1);
}
change = arma::accu(arma::abs(coef.submat(0, 1, coef.n_rows - 1, coef.n_cols - 1) - coefnew))
/ coefnew.n_elem;
coef.submat(0, 1, coef.n_rows - 1, coef.n_cols - 1) = coefnew;
iter++;
if (trace == 3) {
Rcout << "coefficient optimization iter: " << iter;
Rcout << " new coefficients: " << std::endl << coefnew << std::endl;
Rcout << " relative change: " << change << std::endl;
}
weights = exp(X * coef).t();
if (!weights.is_finite()) {
return (5);
}
weights.each_row() /= sum(weights, 0);
}
return (0);
}