Skip to content

Commit

Permalink
style(linting): fixed liniting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mwong009 committed Feb 14, 2024
1 parent a61b2ca commit 88b02f6
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
- uses: psf/black@stable
with:
src: "."
version: "23.11.0"

isort:
runs-on: ubuntu-latest
Expand Down
111 changes: 110 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions pycmtensor/expressions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""
The code snippet is a part of the PyCMTensor expressions module. It defines a base class for parsing and manipulating Aesara tensor expressions. The class provides methods for parsing a tensor expression to remove parentheses and tensor operators, and returns a clean list of keywords found in the expression. It also defines a base class for expression objects, which includes overloaded operators for tensor operations such as addition, subtraction, multiplication, division, and comparison.
The code snippet is a part of the PyCMTensor expressions module. It defines a base
class for parsing and manipulating Aesara tensor expressions. The class provides
methods for parsing a tensor expression to remove parentheses and tensor operators, and
returns a clean list of keywords found in the expression. It also defines a base class
for expression objects, which includes overloaded operators for tensor operations such
as addition, subtraction, multiplication, division, and comparison.
"""
from typing import Union

Expand Down Expand Up @@ -51,7 +56,8 @@ def __init__(self, expression=None):
"""Base class for parsing and manipulating Aesara tensor expressions.
Args:
expression (TensorVariable, optional): The tensor expression to parse. Defaults to None.
expression (TensorVariable, optional): The tensor expression to parse.
Defaults to None.
"""
if expression is not None:
self.expression = str(pprint(expression))
Expand Down Expand Up @@ -153,7 +159,7 @@ def __mul__(self, other):
return self() * other()
else:
raise TypeError(
f"__mul__ {other} must be a TensorVariable or TensorShared Variable object"
f"__mul__ {other} must be a TensorVariable or TensorShared Variable"
)

def __rmul__(self, other):
Expand Down Expand Up @@ -399,8 +405,10 @@ def __init__(self, name: str, draw_type: str, n_draws: int):
Args:
name (str): The name of the RandomDraw object.
draw_type (str): The distribution of the draw. Can be "normal", "lognormal", "gumbel", "exponential", "gamma", or "poisson".
n_draws (int): The number of draws, which determines the size of the shared tensor.
draw_type (str): The distribution of the draw. Can be "normal",
"lognormal", "gumbel", "exponential", "gamma", or "poisson".
n_draws (int): The number of draws, which determines the size of the shared
tensor.
Raises:
NotImplementedError: If an unsupported draw_type is provided.
Expand Down Expand Up @@ -447,7 +455,8 @@ def __init__(self, name, size, value=None):
Args:
name (str): The name of the parameter.
size (Union[tuple,list]): The size of the array in 1 dimension.
value (numpy.ndarray): The initial values of the parameter. If `None` is given, it defaults to `0`.
value (numpy.ndarray): The initial values of the parameter. If `None` is
given, it defaults to `0`.
"""
Param.__init__(self, name, lb=None, ub=None)

