-
Notifications
You must be signed in to change notification settings - Fork 3.3k
DOC: docstrings in robust.norms, improve, reorganize #9402
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
base: main
Are you sure you want to change the base?
Conversation
Hello @josef-pkt, is this PR ready to be merged? |
Could you address the review comments please? |
It seems there are no review comments yet. Or am I not seeing them for some reason? |
statsmodels/robust/norms.py
Outdated
|
||
\psi: \mathbb{R}^n \to \mathbb{R}^n | ||
|
||
\psi(z) = z |
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.
Doesn't seem to match the formula below. Can you check?
statsmodels/robust/norms.py
Outdated
|
||
\text{weights}(z) = \begin{cases} | ||
\left(1 - \left(\frac{z}{ | ||
c}\right)^4\right)^2, & \text{if } |
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.
Formula has k
not 4
.
statsmodels/robust/norms.py
Outdated
\psi: \mathbb{R}^n \to \mathbb{R}^n | ||
|
||
\psi(z) = \begin{cases} | ||
z \left(1 - \frac{z}{c}^4\right)^2, & \text{if } |
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.
Same k in formula, not 4.
Sorry, forgot to finish my review by requesting changes. |
Hello @maxkuttner! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2024-11-03 16:09:13 UTC |
bb69352
to
8a55450
Compare
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.
Needs some more work. Some are not correct. The big issus is that many now have two mathematical details pages. Shoudl only have one, so need to replace existing if necessary.
statsmodels/robust/norms.py
Outdated
|
||
\text{weights}: \mathbb{R}^n \to \mathbb{R}^n | ||
|
||
\text{weights}(z) = \frac{\psi(z)}{z} |
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 one doesn't seem to match the answer. Looks like weights(z) = 1
statsmodels/robust/norms.py
Outdated
|
||
\rho(z) = \begin{cases} | ||
\frac{z^2}{2}, & \text{if } \lvert z \rvert \le t \\ | ||
\lvert z \rvert \ t - \frac{z^2}{2}, & \text{if } |
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.
Second case here seems to be wrong asn well. -0.5 t^2, not -0.5 z^2.
statsmodels/robust/norms.py
Outdated
\lvert z \rvert \le a\pi \\ | ||
2a, & \text{if } \lvert z \rvert > a\pi | ||
\end{cases} | ||
|
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 feel redundant given then math below. We should consolidate these definitions with the formula explanation contained in each, so that there aren't two explanations. Sometimes the formula is python math, sometimes it is LaTeX. I'm happy if you put your latex in place of the which ever is there.
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.
Ok. Thank you for the feedback @bashtage. I understand - so ideally there would always be one formula (either latex or python math). I would therefore refactor all docstrings in this file to have the LaTex formulas in the "Returns" statement to consolidate the information of what the function does in there.
This would look like this:
def rho(self, z):
r"""
The robust criterion function for Andrew's wave.
Parameters
----------
z : array_like
1d array
Returns
-------
rho : ndarray
The elements of rho are defined as:
.. math::
\rho: \mathbb{R}^n \to \mathbb{R}^n
\rho(z) = \begin{cases}
a^2 (1 - \cos(\frac{z}{a})), & \text{if }
\lvert z \rvert \le a\pi \\
2a, & \text{if } \lvert z \rvert > a\pi
\end{cases}
"""
This way there would be one single place to look for this information. Is this how you imagined it?
See this example. I think a good format would be
Either this or skip the |
ed0b59f
to
82933ea
Compare
Replace python formulas with LaTex. Move formulas to Notes section of docstring. Co-authored-by: Ca7Ac1 <Ca7Ac1@gmail.com>
82933ea
to
696d970
Compare
Hello @bashtage. I replaced the python math in the "Returns" section with LaTex math. Any chance you could have a quick look at it again? |
One disadvantage of the heavy LATEX is that it is difficult to read in the code editor. Maybe there is a compromise (or formula duplication) to have (also) a version with readable code |
NumPy's guide.
This PR rebases #8975 to the current main branch with some minor additions and corrections.
Notes:
needed for doc changes.
then show that it is fixed with the new code.
verify you changes are well formatted by running
flake8
is installed. This command is also available on Windowsusing the Windows System for Linux once
flake8
is installed in thelocal Linux environment. While passing this test is not required, it is good practice and it help
improve code quality in
statsmodels
.