-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create sampler module and gaussian mixture sampling function #793
Create sampler module and gaussian mixture sampling function #793
Conversation
…an alternative method if not available
stonesoup/functions/__init__.py
Outdated
|
||
Returns | ||
------- | ||
: :class:`np.ndarray` of shape (:attr:`size`, num_dims)""" |
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.
Should return a StateVectors
type?
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 was torn with this when I wrote the function but I think you are right. Changed in latest commit.
stonesoup/sampler/base.py
Outdated
|
||
|
||
class Sampler(Base): | ||
"""Sampler base class""" |
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.
Should give a description of what a general sampler does.
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.
Description added
@@ -509,6 +509,47 @@ def rotz(theta): | |||
[zero, zero, one]]) | |||
|
|||
|
|||
def gm_sample(means, covars, size, weights=None): | |||
"""Sample from a mixture of multi-variate Gaussians | |||
|
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.
You might wish to explain how this is done, as for non-statisticians it might not be obvious. (First do a multinomial sample from the weight distribution to get the number of times you should sample from each component, then sample from those components that many times.. I think.)
Modified Sampler base class description
Just typos
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.
Only thing I'd suggest is perhaps producing/referencing a gist where you can demonstrate pictorially that the sampling happens correctly. Say create 2 overlapping Gaussian components and then plot a few thousand sample points?
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.
Looks good to me. As discussed it probably makes sense to have your DetectionSampler and GaussianDetectionParticleSampler both inheriting from a "DetectionSampler" class. Happy for that to be amended in a future PR but it may be worth renaming your DetectionSampler here if you do plan on restructuring slightly.
…oduce base DetectionSampler class
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #793 +/- ##
==========================================
+ Coverage 94.90% 94.92% +0.02%
==========================================
Files 176 183 +7
Lines 9757 9919 +162
Branches 1938 1970 +32
==========================================
+ Hits 9260 9416 +156
- Misses 353 355 +2
- Partials 144 148 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Introduced the sampler module for producing samples from distributions.
ParticleSampler
is the main class contributed for this and it accepts a callable sampling function such asnumpy.random.multivariate_normal
orscipy.stats.uniform.rvs
, and a dictionary of parameters to be used as kwargs for the callable and returns aParticleState
containing the samples.GaussianDetectionParticleSampler
is a child class ofParticleSampler
that specifically samples fromDetection
or sets ofDetection
.DetectionSampler
is a generalDetection
sampler that is able to switch between a detection based sampler object such asGaussianDetectionParticleSampler
and a non-detection backup sampler such asParticleSampler
that is used if no detections are available.No single callable has been found for sampling from Gaussian mixture distributions which lead to the introduction of
gm_sample
method instonesoup.functions
. This method can be used as a callable forParticleSampler
and is the sampler used byGaussianDetectionParticleSampler
.