Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cfd23a2

Browse files
committedOct 30, 2024·
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent fc3d7dd commit cfd23a2

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

‎neural_network/adaptive_resonance_theory.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def __init__(self, num_features: int, vigilance: float = 0.7) -> None:
2121
Args:
2222
num_features (int): Number of features in the input data.
2323
vigilance (float): Threshold for similarity (default is 0.7).
24-
24+
2525
Raises:
2626
ValueError: If num_features is not positive or if vigilance is not between 0 and 1.
2727
"""
2828
if num_features <= 0:
2929
raise ValueError("Number of features must be a positive integer.")
3030
if not (0 <= vigilance <= 1):
3131
raise ValueError("Vigilance parameter must be between 0 and 1.")
32-
32+
3333
self.vigilance = vigilance
3434
self.num_features = num_features
3535
self.weights = []
@@ -45,10 +45,16 @@ def _similarity(self, weight_vector: np.ndarray, input_vector: np.ndarray) -> fl
4545
Returns:
4646
float: The similarity score between the weight and the input.
4747
"""
48-
if len(weight_vector) != self.num_features or len(input_vector) != self.num_features:
49-
raise ValueError(f"Both weight_vector and input_vector must have {self.num_features} features.")
50-
48+
if (
49+
len(weight_vector) != self.num_features
50+
or len(input_vector) != self.num_features
51+
):
52+
raise ValueError(
53+
f"Both weight_vector and input_vector must have {self.num_features} features."
54+
)
55+
5156
return np.dot(weight_vector, input_vector) / self.num_features
57+
5258
def _learn(
5359
self, w: np.ndarray, x: np.ndarray, learning_rate: float = 0.5
5460
) -> np.ndarray:

0 commit comments

Comments
 (0)
Please sign in to comment.