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 gradient to uniform distribution #526

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cuqi/distribution/_uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __init__(self, low=None, high=None, is_symmetric=True, **kwargs):
self.high = high

def logpdf(self, x):
"""
Evaluate the logarithm of the PDF at the given values of x.
"""
# First check whether x is outside bounds.
# It is outside if any coordinate is outside the interval.
if np.any(x < self.low) or np.any(x > self.high):
Expand All @@ -38,6 +41,13 @@ def logpdf(self, x):
return_val = np.log(1.0/v)
return return_val

def gradient(self, x):
"""
Computes the gradient of logpdf at the given values of x.
"""
# x accepts scalar, list, tuple, or ndarray
return np.zeros_like(x)
nabriis marked this conversation as resolved.
Show resolved Hide resolved

def _sample(self,N=1, rng=None):

if rng is not None:
Expand Down
Loading