-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Conversation
9ee1b6e
to
5733e78
Compare
produces output of dimension *n+1* such that each *n*-dimensional index *i* | ||
in the output array holds the PDFs of the samples at index *i* in *sample*, | ||
parameterized by the values of *low* and *high* at index *i*. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A special case is that sample is also an n-dimensional tensor which means that we have exactly one sample per distribution. In that case, the output will also be an n-dimensional tensor. I think the code does (and should) support this and that this is an important use case. So should be documented here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Called that out explicitly.
src/operator/random/pdf_op.cc
Outdated
|
||
Examples:: | ||
|
||
random_pdf_uniform(sample=[[1,2,3,4]], low=[0], high=[10]) = [0.1 0.1 0.1 0.1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commas missing in the output array.
|
||
random_pdf_exponential(sample=[[1, 2, 3]], lam=[1]) = | ||
[[0.36787945 0.13533528 0.04978707]] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have consistent types of examples for all distributions.
- single distribution, multiple samples
- multiple distributions, multiple samples
- multiple distributions, single sample per distribution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added second examples for the exponential and Dirichlet.
src/operator/random/pdf_op.h
Outdated
bool is_log; | ||
DMLC_DECLARE_PARAMETER(PdfParam) { | ||
DMLC_DECLARE_FIELD(is_log).set_default(false) | ||
.describe("Whether to compute the log PDF or not."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be that can be phrased a bit better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's now "If set, compute the density of the log-probability instead of the probability."
template<typename DType, typename IType1, typename IType2> | ||
MSHADOW_XINLINE static void Map(int start, int length, int sample_size, int index, | ||
DType *out, IType1 *sample, IType2 *lower, IType2 *upper) { | ||
const DType l(lower[index]), h(upper[index]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providing "index" to this and all similar functions below is redundant. According to the processing in LaunchExWrapper it always hold that index == start/sample_size. Still we may want to keep "index" as an explicit parameter for clarity. So o.k. with either choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's gone.
Should be noted that this PR allows to compute log-pdf and pdf. And that it also adds pdf of Dirichlet distribution which does not yet exist in MXNet. |
This addresses several requests from issue #12932 |
)code"); | ||
} | ||
|
||
inline std::string dirichlet_desc() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have a function to draw samples from a dirichlet distribution? this only computes the pdf of the distribution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. Sampler does not exist yet. As by my previous comments, we should add it. We may have the bandwidth to do so in our team (and actually will need it). But we should not make existence of a sampler be a conditional to this PR as having the PDF is beneficial by itself (and we are using it already in a project).
My hope is that by adding serious functionality to the random-namespace in MXNet, we get more people interested (for example supplying also CDF etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the commit message to clarify that, unlike the other distributions, we don't have a Dirichlet sampler yet.
Is this PR pointing against the 1.3 branch on purpose? |
a2e601c
to
971ae83
Compare
@david-seiler Seems like you want to add a particular feature to a previous version of MXNet.
@mxnet-label-bot Add [pr-awaiting-review, operator] |
I started with 1.3.x because it's what we're using internally (for now); I'll close this in favor of a new PR against master once I've updated to build against master and addressed the rest of the review comments. |
…r (plus also the PDF of the Dirichlet). Supports probabilities and log-probabilities, as well as gradients.
This PR now correctly targets master -- still from a branch named v1.3.x on my side, since I couldn't see how to reset that, but that branch now follows apache:master with this one commit on top. Sorry for the confusion, but it seems better on net than throwing away the existing conversation. |
The tests in Jenkins have been stuck ever single I switched this PR to master, and I haven't found a way to unstick them, so please join me in a new PR of the same code: #14617 All the comments from this PR should be addressed there. |
Description
This PR adds operators for computing the densities of samples drawn from any of the various distributions defined in operator/random, as well as their gradients. There are lots of changes to test_random.py to test each PDF alongside its distribution; aside from that, the patch should be entirely stand-alone. See pdf_op.cc for more-detailed description strings.
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.