Skip to content

Commit

Permalink
use workaround for attribute formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohjeah committed May 4, 2020
1 parent 9c380a4 commit 9e982d0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
39 changes: 39 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,42 @@ def setup(app):
gallery_dirs=["examples"],
pattern=".+.ipynb",
)

# -- Extensions to the Napoleon GoogleDocstring class ---------------------
# michaelgoerz.net/notes/extending-sphinx-napoleon-docstring-sections.html
from sphinx.ext.napoleon.docstring import GoogleDocstring # noqa: E402


def parse_keys_section(self, section):
return self._format_fields("Keys", self._consume_fields())


GoogleDocstring._parse_keys_section = parse_keys_section


def parse_attributes_section(self, section):
return self._format_fields("Attributes", self._consume_fields())


GoogleDocstring._parse_attributes_section = parse_attributes_section


def parse_class_attributes_section(self, section):
return self._format_fields("Class Attributes", self._consume_fields())


GoogleDocstring._parse_class_attributes_section = parse_class_attributes_section


def patched_parse(self):
"""
we now patch the parse method to guarantee that the the above methods are
assigned to the _section dict
"""
self._sections["keys"] = self._parse_keys_section
self._sections["class attributes"] = self._parse_class_attributes_section
self._unpatched_parse()


GoogleDocstring._unpatched_parse = GoogleDocstring._parse
GoogleDocstring._parse = patched_parse
6 changes: 3 additions & 3 deletions pysindy/optimizers/sindy_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class SINDyOptimizer(BaseEstimator):
unbias : boolean, optional (default True)
Whether to perform an extra step of unregularized linear regression to unbias
the coefficients for the identified support.
For example, if `optimizer=STLSQ(alpha=0.1)` is used then the learned
For example, if ``optimizer=STLSQ(alpha=0.1)`` is used then the learned
coefficients will be biased toward 0 due to the L2 regularization.
Setting `unbias=True` will trigger an additional step wherein the nonzero
coefficients learned by the `STLSQ` object will be updated using an
Setting ``unbias=True`` will trigger an additional step wherein the nonzero
coefficients learned by the optimizer object will be updated using an
unregularized least-squares fit.
"""

Expand Down
4 changes: 2 additions & 2 deletions pysindy/optimizers/sr3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SR3(BaseOptimizer):
.. math::
0.5\\|y-Xw\\|^2_2 + lambda \\times R(v)
+ (0.5 / nu)\\|w-v\\|^2_2
0.5\\|y-Xw\\|^2_2 + \\lambda \\times R(v)
+ (0.5 / \\nu)\\|w-v\\|^2_2
where :math:`R(v)` is a regularization function. See the following reference
for more details:
Expand Down
2 changes: 1 addition & 1 deletion pysindy/optimizers/stlsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class STLSQ(BaseOptimizer):
"""Sequentially thresholded least squares algorithm.
Attempts to minimize the objective function
:math:`\\|y - Xw\\|^2_2 + alpha \\times \\|w\\|^2_2`
:math:`\\|y - Xw\\|^2_2 + \\alpha \\|w\\|^2_2`
by iteratively performing least squares and masking out
elements of the weight that are below a given threshold.
Expand Down

0 comments on commit 9e982d0

Please sign in to comment.