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

TST: tested generate_RW. Difficult to test outputs so just looked to … #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nhuntwalker
Copy link
Contributor

…see if the mean of the output random walk is more or less centered around the input mean

…see if the mean of the output random walk is more or less centered around the input mean
@nhuntwalker nhuntwalker reopened this Jun 23, 2015
@jakevdp
Copy link
Member

jakevdp commented Jun 23, 2015

For this test, we should explicitly set a random seed (otherwise there are rare cases in which it will fail). The best way is probably to use a local seed, e.g.

# ...
rng = np.random.RandomState(0)
xmean = rng.rand()*200 - 100
N = len(t)
y = generate_damped_RW(t, tau=tau, z=z, xmean=xmean, random_state=rng)
# ...

@jakevdp
Copy link
Member

jakevdp commented Jun 23, 2015

Same goes for other tests that depend on a random state.

@nhuntwalker
Copy link
Contributor Author

Yeah I was just realizing that as I was working on a test of the lomb_scargle_bootstrap module
Edit: word

@nhuntwalker
Copy link
Contributor Author

Interesting issue. I'm trying to test astroML.time_series.multiterm_periodogram and I'm feeding it the appropriate data structures (arrays) and it's not working. Toward the end of the function, it's dying because I'm apparently trying to set an array element with a sequence. Really what's happening is the function is trying to set an array element with an empty array. Not sure why numpy.linalg.lstsq() is returning an empty array

@jakevdp
Copy link
Member

jakevdp commented Jun 23, 2015

It looks like in testing lomb_scargle_bootstrap you essentially copied the internals of the function and asserted that they were equal to the output. This is not really an effective unit test... for example, if one of the functions used by this code changes (e.g. lomb_scargle), the results will still match perfectly, but they will not be correct!

To write a unit test, you should think about what the purpose of the function is, and think about how to test that this purpose is fulfilled for a variety of inputs.

For example, here we could use very well-sampled, high signal-to-noise data and check that (1) the routine returns the correct result, and (2) the distribution returned is very narrow around this value. Then use some poorly sampled/low signal-to-noise data and confirm that the resulting distribution is much wider. I would also add a routine which tests the exact numerical output for a known input.

Base automatically changed from master to main February 24, 2021 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants