Skip to content

Commit

Permalink
test new line in docstring link
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew McCluskey committed Feb 24, 2020
1 parent 4c3ef68 commit 18bc5ea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
3 changes: 2 additions & 1 deletion uravu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Q_ = UREG.Quantity
set_application_registry(UREG)


def __version__():
"""
Return the current version of uravu.
Expand All @@ -22,4 +23,4 @@ def __version__():
major = 0
minor = 0
micro = 1
return "{}.{}.{}".format(major, minor, micro)
return "{}.{}.{}".format(major, minor, micro)
6 changes: 4 additions & 2 deletions uravu/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from uravu.distribution import Distribution


def plot_relationship(relationship, axes=None, figsize=(10, 6)): # pragma: no cover
def plot_relationship(
relationship, axes=None, figsize=(10, 6)
): # pragma: no cover
"""
Plot the relationship. Additional plots will be included on this if
the MCMC sampling has been used to find the activation_energy
Expand Down Expand Up @@ -88,7 +90,7 @@ def plot_distribution(distro, axes=None, figsize=(10, 6)): # pragma: no cover
for the plot.
"""
if axes is None:
axes = plt.subplots(figsize=figsize)[1]
axes = plt.subplots(figsize=figsize)[1]
kde = gaussian_kde(distro.samples)
abscissa = np.linspace(distro.samples.min(), distro.samples.max(), 100)
ordinate = kde.evaluate(abscissa)
Expand Down
20 changes: 15 additions & 5 deletions uravu/relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ def citations(self):
string = "Please consider citing the following:\n"
string += " - Publication of uravu (to come).\n"
string += " - Zenodo DOI for uravu version: {}\n".format(__version__())
if not np.isclose(self.variable_medians, np.ones((self.len_parameters()))).all():
if not np.isclose(
self.variable_medians, np.ones((self.len_parameters()))
).all():
string += "The scipy.optimize.minimize function was used to maximise the ln likelihood. Please consider citing:\n"
string += " - P. Virtanen, r. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, E. Burovski, P. Peterson, W. Weckesser, J. Bright, S. J. van der Walt, M. Brett, J./ Wilson, K. J. Millman, N. Mayorov, A. R. J. Nelson, E. Jones, R. Kern, E. Larson, C. Carey, I. Polat, Y. Feng, E. W. Moore, J. VanderPlas, D. Laxalde, J. Perktold, R. Cimrman, I. Henriksen, E. A. Quintero, C. R Harris, A. M. Archibald, A. H. Ribeiro, F. Pedregosa, P. van Mulbregt, & SciPy 1.0 Contributors, (2020). Nature Methods, in press. DOI: 10.1038/s41592-019-0686-2\n"
if self.mcmc_done:
Expand Down Expand Up @@ -413,10 +415,16 @@ def bayesian_information_criteria(self):
Returns:
(float): Bayesian information criteria.
"""
return np.log(self.x_n.size) * self.len_parameters() - 2 * optimize.ln_likelihood(self.variable_medians, self.function,
self.max_likelihood()
return np.log(
self.x_n.size
) * self.len_parameters() - 2 * optimize.ln_likelihood(
self.variable_medians,
self.function,
self.abscissa,
self.ordinate,
self.unaccounted_uncertainty)
self.unaccounted_uncertainty,
)

def max_likelihood(self, x0=None, **kwargs):
"""
Expand All @@ -426,7 +434,8 @@ def max_likelihood(self, x0=None, **kwargs):
Keyword Args:
See the `scipy.optimize.minimize()`_ documentation.
.. _scipy.optimize.minimize(): https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
.. _scipy.optimize.minimize(): https://docs.scipy.org/doc/scipy/
reference/generated/scipy.optimize.minimize.html
"""
self.variables = optimize.max_ln_likelihood(self, x0, **kwargs)

Expand Down Expand Up @@ -504,7 +513,8 @@ def nested_sampling(self, prior_function=None, progress=True, **kwargs):
Keyword Args:
See the `dynesty.run_nested()`_ documentation.
.. _dynesty.run_nested(): https://dynesty.readthedocs.io/en/latest/api.html#dynesty.sampler.Sampler.run_nested
.. _dynesty.run_nested(): https://dynesty.readthedocs.io/en/latest/
api.html#dynesty.sampler.Sampler.run_nested
"""
self.ln_evidence = sampling.nested_sampling(
self, prior_function=prior_function, progress=progress, **kwargs
Expand Down
25 changes: 9 additions & 16 deletions uravu/tests/test_relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@
"Nested sampling performed: False \n"
)

CITATION_A = ("Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\n")
CITATION_B = ("Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\nThe scipy.optimize.minimize function was used to maximise the ln likelihood. Please consider citing:\n - P. Virtanen, r. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, E. Burovski, P. Peterson, W. Weckesser, J. Bright, S. J. van der Walt, M. Brett, J./ Wilson, K. J. Millman, N. Mayorov, A. R. J. Nelson, E. Jones, R. Kern, E. Larson, C. Carey, I. Polat, Y. Feng, E. W. Moore, J. VanderPlas, D. Laxalde, J. Perktold, R. Cimrman, I. Henriksen, E. A. Quintero, C. R Harris, A. M. Archibald, A. H. Ribeiro, F. Pedregosa, P. van Mulbregt, & SciPy 1.0 Contributors, (2020). Nature Methods, in press. DOI: 10.1038/s41592-019-0686-2\n")
CITATION_C = ("Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\nThe scipy.optimize.minimize function was used to maximise the ln likelihood. Please consider citing:\n - P. Virtanen, r. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, E. Burovski, P. Peterson, W. Weckesser, J. Bright, S. J. van der Walt, M. Brett, J./ Wilson, K. J. Millman, N. Mayorov, A. R. J. Nelson, E. Jones, R. Kern, E. Larson, C. Carey, I. Polat, Y. Feng, E. W. Moore, J. VanderPlas, D. Laxalde, J. Perktold, R. Cimrman, I. Henriksen, E. A. Quintero, C. R Harris, A. M. Archibald, A. H. Ribeiro, F. Pedregosa, P. van Mulbregt, & SciPy 1.0 Contributors, (2020). Nature Methods, in press. DOI: 10.1038/s41592-019-0686-2\nThe emcee package was used to perform the MCMC analysis. Please consider citing:\n - D. Foreman-Mackey, W. Farr, M. Sinha, A. Archibald, D. Hogg, J. Sanders, J. Zuntz, P. Williams, A. Nelson, M. de Val-Borro, T. Erhardt, I. Pashchenko, & O. Pla, (2019). Journal of Open Source Software, 4(43), 1864. DOI: 10.21105/joss.01864\n - J. Goodman & J. Weare, (2010). Communications in applied mathematics and computational science, 5(1), 65. DOI: 10.2140/camcos.2010.5.65\n")
CITATION_D = ("Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\nThe scipy.optimize.minimize function was used to maximise the ln likelihood. Please consider citing:\n - P. Virtanen, r. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, E. Burovski, P. Peterson, W. Weckesser, J. Bright, S. J. van der Walt, M. Brett, J./ Wilson, K. J. Millman, N. Mayorov, A. R. J. Nelson, E. Jones, R. Kern, E. Larson, C. Carey, I. Polat, Y. Feng, E. W. Moore, J. VanderPlas, D. Laxalde, J. Perktold, R. Cimrman, I. Henriksen, E. A. Quintero, C. R Harris, A. M. Archibald, A. H. Ribeiro, F. Pedregosa, P. van Mulbregt, & SciPy 1.0 Contributors, (2020). Nature Methods, in press. DOI: 10.1038/s41592-019-0686-2\nThe dynesty package was used to carry out the nested sampling. Please consider citing:\n - J. S. Speagle, (2019), Monthly Notices of the Royal Astronomical Society, staa278. DOI: 10.1093/mnras/staa278.\n - J. Skilling (2004), AIP Conference Proceedings, 735(1), 395. DOI: 10.1063/1.1835238.\n - J. Skilling (2006), Bayesian Analysis, 1(4), 833. DOI: 10.1214/06-BA127.\n")

CITATION_A = "Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\n"
CITATION_B = "Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\nThe scipy.optimize.minimize function was used to maximise the ln likelihood. Please consider citing:\n - P. Virtanen, r. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, E. Burovski, P. Peterson, W. Weckesser, J. Bright, S. J. van der Walt, M. Brett, J./ Wilson, K. J. Millman, N. Mayorov, A. R. J. Nelson, E. Jones, R. Kern, E. Larson, C. Carey, I. Polat, Y. Feng, E. W. Moore, J. VanderPlas, D. Laxalde, J. Perktold, R. Cimrman, I. Henriksen, E. A. Quintero, C. R Harris, A. M. Archibald, A. H. Ribeiro, F. Pedregosa, P. van Mulbregt, & SciPy 1.0 Contributors, (2020). Nature Methods, in press. DOI: 10.1038/s41592-019-0686-2\n"
CITATION_C = "Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\nThe scipy.optimize.minimize function was used to maximise the ln likelihood. Please consider citing:\n - P. Virtanen, r. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, E. Burovski, P. Peterson, W. Weckesser, J. Bright, S. J. van der Walt, M. Brett, J./ Wilson, K. J. Millman, N. Mayorov, A. R. J. Nelson, E. Jones, R. Kern, E. Larson, C. Carey, I. Polat, Y. Feng, E. W. Moore, J. VanderPlas, D. Laxalde, J. Perktold, R. Cimrman, I. Henriksen, E. A. Quintero, C. R Harris, A. M. Archibald, A. H. Ribeiro, F. Pedregosa, P. van Mulbregt, & SciPy 1.0 Contributors, (2020). Nature Methods, in press. DOI: 10.1038/s41592-019-0686-2\nThe emcee package was used to perform the MCMC analysis. Please consider citing:\n - D. Foreman-Mackey, W. Farr, M. Sinha, A. Archibald, D. Hogg, J. Sanders, J. Zuntz, P. Williams, A. Nelson, M. de Val-Borro, T. Erhardt, I. Pashchenko, & O. Pla, (2019). Journal of Open Source Software, 4(43), 1864. DOI: 10.21105/joss.01864\n - J. Goodman & J. Weare, (2010). Communications in applied mathematics and computational science, 5(1), 65. DOI: 10.2140/camcos.2010.5.65\n"
CITATION_D = "Please consider citing the following:\n - Publication of uravu (to come).\n - Zenodo DOI for uravu version: 0.0.1\nThe scipy.optimize.minimize function was used to maximise the ln likelihood. Please consider citing:\n - P. Virtanen, r. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, E. Burovski, P. Peterson, W. Weckesser, J. Bright, S. J. van der Walt, M. Brett, J./ Wilson, K. J. Millman, N. Mayorov, A. R. J. Nelson, E. Jones, R. Kern, E. Larson, C. Carey, I. Polat, Y. Feng, E. W. Moore, J. VanderPlas, D. Laxalde, J. Perktold, R. Cimrman, I. Henriksen, E. A. Quintero, C. R Harris, A. M. Archibald, A. H. Ribeiro, F. Pedregosa, P. van Mulbregt, & SciPy 1.0 Contributors, (2020). Nature Methods, in press. DOI: 10.1038/s41592-019-0686-2\nThe dynesty package was used to carry out the nested sampling. Please consider citing:\n - J. S. Speagle, (2019), Monthly Notices of the Royal Astronomical Society, staa278. DOI: 10.1093/mnras/staa278.\n - J. Skilling (2004), AIP Conference Proceedings, 735(1), 395. DOI: 10.1063/1.1835238.\n - J. Skilling (2006), Bayesian Analysis, 1(4), 833. DOI: 10.1214/06-BA127.\n"


class TestRelationship(unittest.TestCase):
Expand Down Expand Up @@ -700,10 +699,8 @@ def test_bic(self):
test_x = np.linspace(0, 99, 10)
test_y = np.ones(10)
test_y_e = np.ones(10) * 0.1
test_rel = Relationship(
utils.straight_line, test_x, test_y, test_y_e
)
expected_bic = np.log(10) * 2 - 2 * -1724236.163534402
test_rel = Relationship(utils.straight_line, test_x, test_y, test_y_e)
expected_bic = -23.06776100915812
actual_bic = test_rel.bayesian_information_criteria()
assert_almost_equal(actual_bic, expected_bic)

Expand All @@ -714,9 +711,7 @@ def test_citations_a(self):
test_x = np.linspace(0, 99, 10)
test_y = np.ones(10)
test_y_e = np.ones(10) * 0.1
test_rel = Relationship(
utils.straight_line, test_x, test_y, test_y_e
)
test_rel = Relationship(utils.straight_line, test_x, test_y, test_y_e)
assert_equal(test_rel.citations, CITATION_A)

def test_citations_b(self):
Expand All @@ -726,9 +721,7 @@ def test_citations_b(self):
test_x = np.linspace(0, 99, 10)
test_y = np.ones(10) * 2
test_y_e = np.ones(10) * 0.1
test_rel = Relationship(
utils.straight_line, test_x, test_y, test_y_e
)
test_rel = Relationship(utils.straight_line, test_x, test_y, test_y_e)
test_rel.max_likelihood()
assert_equal(test_rel.citations, CITATION_B)

Expand Down Expand Up @@ -760,4 +753,4 @@ def test_citations_d(self):
test_rel = Relationship(utils.straight_line, test_x, test_y, test_y_e,)
test_rel.max_likelihood()
test_rel.nested_sampling(maxiter=10)
assert_equal(test_rel.citations, CITATION_D)
assert_equal(test_rel.citations, CITATION_D)

0 comments on commit 18bc5ea

Please sign in to comment.