<p>In <a href="https://github.com/mlpack/mlpack/pull/751#discussion_r73780816">src/mlpack/core/dists/gamma_distribution.cpp</a>:</p>
<pre style='color:#555'>&gt; @@ -53,6 +64,13 @@ void GammaDistribution::Train(const arma::mat&amp; rdata, const double tol)
&gt;    Train(logMeanxVec, meanLogxVec, meanxVec, tol);
&gt;  }
&gt;  
&gt; +// Fits an alpha and beta parameter according to observation probabilities.
&gt; +void GammaDistribution::Train(const arma::mat&amp; observations, 
&gt; +                              const arma::vec&amp; probabilities,
&gt; +                              const double tol)
&gt; +{
</pre>
<p>Here's an idea for this.  The idea is that we are training the distribution, but we do not know for certain that the points we are training on came from this distribution---we only have an estimate between 0 and 1 of how likely we think it is that the point came from this distribution.  So we can train using the probabilities as weights.</p>

<p>We can use each of the probabilities to construct a "weighted" version of <code>meanLogxVec</code>, <code>meanxVec</code>, and <code>logMeanxVec</code>.  This means we can't use Armadillo's nice syntax though since we have to implement this ourselves.</p>

<pre><code>arma::vec meanLogxVec(rdata.n_rows, arma::fill::zeros);
arma::vec meanxVec(rdata.n_rows, arma::fill::zeros);
arma::vec logMeanxVec(rdata.n_rows, arma::fill::zeros);

for (size_t i = 0; i &lt; rdata.n_cols; ++i)
{
  meanLogxVec += probabilities(i) * std::log(rdata.col(i));
  meanxVec += probabilities(i) * rdata.col(i);
}
meanLogxVec /= arma::accu(probabilities);
meanxVec /= arma::accu(probabilities);
logMeanxVec = arma::log(meanxVec);

Train(logMeanxVec, meanLogxVec, meanxVec, tol);
</code></pre>

<p>What do you think?</p>

<p>Testing that could be done by generating points from a Gamma distribution, assigning them a random weight between, e.g., 0.9 and 1, and then generating points from a uniform distribution, and assigning those points a random weight between, e.g, 0.0 and 0.02.  Then, call Train() with probabilities, and ensure the resulting trained Gamma distribution is close to the distribution that was used to generate points.</p>

<p>What do you think?  I've only outlined ideas here, but I can implement them if you need.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/mlpack/mlpack/pull/751/files/9cb117f671f55186baddf38ce71107a2a3ae027f#r73780816">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJ4bFIzJjZgwkoDPkm5QiB8lrYp6yjshks5qdBHBgaJpZM4Jd7IK">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFAcZ5m6xOFNTtp_kTPS6H3Wlzw5oks5qdBHBgaJpZM4Jd7IK.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/751/files/9cb117f671f55186baddf38ce71107a2a3ae027f#r73780816"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/mlpack/mlpack","title":"mlpack/mlpack","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/modules/aws/aws-bg.jpg","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/mlpack/mlpack"}},"updates":{"snippets":[{"icon":"PERSON","message":"@rcurtin in #751: Here's an idea for this.  The idea is that we are training the distribution, but we do not know for certain that the points we are training on came from this distribution---we only have an estimate between 0 and 1 of how likely we think it is that the point came from this distribution.  So we can train using the probabilities as weights.\r\n\r\nWe can use each of the probabilities to construct a \"weighted\" version of `meanLogxVec`, `meanxVec`, and `logMeanxVec`.  This means we can't use Armadillo's nice syntax though since we have to implement this ourselves.\r\n\r\n```\r\narma::vec meanLogxVec(rdata.n_rows, arma::fill::zeros);\r\narma::vec meanxVec(rdata.n_rows, arma::fill::zeros);\r\narma::vec logMeanxVec(rdata.n_rows, arma::fill::zeros);\r\n\r\nfor (size_t i = 0; i \u003c rdata.n_cols; ++i)\r\n{\r\n  meanLogxVec += probabilities(i) * std::log(rdata.col(i));\r\n  meanxVec += probabilities(i) * rdata.col(i);\r\n}\r\nmeanLogxVec /= arma::accu(probabilities);\r\nmeanxVec /= arma::accu(probabilities);\r\nlogMeanxVec = arma::log(meanxVec);\r\n\r\nTrain(logMeanxVec, meanLogxVec, meanxVec, tol);\r\n```\r\n\r\nWhat do you think?\r\n\r\nTesting that could be done by generating points from a Gamma distribution, assigning them a random weight between, e.g., 0.9 and 1, and then generating points from a uniform distribution, and assigning those points a random weight between, e.g, 0.0 and 0.02.  Then, call Train() with probabilities, and ensure the resulting trained Gamma distribution is close to the distribution that was used to generate points.\r\n\r\nWhat do you think?  I've only outlined ideas here, but I can implement them if you need."}],"action":{"name":"View Pull Request","url":"https://github.com/mlpack/mlpack/pull/751/files/9cb117f671f55186baddf38ce71107a2a3ae027f#r73780816"}}}</script>