QInfer / python-qinfer

Library for Bayesian inference via sequential Monte Carlo for quantum parameter estimation.
BSD 3-Clause "New" or "Revised" License
92 stars 31 forks source link

Simple Estimation Functions example problem #142

Closed omarshehab closed 6 years ago

omarshehab commented 6 years ago

Should it be ts = np.arange(1, 51) / (2.0 * omega_max) instead of ts = np.arange(1, 51) / (2 * omega_max) in the Simple Estimation Functions example?

I thought the elements in ts should not be always zero.

ihincks commented 6 years ago

Hi @omarshehab. The short answer is that, yes, you are right. The long answer is that---due to the explanation below---it's fine the way it is, you are just missing something like from __future__ import division at the top of your file.

In python 2, the default behavior when dividing integers is to floor the output and return an integer. In python 3, the default is to return a float. The latter behavior is what most scientific users expect, and therefore, it is common to force the python 3 behavior using from __future__ import division.

If you cast the denominator to a float, as you have done by using 2.0, a float is returned in both python 2 and 3. I don't like this as much because if I forget to add the .0 or float(2), it can cause some seriously confusing bugs.

ihincks commented 6 years ago

For what it's worth, I like np.linspace(0, 2*omega_max, 51)[1:] better, anyway.