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

Added a flag to specify vectorized theory function #21

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
28 changes: 10 additions & 18 deletions src/pspec_likelihood/likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
bias_prior,
kbin_centers,
kbin_widths,
theoretical_model_vectorized=False,
little_h=True,
weight_by_cov=True,
history="",
Expand Down Expand Up @@ -70,6 +71,8 @@ def __init__(
The nuisance model is defined in data space
and can be treaded as the bias term in
\hat{p} = W p_true + b
theoretical_model_vectorized: bool
specifies whether the theoretical model accepts numpy-vectors for k and z.
little_h
specifies whether k units are in h/Mpc or 1/Mpc
bias_prior : func(params) -> prob
Expand Down Expand Up @@ -139,8 +142,7 @@ def discretized_ps(self, spw, theory_params, little_h=True, method=None):
redshifts are determined by the spherical windows (spw).

Possible methods: Just evaluate the power spectrum at the bin centers,
integrate over the power spectrum to take the bin average, or
evaluate at the bin edges (+ center?) and return the mean.
or integrate over the power spectrum to take the bin average.

Parameters
----------
Expand All @@ -156,29 +158,19 @@ def discretized_ps(self, spw, theory_params, little_h=True, method=None):
results
list of power spectrum values corresponding to the bins
errors
Estimation of the error through binning, if a suitable method has been
chosen, otherwise None.
Integration error if a suitable method has been chosen, otherwise None.
"""

#Todo: Mapping from spw to (one/many) redshift(s), see also issue #3
z = self.get_z_from_spw(spw)

# Q: Is little_h a keyword argument of theory_func?
# Q: Does the bin go from center-width/2 to center+width/2 ?
# The error is just an order of magnitude, not any precise confidence interval.
# If the power spectrum was monotonous, the error would be the maximal deviation.
#Todo: Implement an efficient wrapper in case
# theoretical_model_vectorized==False

if method == "bin_center":
results = self.theoretical_model(
self.kbin_centers, z, little_h, theory_params
)
elif method == "two_point":
lower = self.theoretical_model(
self.kbin_centers - self.kbin_widths / 2, z, little_h, theory_params
)
upper = self.theoretical_model(
self.kbin_centers + self.kbin_widths / 2, z, little_h, theory_params
)
results = (lower + upper) / 2
errors = (lower - upper) / 2
elif method == "integrate":

def pk_func(k):
Expand All @@ -192,7 +184,7 @@ def pk_func(k):
errors.append(error / width)
else:
raise ValueError(
f"method must be one of 'bin_center', 'two_point' or 'integrate'. Got '{method}'."
f"method must be one of 'bin_center' or 'integrate'. Got '{method}'."
)

return results, errors
Expand Down