[mlpack-git] [mlpack/mlpack] Adds a GammaDistribution object for estimating gamma parameters (#729)

Ryan Curtin notifications at github.com
Thu Jul 21 23:15:48 EDT 2016


> +  // Use boost's definitions of digamma and tgamma, and std::log.
> +  using boost::math::digamma;
> +  using boost::math::trigamma;
> +  using std::log;
> +
> +  // Allocate space for alphas and betas (Assume independent rows).
> +  alpha.set_size(fittingSet.n_rows);
> +  beta.set_size(fittingSet.n_rows);
> +
> +  // Treat each dimension (i.e. row) independently.
> +  for (size_t row = 0; row < fittingSet.n_rows; ++row)
> +  {
> +    // Calculate log(mean(x)) and mean(log(x)) required for fitting process.
> +    const double meanLogx = arma::mean(arma::log(fittingSet.row(row)));
> +    const double meanx = arma::mean(fittingSet.row(row));
> +    const double logMeanx = std::log(arma::mean(meanx));

Hm, if you are willing to pay a little more memory to calculate the means of each dimension all at once, instead of one row at a time, I think that you can get some speedup here, since row-wise access is suboptimal (but accessing the full matrix to calculate the mean should be fine).  Then inside this loop where you estimate parameters for each dimension, you could just use the relevant mean/log-mean/mean-log from the vector that was calculated.

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/pull/729/files/ee69680e03696c9abde8e722afb5babe6fab9a36#r71821784
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20160721/139fa967/attachment-0001.html>


More information about the mlpack-git mailing list