本文整理汇总了C++中Visualizer::thread方法的典型用法代码示例。如果您正苦于以下问题:C++ Visualizer::thread方法的具体用法?C++ Visualizer::thread怎么用?C++ Visualizer::thread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Visualizer
的用法示例。
在下文中一共展示了Visualizer::thread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sgd
// [[Rcpp::export]]
arma::mat sgd(arma::mat& coords,
arma::ivec& targets_i, // vary randomly
arma::ivec& sources_j, // ordered
arma::ivec& ps, // N+1 length vector of indices to start of each row j in vector is
arma::vec& weights, // w{ij}
const double& gamma,
const double& rho,
const arma::uword& n_samples,
const int& M,
const double& alpha,
const Rcpp::Nullable<Rcpp::NumericVector> momentum,
const bool& useDegree,
const Rcpp::Nullable<Rcpp::NumericVector> seed,
const Rcpp::Nullable<Rcpp::NumericVector> threads,
const bool verbose) {
#ifdef _OPENMP
checkCRAN(threads);
#endif
const dimidxtype D = coords.n_rows;
const vertexidxtype N = coords.n_cols;
const edgeidxtype E = targets_i.n_elem;
Visualizer* v;
if (momentum.isNull()) v = new Visualizer(
sources_j.memptr(), targets_i.memptr(), coords.memptr(),
D, N, E,
rho, n_samples,
M, alpha, gamma);
else {
float moment = NumericVector(momentum)[0];
if (moment < 0) throw Rcpp::exception("Momentum cannot be negative.");
if (moment > 0.95) throw Rcpp::exception("Bad things happen when momentum is > 0.95.");
v = new MomentumVisualizer(
sources_j.memptr(), targets_i.memptr(), coords.memptr(),
D, N, E,
rho, n_samples, moment,
M, alpha, gamma);
}
distancetype* negweights = new distancetype[N];
std::fill(negweights, negweights + N, 0);
if (useDegree) {
std::for_each(targets_i.begin(), targets_i.end(), [&negweights](const sword& e) {negweights[e]++;});
} else {
for (vertexidxtype p = 0; p < N; ++p) {
for (edgeidxtype e = ps[p]; e != ps[p + 1]; ++e) {
negweights[p] += weights[e];
}
}
}
std::for_each(negweights, negweights + N, [](distancetype& weight) {weight = pow(weight, 0.75);});
v -> initAlias(weights.memptr(), negweights, seed);
delete[] negweights;
const uword batchSize = BATCHSIZE;
#ifdef _OPENMP
const unsigned int ts = omp_get_max_threads();
#else
const unsigned int ts = 2;
#endif
Progress progress(max((uword) ts, n_samples / BATCHSIZE), verbose);
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (unsigned int t = 0; t < ts; ++t) {
v->thread(progress, batchSize);
}
delete v;
return coords;
}