Skip to content
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

Add ShotNoise CPU and GPU operators #2861

Merged
merged 6 commits into from
Apr 26, 2021

Conversation

jantonguirao
Copy link
Contributor

@jantonguirao jantonguirao commented Apr 13, 2021

Signed-off-by: Joaquin Anton janton@nvidia.com

Why we need this PR?

Pick one, remove the rest

  • It adds a new feature needed because to produce apply random shot noise to data

What happened in this PR?

Fill relevant points, put NA otherwise. Replace anything inside []

  • What solution was applied:
    Implemented noise.shot based on the existing template for noise generators.
  • Affected modules and functionalities:
    New functionality
  • Key points relevant for the review:
    All
  • Validation and testing:
    Tests added
  • Documentation (including examples):
    Docstr

JIRA TASK: [DALI-1946] [DALI-1947]

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao jantonguirao changed the title [WIP] Add ShotNoise CPU and GPU operators Add ShotNoise CPU and GPU operators Apr 21, 2021
Signed-off-by: Joaquin Anton <janton@nvidia.com>

output[i] = denormalize(poisson_dist(normalize(input[:]) * peak) / peak)

where ``normalize`` and ``denormalize`` represent scaling to the range [-1, 1] and back to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poisson noise is unsigned - if so, then why do we have the [-1,1] range? Also - do we want to do something with negative values? (e.g. produce a noisy value from the absolute and copysign?).

DALI_HOST_DEV inline T operator()(T in_val, Generator& g) {
float norm = ConvertNorm<float>(in_val);
Dist dist(peak_ * norm);
return ConvertSatNorm<T>(dist(g) / peak_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store the reciprocal and multiply here.

Suggested change
return ConvertSatNorm<T>(dist(g) / peak_);
return ConvertSatNorm<T>(dist(g) * ipeak_);

std::poisson_distribution<uint32_t>>;

DALI_HOST_DEV explicit shot_noise_impl(float peak = 12)
: peak_{peak} {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: peak_{peak} {}
: peak_(peak), ipeak(1/peak) {}

Nitpick: following my advisor's recommendation - I think that such simple initialization can be expressed more naturally by plain assignment.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Comment on lines 31 to 35
The factor can be interpreted as the number of event registrations (modeled by the poisson distribution)
are required to increase the output value by 1. For example, a factor of 0.1 means we need the
10 events to increase the output by 1, while a factor of 10 means that a single event
increases the output by 10. The higher the factor, the more noise will be applied to the data.
A factor of 0 translates to an identity operation.
Copy link
Contributor

@mzient mzient Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description is inaccurate (it's for the 1/factor). Also, perhaps we should define what a shot noise is?

Suggested change
The factor can be interpreted as the number of event registrations (modeled by the poisson distribution)
are required to increase the output value by 1. For example, a factor of 0.1 means we need the
10 events to increase the output by 1, while a factor of 10 means that a single event
increases the output by 10. The higher the factor, the more noise will be applied to the data.
A factor of 0 translates to an identity operation.
Shot noise is a noise that's present in data generated by a Poisson process, like
registering photons by an image sensor. This operator simulates the data
acquisition process where each event increases the output value by
``factor`` and the input tensor contains the expected values of corresponding
output points. For example, a ``factor`` of 0.1 means that each 10 events are
needed to increase the output value by 1, while a factor of 10 means that
a single event increases the output by 10. The output values are quantized
to multiples of ``factor``. The larger the factor, the more noise is present in
the output. A factor of 0 makes this an identity operation.

Optionally, we can add a line saying that

The values in the input must be of the same sign as the factor.

but I'm not sure if we really need to write that - an inquisitive reader should discover that on their own.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2299238]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2299238]: BUILD PASSED

@jantonguirao jantonguirao merged commit 16bdf09 into NVIDIA:master Apr 26, 2021
@JanuszL JanuszL mentioned this pull request May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants