-
Notifications
You must be signed in to change notification settings - Fork 11
gh-486: run individual iternorms
on ell blocks
#591
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
Draft
Saransh-cpp
wants to merge
2
commits into
main
Choose a base branch
from
saransh/blocked-iternorm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -345,7 +345,7 @@ def _generate_grf( | |
gls: Cls, | ||
nside: int, | ||
*, | ||
ncorr: int | None = None, | ||
ncorrs: list[int] | None = None, | ||
rng: np.random.Generator | None = None, | ||
) -> Generator[NDArray[np.float64]]: | ||
""" | ||
|
@@ -390,43 +390,62 @@ def _generate_grf( | |
ngls = len(gls) | ||
ngrf = nfields_from_nspectra(ngls) | ||
|
||
# number of correlated fields if not specified | ||
if ncorr is None: | ||
ncorr = ngrf - 1 | ||
|
||
# number of modes | ||
n = max((len(gl) for gl in gls), default=0) | ||
if n == 0: | ||
msg = "all gls are empty" | ||
raise ValueError(msg) | ||
|
||
# generates the covariance matrix for the iterative sampler | ||
cov = cls2cov(gls, n, ngrf, ncorr) | ||
|
||
# working arrays for the iterative sampling | ||
z = np.zeros(n * (n + 1) // 2, dtype=np.complex128) | ||
y = np.zeros((n * (n + 1) // 2, ncorr), dtype=np.complex128) | ||
|
||
blocks = [] | ||
block_ns = [] | ||
for j in range(len(gls)): | ||
block = [gls[i][j : j + 1] for i in range(j, len(gls))] | ||
blocks.append(block) | ||
block_ns.append(len(gls) - j) | ||
|
||
# number of correlated fields if not specified | ||
if ncorrs is None: | ||
ncorrs = [ngrf - 1 for _ in range(len(blocks))] | ||
|
||
# generate the conditional normal distribution for iterative sampling | ||
conditional_dist = iternorm(ncorr, cov, size=n) | ||
conditional_dists = [] | ||
for block, block_n, block_ncorr in zip(blocks, block_ns, ncorrs, strict=True): | ||
# generate the covariance matrix of this block for the iterative sampler | ||
block_cov = cls2cov(block, block_n, ngrf, block_ncorr) | ||
# generate the conditional normal distribution for iterative sampling | ||
conditional_dist = iternorm(block_ncorr, block_cov, size=block_n) | ||
# store for parallel processing of all blocks | ||
conditional_dists.append(conditional_dist) | ||
|
||
# sample the fields from the conditional distribution | ||
for j, a, s in conditional_dist: | ||
for results, ncorr in zip(*conditional_dists, ncorrs, strict=True): | ||
# standard normal random variates for alm | ||
# sample real and imaginary parts, then view as complex number | ||
rng.standard_normal(n * (n + 1), np.float64, z.view(np.float64)) | ||
|
||
# concatenate individual updates into one update | ||
s = np.concatenate([block_s for _, _, block_s in results]) | ||
|
||
# scale by standard deviation of the conditional distribution | ||
# variance is distributed over real and imaginary part | ||
alm = _multalm(z, s) | ||
|
||
# add the mean of the conditional distribution | ||
y = np.zeros((n * (n + 1) // 2, ncorr), dtype=np.complex128) | ||
a = np.concatenate([block_a for _, block_a, _ in results]) | ||
for i in range(ncorr): | ||
alm += _multalm(y[:, i], a[:, i]) | ||
|
||
for i in range(ncorr): | ||
# calculate ks | ||
pass | ||
Comment on lines
+442
to
+444
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking that this should be possible. |
||
|
||
# store the standard normal in y array at the indicated index | ||
if j is not None: | ||
y[:, j] = z | ||
if results[0] is not None: | ||
y[:, results[0]] = z[k1:k2] | ||
|
||
alm = _glass_to_healpix_alm(alm) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Given that
y
is has a dimensionncorr
, should be initialised inside the loop or should it be given the dimensionncorrs
.