Expand Down Expand Up @@ -496,7 +505,8 @@ def __init__(self, name, size, value=None, init_type=None):
Args:
name (str): name of the parameter
size (Union[tuple,list]): size of the array
value (numpy.ndarray): initial values of the parameter. Defaults to `random.uniform(-0.1, 0.1, size)`
value (numpy.ndarray): initial values of the parameter. Defaults to `random.
uniform(-0.1, 0.1, size)`
init_type (str): initialization type, see notes
Note:
Expand All @@ -510,8 +520,14 @@ def __init__(self, name, size, value=None, init_type=None):
* `"glorot"`: initialization method that maintains the variance for
symmetric activation functions, e.g. sigm, tanh [^2]
[^1] He, K., Zhang, X., Ren, S. and Sun, J., 2015. Delving deep into rectifiers: Surpassing human-level performance on imagenet classification. In Proceedings of the IEEE international conference on computer vision (pp. 1026-1034).
[^2] Glorot, X. and Bengio, Y., 2010, March. Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the thirteenth international conference on artificial intelligence and statistics (pp. 249-256). JMLR Workshop and Conference Proceedings.
[^1] He, K., Zhang, X., Ren, S. and Sun, J., 2015. Delving deep into
rectifiers: Surpassing human-level performance on imagenet classification.
In Proceedings of the IEEE international conference on computer vision (pp.
1026-1034).
[^2] Glorot, X. and Bengio, Y., 2010, March. Understanding the difficulty
of training deep feedforward neural networks. In Proceedings of the
thirteenth international conference on artificial intelligence and
statistics (pp. 249-256). JMLR Workshop and Conference Proceedings.
!!! example
Specifying a weight array:
Expand Down
3 changes: 2 additions & 1 deletion pycmtensor/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
```
## Inputs
- `level` (int): The level of the logger to be set. It can be one of the predefined levels: `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`.
- `level` (int): The level of the logger to be set. It can be one of the predefined
levels: `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`.
## Outputs
- None
Expand Down
6 changes: 4 additions & 2 deletions pycmtensor/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __init__(self):
bhhh_matrix (numpy.ndarray): the 3-D bhhh matrix where the 1st dimension is
the length of the dataset and the last 2 dimensions are the matrix for
each data observation
statistics_graph (dict): a dictionary containing the learning_rate, training, and validation statistics
statistics_graph (dict): a dictionary containing the learning_rate,
training, and validation statistics
betas (dict): a dictionary containing the Beta coefficients
params (dict): a dictionary containing all model coefficients
"""
Expand Down Expand Up @@ -99,7 +100,8 @@ def AIC(self):
return 2.0 * (k - self.best_loglikelihood)

def BIC(self):
"""Bayesian information criterion, adjusted for the number of parameters and number of training samples
"""Bayesian information criterion, adjusted for the number of parameters and
number of training samples
Returns:
(float): the BIC of the model
Expand Down
35 changes: 24 additions & 11 deletions pycmtensor/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
This module contains methods for calculating the statistics of the estimated parameters.
Functions:
- variance_covariance(hessian): Computes the variance covariance matrix given the Hessian.
- rob_variance_covariance(hessian, bhhh): Computes the robust variance covariance matrix given the Hessian and BHHH matrices.
- t_test(stderr, params): Computes the statistical t-test of the estimated parameters and the standard errors.
- p_value(stderr, params): Computes the p-value (statistical significance) of the estimated parameters using the two-tailed normal distribution.
- stderror(hessian, params): Calculates the standard error of the estimated parameters given the Hessian matrix.
- rob_stderror(hessian, bhhh, params): Calculates the robust standard error of the estimated parameters given the Hessian and BHHH matrices.
- variance_covariance(hessian): Computes the variance covariance matrix given the
Hessian.
- rob_variance_covariance(hessian, bhhh): Computes the robust variance covariance
matrix given the Hessian and BHHH matrices.
- t_test(stderr, params): Computes the statistical t-test of the estimated parameters
and the standard errors.
- p_value(stderr, params): Computes the p-value (statistical significance) of the
estimated parameters using the two-tailed normal distribution.
- stderror(hessian, params): Calculates the standard error of the estimated parameters
given the Hessian matrix.
- rob_stderror(hessian, bhhh, params): Calculates the robust standard error of the
estimated parameters given the Hessian and BHHH matrices.
- correlation_matrix(hessian): Computes the correlation matrix from the Hessian matrix.
- rob_correlation_matrix(hessian, bhhh): Computes the robust correlation matrix from the Hessian and BHHH matrices.
- rob_correlation_matrix(hessian, bhhh): Computes the robust correlation matrix from
the Hessian and BHHH matrices.
"""
import numpy as np
from scipy import stats
Expand All @@ -37,7 +44,9 @@ def variance_covariance(hessian):
!!! notes
The variance covariance matrix is calculated by taking the inverse of the (negative) hessian matrix. If the inverse is undefined, returns a zero or a large finite number.
The variance covariance matrix is calculated by taking the inverse of the
(negative) hessian matrix. If the inverse is undefined, returns a zero or a
large finite number.
$$
varcovar = -H^{-1}
Expand All @@ -47,7 +56,8 @@ def variance_covariance(hessian):


def rob_variance_covariance(hessian, bhhh):
"""computes the robust variance covariance matrix given the Hessian and the BHHH matrices
"""computes the robust variance covariance matrix given the Hessian and the BHHH
matrices
Args:
hessian (numpy.ndarray): the hessian matrix
Expand Down Expand Up @@ -83,7 +93,9 @@ def t_test(stderr, params):


def p_value(stderr, params):
"""computes the p-value (statistical significance) of the estimated parameter using the two-tailed normal distribution, where p-value=$2(1-\\phi(|t|)$, $\\phi$ is the cdf of the normal distribution
"""computes the p-value (statistical significance) of the estimated parameter using
the two-tailed normal distribution, where p-value=$2(1-\\phi(|t|)$, $\\phi$ is
the cdf of the normal distribution
Args:
stderr (pandas.Series): standard errors
Expand Down Expand Up @@ -128,7 +140,8 @@ def stderror(hessian, params):


def rob_stderror(hessian, bhhh, params):
"""calculates the robust standard error of the estimated parameter given the hessian and the bhhh matrices
"""calculates the robust standard error of the estimated parameter given the
hessian and the bhhh matrices
Args:
hessian (numpy.ndarray): the hessian matrix
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ optional = true
pytest = ">=7.4.3"
pytest-cov = ">=4.1.0"

[tool.poetry.group.lint]
optional = true

[tool.poetry.group.lint.dependencies]
black = ">=22.1.0"
isort = ">=5.9.3"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand Down

0 comments on commit 88b02f6

Please sign in to comment.