Skip to content

Allow sampling a PowerLaw over negative domain for even powers #3859

@gonuke

Description

@gonuke

Description

I recently encountered the same bug identified in #3541, which was ultimately resolved by #3542, which tests to ensure that the domain was always positive valued.

This seems overly restrictive since sampling even powers over negative domains is well-defined and may even be useful, e.g. sampling cosine of a scattering angle. Admittedly, sampling odd powers over negative domains is not well-posed because it requires some constant offset to ensure that the PDF is always non-negative in the negative domain, which is outside the scope of the current power law.

Perhaps allowing negative domains in some cases and not in others is a little confusing, but I'd advocate for it. This can be accomplished by changes to c++ that capture when the sample is landing in the negative part of the domain and handle it properly.

Note: the documentation for PowerLaw does not indicate the current limitation.

Alternatives

It may be possible (?) for users to break the PDF into a positive part and a negative part, sample between them, and then sample the negative part as if it was positive and flip the sign of the result.

Compatibility

This will not change the API but will allow it to be used in a broader range of cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions