-
Notifications
You must be signed in to change notification settings - Fork 1
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
Unify and clean code style and docstring #68
Conversation
Pull Request Test Coverage Report for Build 5717911329
💛 - Coveralls |
7355bd4
to
2e4c06c
Compare
I just had a very brief look. Is there a particular benefit of choosing restructured text docstring? As far as I know, sphinx also supports Google fand NumPy-type docstrings. I generally find reStr text terrible to read and to maintain and if there is no clear point in favor of it I’d much prefer to go to one of the alternative standards. |
OK, I will go to Google style docstring. |
Ah very nice! So do we need to make the linking to the things in the sidebar manually? I think this would be very useful! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor things and some of the previous discussions are still open but apart from that it looks great -- very nice to have such clean and structured docstrings! 🚀
Maybe later. This PR only makes docstring. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me now -- thank you very much for this contribution @dachengx ! 😊
mu (float, optional (default=None)): mean of the gaussian, | ||
if None, the nominal value is used | ||
sigma (float, optional (default=None)): standard deviation of the gaussian, | ||
if None, the nominal value is used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we warn that no nominal values are set here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you properly call the ll via .ll
instead of ._ll
it should parse the defaults or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure but I think it's possible to run into a useless error if you don't define the defaults and then mu and sigma stay None and are parsed to stats.norm.. Maybe it would make sense to catch this case and provide a more useful error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do catch it-- but it is nice to point out this stumbling block in the documentation, in particular since this is a tutorial model, that fails if you use it naively
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do catch it, but it is the default behavior of the gaussian model if you
just initialize, give it a data set, and try to fit
…On Tue, Aug 1, 2023, 08:20 Robert Hammann ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In alea/examples/gaussian_model.py
<#68 (comment)>:
> if parameter_definition is None:
parameter_definition = ["mu", "sigma"]
super().__init__(parameter_definition=parameter_definition, **kwargs)
def _ll(self, mu=None, sigma=None):
+ """
+ Log-likelihood of the model.
+
+ Args:
+ mu (float, optional (default=None)): mean of the gaussian,
+ if None, the nominal value is used
+ sigma (float, optional (default=None)): standard deviation of the gaussian,
+ if None, the nominal value is used
Not entirely sure but I think it's possible to run into a useless error if
you don't define the defaults and then mu and sigma stay None and are
parsed to stats.norm.. Maybe it would make sense to catch this case and
provide a more useful error.
—
Reply to this email directly, view it on GitHub
<#68 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEAPFKJWFAGTG45RHEBY5NLXTDX7FANCNFSM6AAAAAA24Z7C6Y>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
Ah, right @kdund we catch it in the Parameters class. Then I think everything is fine or not? Probably I'm just missing your point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Few minor changes-- I think we should warn that the gaussian model must have nominal values set manually, or fitting will not work (i.e. write it in the docstring) and we should label the likelihood likelihood not logpdf in the example placeholder
alea/model.py
Outdated
raise NotImplementedError( | ||
"You must write a data-generation method (_generate_data) for your statistical model" | ||
" or use a subclass where it is written for you") | ||
|
||
@_needs_data | ||
def ll(self, **kwargs) -> float: | ||
""" | ||
Likelihod function, returns the loglikelihood for the given parameters. | ||
Likelihod function, return the loglikelihood for the given parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returns is correct
alea/model.py
Outdated
Make a function that can be passed to Minuit | ||
|
||
Args: | ||
minus (bool, optional (default=True)): if True, the function is multiplied by -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why have minus here if we never use the option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that we drop this minus
and always use True
? Maybe @hammannr can comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good point -- let's drop it. It's a remnant from blueice, we don't need this flexibility here I think.
alea/model.py
Outdated
""" | ||
Generate data for the given parameters. | ||
The parameters are passed as keyword arguments, positional arguments are not possible. | ||
If a parameter is not given, the default value is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would keep singular to emphasize that it is the default value singular for that parameter (i.e. not for all parameters)
mu (float, optional (default=None)): mean of the gaussian, | ||
if None, the nominal value is used | ||
sigma (float, optional (default=None)): standard deviation of the gaussian, | ||
if None, the nominal value is used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do catch it-- but it is nice to point out this stumbling block in the documentation, in particular since this is a tutorial model, that fails if you use it naively
r_data = np.zeros(np.sum(n_sources), dtype=self.dtype) | ||
i_write = 0 | ||
for i, n_source in enumerate(n_sources): | ||
if 0 < n_source: #dont generate if 0 | ||
if n_source > 0: # dont generate if 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong way, no? Always better to go smaller->larger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8's WPS309 prefer putting variable first: #68 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I want us to ignore WPS309 errors.
To me this is a significant readability issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your reasoning Knut but I have to say I'm so used to it that writing 0 < n_sources
takes me a few seconds to understand 😄 Though I think it's a small detail and I can live with either solution.
@@ -42,8 +41,7 @@ def adapt_likelihood_config_for_blueice( | |||
|
|||
Args: | |||
likelihood_config (dict): likelihood config dict | |||
template_folder_list (list): list of possible base folders. | |||
Ordered by priority. | |||
template_folder_list (list): list of possible base folders. Ordered by priority. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which order? Try first one first or last one first?
notebooks/placeholder.ipynb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While "logPDF" is correct in principle here, I would label it likelihood instead since it is used as a function of mu, rather than the observation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, so it is not correct in principle, but in practise :)
…calModel.make_objective
Every time we update the attributes of modules, like adding a module
runner
, we should runalea/docs/make_docs.sh
inalea/docs
folder to updatealea/docs/reference
.But the docstring of
template_source.py
is not updated. It will be fixed in #69.Reference:
Indentation: https://legacy.python.org/dev/peps/pep-0008/#indentation
Docstring format: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
This PR tries to apply hanging indentation as much as possible.
You can check the built docs at https://readthedocs.org/projects/alea/builds/ or https://alea--68.org.readthedocs.build/en/68/.