Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maxkuttner
Copy link

@maxkuttner maxkuttner commented Oct 19, 2024

This PR rebases #8975 to the current main branch with some minor additions and corrections.

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/main -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

@maxkuttner maxkuttner marked this pull request as ready for review October 19, 2024 07:10
@josef-pkt josef-pkt added this to the 0.15 milestone Oct 21, 2024
@maxkuttner
Copy link
Author

Hello @josef-pkt, is this PR ready to be merged?

@bashtage
Copy link
Member

Could you address the review comments please?

@maxkuttner
Copy link
Author

Could you address the review comments please?

It seems there are no review comments yet. Or am I not seeing them for some reason?


\psi: \mathbb{R}^n \to \mathbb{R}^n

\psi(z) = z
Copy link
Member

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?


\text{weights}(z) = \begin{cases}
\left(1 - \left(\frac{z}{
c}\right)^4\right)^2, & \text{if }
Copy link
Member

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.

\psi: \mathbb{R}^n \to \mathbb{R}^n

\psi(z) = \begin{cases}
z \left(1 - \frac{z}{c}^4\right)^2, & \text{if }
Copy link
Member

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.

@bashtage
Copy link
Member

Sorry, forgot to finish my review by requesting changes.

@pep8speaks
Copy link

pep8speaks commented Oct 23, 2024

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

Copy link
Member

@bashtage bashtage left a 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.


\text{weights}: \mathbb{R}^n \to \mathbb{R}^n

\text{weights}(z) = \frac{\psi(z)}{z}
Copy link
Member

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


\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 }
Copy link
Member

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.

\lvert z \rvert \le a\pi \\
2a, & \text{if } \lvert z \rvert > a\pi
\end{cases}

Copy link
Member

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.

Copy link
Author

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?

@bashtage
Copy link
Member

See this example. I think a good format would be

Parameters
----------
blah : ...

Returns
-------

Notes
------
rho is defined as 

   .. math::

      rho(z) & = a^2 *(1-cos(z/a)), |z| \leq a\pi \\
      rho(z) & = 2a, |z|>q\pi

Either this or skip the Notes section header and simply include the math as part of the returns.

@maxkuttner maxkuttner force-pushed the DocUpdates branch 2 times, most recently from ed0b59f to 82933ea Compare November 3, 2024 15:49
Replace python formulas with LaTex.
Move formulas to Notes section of docstring.

Co-authored-by: Ca7Ac1 <Ca7Ac1@gmail.com>
@maxkuttner
Copy link
Author

maxkuttner commented Nov 3, 2024

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?

@josef-pkt
Copy link
Member

One disadvantage of the heavy LATEX is that it is difficult to read in the code editor.
I often rely on being able to read the formulas/equations when checking the code.

Maybe there is a compromise (or formula duplication) to have (also) a version with readable code

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.

DOC: docstrings in robust.norms, improve, reorganize
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy