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

Ensure posterior predictive samples have the proper type #3683

Merged
merged 3 commits into from
Nov 25, 2019

Conversation

aloctavodia
Copy link
Member

@aloctavodia aloctavodia commented Nov 18, 2019

this is the actual line I changed https://github.com/pymc-devs/pymc3/pull/3683/files#diff-7eb6c4a83cfe45b9fc0eac76b57e2175R1171, the rest is black. I can revert black if you want.

@codecov
Copy link

codecov bot commented Nov 18, 2019

Codecov Report

Merging #3683 into master will increase coverage by 0.09%.
The diff coverage is 78.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3683      +/-   ##
==========================================
+ Coverage   89.82%   89.91%   +0.09%     
==========================================
  Files         134      134              
  Lines       20133    20194      +61     
==========================================
+ Hits        18084    18157      +73     
+ Misses       2049     2037      -12
Impacted Files Coverage Δ
pymc3/tests/test_sampling.py 99.54% <100%> (+0.01%) ⬆️
pymc3/sampling.py 83.09% <74.19%> (ø) ⬆️
pymc3/tests/test_distributions_random.py 99.13% <0%> (-0.14%) ⬇️
pymc3/tests/test_util.py 100% <0%> (ø) ⬆️
pymc3/ode/utils.py 100% <0%> (ø) ⬆️
pymc3/ode/ode.py 93.75% <0%> (ø) ⬆️
pymc3/tests/test_ode.py 100% <0%> (ø) ⬆️
pymc3/exceptions.py 100% <0%> (ø) ⬆️
pymc3/distributions/timeseries.py 71.65% <0%> (+11.9%) ⬆️

@canyon289
Copy link
Member

This LGTM. I can add a test sometime this week if you'd like.

else:
value_shape = ()

# initialize if necessary
if k not in self.trace_dict:
array_shape = (self._len,) + value_shape
self.trace_dict[k] = np.full(array_shape, np.nan)
self.trace_dict[k] = np.zeros(array_shape, dtype=np.array(v).dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we keep nan as the default value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't the arrays in trace_dict supposed to be completely filled with the posterior predictive samples? Then the filler value would have no relevance at all. In this case, I think the situation would be np.empty ideal usecase.

Copy link
Member Author

@aloctavodia aloctavodia Nov 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing because nan are floats so if trace_dict is filled with integers they will be upcasted to floats.

The default value for empty is also float so we should specify the dtype as with zeros. It seems to me that using empty of zeros is basically the same, unless using emptyis preferred because it conveys the idea that the initial values are irrelevant and they will be completetelly replaced. @OriolAbril Is that the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to everything, the dtype must be specified and empty only allocates the memory that will be occupied by the array so the user can fill the array afterwards without problems (the values of the array may or may not actually be zeros, it depends on what was stored there before).

Moreover, just for the record because this array allocation is far from being a bottleneck, empty also leaves the actual memory untouched, thus empty is much faster than zeros or full.

@aloctavodia aloctavodia merged commit 6ccc75d into pymc-devs:master Nov 25, 2019
@aloctavodia aloctavodia deleted the sampling branch November 25, 2019 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants