Skip to content

Commit 8cf60bb

Browse files
committed
ty: un-ignore call-non-callable rule
1 parent adccf0c commit 8cf60bb

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎neural_network/back_propagation_neural_network.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
1919
"""
2020

21+
from collections.abc import Callable
22+
2123
import numpy as np
2224
from matplotlib import pyplot as plt
2325

@@ -32,18 +34,29 @@ class DenseLayer:
3234
"""
3335

3436
def __init__(
35-
self, units, activation=None, learning_rate=None, is_input_layer=False
37+
self,
38+
units,
39+
activation: Callable[[np.ndarray], np.ndarray] | None = None,
40+
learning_rate=None,
41+
is_input_layer=False,
3642
) -> None:
3743
"""
3844
common connected layer of bp network
3945
:param units: numbers of neural units
40-
:param activation: activation function
46+
:param activation: activation function, sigmoid if not given
4147
:param learning_rate: learning rate for paras
4248
:param is_input_layer: whether it is input layer or not
49+
50+
>>> DenseLayer(3).activation is sigmoid
51+
True
52+
>>> DenseLayer(3, activation=np.tanh).activation is np.tanh
53+
True
4354
"""
4455
self.units = units
4556
self.weight = None
4657
self.bias = None
58+
if activation is None:
59+
activation = sigmoid
4760
self.activation = activation
4861
if learning_rate is None:
4962
learning_rate = 0.3
@@ -54,8 +67,6 @@ def initializer(self, back_units) -> None:
5467
rng = np.random.default_rng()
5568
self.weight = np.asmatrix(rng.normal(0, 0.5, (self.units, back_units)))
5669
self.bias = np.asmatrix(rng.normal(0, 0.5, self.units)).T
57-
if self.activation is None:
58-
self.activation = sigmoid
5970

6071
def cal_gradient(self):
6172
# activation function may be sigmoid or linear

‎pyproject.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ skip = """\
316316
# assumptions consistent with the CI job in .github/workflows/ty.yml, where the
317317
# free-threaded 3.15t test venv would otherwise leave several stubs unresolved.
318318
environment.python-version = "3.15"
319-
rules.call-non-callable = "ignore"
320319
rules.invalid-argument-type = "ignore"
321320
rules.invalid-return-type = "ignore"
322321
rules.no-matching-overload = "ignore"

0 commit comments

Comments
 (0)