Skip to content

Commit 88b02f6

Browse files
committedFeb 14, 2024
style(linting): fixed liniting errors
1 parent a61b2ca commit 88b02f6

File tree

7 files changed

+173
-24
lines changed

7 files changed

+173
-24
lines changed
 

‎.github/workflows/linting.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
- uses: psf/black@stable
1111
with:
1212
src: "."
13+
version: "23.11.0"
1314

1415
isort:
1516
runs-on: ubuntu-latest

‎poetry.lock

+110-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pycmtensor/expressions.py

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
"""
2-
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.
2+
The code snippet is a part of the PyCMTensor expressions module. It defines a base
3+
class for parsing and manipulating Aesara tensor expressions. The class provides
4+
methods for parsing a tensor expression to remove parentheses and tensor operators, and
5+
returns a clean list of keywords found in the expression. It also defines a base class
6+
for expression objects, which includes overloaded operators for tensor operations such
7+
as addition, subtraction, multiplication, division, and comparison.
38
"""
49
from typing import Union
510

@@ -51,7 +56,8 @@ def __init__(self, expression=None):
5156
"""Base class for parsing and manipulating Aesara tensor expressions.
5257
5358
Args:
54-
expression (TensorVariable, optional): The tensor expression to parse. Defaults to None.
59+
expression (TensorVariable, optional): The tensor expression to parse.
60+
Defaults to None.
5561
"""
5662
if expression is not None:
5763
self.expression = str(pprint(expression))
@@ -153,7 +159,7 @@ def __mul__(self, other):
153159
return self() * other()
154160
else:
155161
raise TypeError(
156-
f"__mul__ {other} must be a TensorVariable or TensorShared Variable object"
162+
f"__mul__ {other} must be a TensorVariable or TensorShared Variable"
157163
)
158164

159165
def __rmul__(self, other):
@@ -399,8 +405,10 @@ def __init__(self, name: str, draw_type: str, n_draws: int):
399405
400406
Args:
401407
name (str): The name of the RandomDraw object.
402-
draw_type (str): The distribution of the draw. Can be "normal", "lognormal", "gumbel", "exponential", "gamma", or "poisson".
403-
n_draws (int): The number of draws, which determines the size of the shared tensor.
408+
draw_type (str): The distribution of the draw. Can be "normal",
409+
"lognormal", "gumbel", "exponential", "gamma", or "poisson".
410+
n_draws (int): The number of draws, which determines the size of the shared
411+
tensor.
404412
405413
Raises:
406414
NotImplementedError: If an unsupported draw_type is provided.
@@ -447,7 +455,8 @@ def __init__(self, name, size, value=None):
447455
Args:
448456
name (str): The name of the parameter.
449457
size (Union[tuple,list]): The size of the array in 1 dimension.
450-
value (numpy.ndarray): The initial values of the parameter. If `None` is given, it defaults to `0`.
458+
value (numpy.ndarray): The initial values of the parameter. If `None` is
459+
given, it defaults to `0`.
451460
"""
452461
Param.__init__(self, name, lb=None, ub=None)
453462

@@ -496,7 +505,8 @@ def __init__(self, name, size, value=None, init_type=None):
496505
Args:
497506
name (str): name of the parameter
498507
size (Union[tuple,list]): size of the array
499-
value (numpy.ndarray): initial values of the parameter. Defaults to `random.uniform(-0.1, 0.1, size)`
508+
value (numpy.ndarray): initial values of the parameter. Defaults to `random.
509+
uniform(-0.1, 0.1, size)`
500510
init_type (str): initialization type, see notes
501511
502512
Note:
@@ -510,8 +520,14 @@ def __init__(self, name, size, value=None, init_type=None):
510520
* `"glorot"`: initialization method that maintains the variance for
511521
symmetric activation functions, e.g. sigm, tanh [^2]
512522
513-
[^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).
514-
[^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.
523+
[^1] He, K., Zhang, X., Ren, S. and Sun, J., 2015. Delving deep into
524+
rectifiers: Surpassing human-level performance on imagenet classification.
525+
In Proceedings of the IEEE international conference on computer vision (pp.
526+
1026-1034).
527+
[^2] Glorot, X. and Bengio, Y., 2010, March. Understanding the difficulty
528+
of training deep feedforward neural networks. In Proceedings of the
529+
thirteenth international conference on artificial intelligence and
530+
statistics (pp. 249-256). JMLR Workshop and Conference Proceedings.
515531
516532
!!! example
517533
Specifying a weight array:

‎pycmtensor/logger.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
```
1919
2020
## Inputs
21-
- `level` (int): The level of the logger to be set. It can be one of the predefined levels: `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`.
21+
- `level` (int): The level of the logger to be set. It can be one of the predefined
22+
levels: `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`.
2223
2324
## Outputs
2425
- None

‎pycmtensor/results.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def __init__(self):
3737
bhhh_matrix (numpy.ndarray): the 3-D bhhh matrix where the 1st dimension is
3838
the length of the dataset and the last 2 dimensions are the matrix for
3939
each data observation
40-
statistics_graph (dict): a dictionary containing the learning_rate, training, and validation statistics
40+
statistics_graph (dict): a dictionary containing the learning_rate,
41+
training, and validation statistics
4142
betas (dict): a dictionary containing the Beta coefficients
4243
params (dict): a dictionary containing all model coefficients
4344
"""
@@ -99,7 +100,8 @@ def AIC(self):
99100
return 2.0 * (k - self.best_loglikelihood)
100101

101102
def BIC(self):
102-
"""Bayesian information criterion, adjusted for the number of parameters and number of training samples
103+
"""Bayesian information criterion, adjusted for the number of parameters and
104+
number of training samples
103105
104106
Returns:
105107
(float): the BIC of the model

‎pycmtensor/statistics.py

+24-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
This module contains methods for calculating the statistics of the estimated parameters.
44
55
Functions:
6-
- variance_covariance(hessian): Computes the variance covariance matrix given the Hessian.
7-
- rob_variance_covariance(hessian, bhhh): Computes the robust variance covariance matrix given the Hessian and BHHH matrices.
8-
- t_test(stderr, params): Computes the statistical t-test of the estimated parameters and the standard errors.
9-
- p_value(stderr, params): Computes the p-value (statistical significance) of the estimated parameters using the two-tailed normal distribution.
10-
- stderror(hessian, params): Calculates the standard error of the estimated parameters given the Hessian matrix.
11-
- rob_stderror(hessian, bhhh, params): Calculates the robust standard error of the estimated parameters given the Hessian and BHHH matrices.
6+
- variance_covariance(hessian): Computes the variance covariance matrix given the
7+
Hessian.
8+
- rob_variance_covariance(hessian, bhhh): Computes the robust variance covariance
9+
matrix given the Hessian and BHHH matrices.
10+
- t_test(stderr, params): Computes the statistical t-test of the estimated parameters
11+
and the standard errors.
12+
- p_value(stderr, params): Computes the p-value (statistical significance) of the
13+
estimated parameters using the two-tailed normal distribution.
14+
- stderror(hessian, params): Calculates the standard error of the estimated parameters
15+
given the Hessian matrix.
16+
- rob_stderror(hessian, bhhh, params): Calculates the robust standard error of the
17+
estimated parameters given the Hessian and BHHH matrices.
1218
- correlation_matrix(hessian): Computes the correlation matrix from the Hessian matrix.
13-
- rob_correlation_matrix(hessian, bhhh): Computes the robust correlation matrix from the Hessian and BHHH matrices.
19+
- rob_correlation_matrix(hessian, bhhh): Computes the robust correlation matrix from
20+
the Hessian and BHHH matrices.
1421
"""
1522
import numpy as np
1623
from scipy import stats
@@ -37,7 +44,9 @@ def variance_covariance(hessian):
3744
3845
!!! notes
3946
40-
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.
47+
The variance covariance matrix is calculated by taking the inverse of the
48+
(negative) hessian matrix. If the inverse is undefined, returns a zero or a
49+
large finite number.
4150
4251
$$
4352
varcovar = -H^{-1}
@@ -47,7 +56,8 @@ def variance_covariance(hessian):
4756

4857

4958
def rob_variance_covariance(hessian, bhhh):
50-
"""computes the robust variance covariance matrix given the Hessian and the BHHH matrices
59+
"""computes the robust variance covariance matrix given the Hessian and the BHHH
60+
matrices
5161
5262
Args:
5363
hessian (numpy.ndarray): the hessian matrix
@@ -83,7 +93,9 @@ def t_test(stderr, params):
8393

8494

8595
def p_value(stderr, params):
86-
"""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
96+
"""computes the p-value (statistical significance) of the estimated parameter using
97+
the two-tailed normal distribution, where p-value=$2(1-\\phi(|t|)$, $\\phi$ is
98+
the cdf of the normal distribution
8799
88100
Args:
89101
stderr (pandas.Series): standard errors
@@ -128,7 +140,8 @@ def stderror(hessian, params):
128140

129141

130142
def rob_stderror(hessian, bhhh, params):
131-
"""calculates the robust standard error of the estimated parameter given the hessian and the bhhh matrices
143+
"""calculates the robust standard error of the estimated parameter given the
144+
hessian and the bhhh matrices
132145
133146
Args:
134147
hessian (numpy.ndarray): the hessian matrix

‎pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ optional = true
3636
pytest = ">=7.4.3"
3737
pytest-cov = ">=4.1.0"
3838

39+
[tool.poetry.group.lint]
40+
optional = true
41+
42+
[tool.poetry.group.lint.dependencies]
43+
black = ">=22.1.0"
44+
isort = ">=5.9.3"
45+
3946
[build-system]
4047
requires = ["poetry-core>=1.0.0"]
4148
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)
Please sign in to comment.