Skip to content

Commit

Permalink
poisson cleanup (Bears-R-Us#3280)
Browse files Browse the repository at this point in the history
* small updates found from team code share / knowledge transfer

* missed a spot

---------

Co-authored-by: Tess Hayes <stress-tess@users.noreply.github.com>
  • Loading branch information
stress-tess and stress-tess authored Jun 4, 2024
1 parent ace1e32 commit 0ceb566
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
10 changes: 4 additions & 6 deletions PROTO_tests/tests/random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ def test_poisson_hypothesis_testing(self):
sample = rng.poisson(lam=lam, size=num_samples)
count_dict = Counter(sample.to_list())

# the sum of exp freq must be within 1e-08, so use the cdf to find out how many
# elements we need to ensure we're within that tolerance
tol = 1e-09
num_elems = 5
while (1 - sp_stats.poisson.cdf(num_elems, mu=lam)) > tol:
num_elems += 5
# the sum of exp freq and obs freq must be within 1e-08, so we use
# the isf (inverse survival function where survival function is 1-cdf) to
# find out how many elements we need to ensure we're within that tolerance
num_elems = int(sp_stats.poisson.isf(1e-09, mu=lam))

obs_counts = np.array([0] * num_elems)
for k, v in count_dict.items():
Expand Down
8 changes: 4 additions & 4 deletions src/RandMsg.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ module RandMsg
// I hate the code duplication here but it's not immediately obvious to me how to avoid it
if isSingleLam {
const lam = lamStr:real;
// using nested coforall over locales and tasks so we know how to generate taskSeed
for loc in Locales do on loc {
// using nested coforalls over locales and tasks so we know how to generate taskSeed
coforall loc in Locales do on loc {
const generatorIdxOffset = here.id * nTasksPerLoc,
locSubDom = poissonArr.localSubdomain(), // the chunk that this locale needs to handle
indicesPerTask = locSubDom.size / nTasksPerLoc; // the number of elements each task needs to handle
Expand All @@ -610,8 +610,8 @@ module RandMsg
else {
st.checkTable(lamStr);
const lamArr = toSymEntry(getGenericTypedArrayEntry(lamStr, st),real).a;
// using nested coforall over locales and task so we know exactly how many generators we need
for loc in Locales do on loc {
// using nested coforalls over locales and task so we know exactly how many generators we need
coforall loc in Locales do on loc {
const generatorIdxOffset = here.id * nTasksPerLoc,
locSubDom = poissonArr.localSubdomain(), // the chunk that this locale needs to handle
indicesPerTask = locSubDom.size / nTasksPerLoc; // the number of elements each task needs to handle
Expand Down
10 changes: 4 additions & 6 deletions tests/random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,10 @@ def test_poisson_hypothesis_testing(self):
sample = rng.poisson(lam=lam, size=num_samples)
count_dict = Counter(sample.to_list())

# the sum of exp freq must be within 1e-08, so use the cdf to find out how many
# elements we need to ensure we're within that tolerance
tol = 1e-09
num_elems = 5
while (1 - sp_stats.poisson.cdf(num_elems, mu=lam)) > tol:
num_elems += 5
# the sum of exp freq and obs freq must be within 1e-08, so we use
# the isf (inverse survival function where survival function is 1-cdf) to
# find out how many elements we need to ensure we're within that tolerance
num_elems = int(sp_stats.poisson.isf(1e-09, mu=lam))

obs_counts = np.array([0] * num_elems)
for k, v in count_dict.items():
Expand Down

0 comments on commit 0ceb566

Please sign in to comment.