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 ac9dba6

Browse files
authoredOct 30, 2024··
Update adaptive_resonance_theory.py
1 parent 4bfd5ee commit ac9dba6

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed
 

‎neural_network/adaptive_resonance_theory.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
"""
22
adaptive_resonance_theory.py
33
4-
This module implements the Adaptive Resonance Theory 1 (ART1) model, a type
5-
of neural network designed for unsupervised learning and clustering of binary
6-
input data. The ART1 algorithm continuously learns to categorize inputs based
7-
on their similarity while preserving previously learned categories. This is
8-
achieved through a vigilance parameter that controls the strictness of
4+
This module implements the Adaptive Resonance Theory 1 (ART1) model, a type
5+
of neural network designed for unsupervised learning and clustering of binary
6+
input data. The ART1 algorithm continuously learns to categorize inputs based
7+
on their similarity while preserving previously learned categories. This is
8+
achieved through a vigilance parameter that controls the strictness of
99
category matching, allowing for flexible and adaptive clustering.
1010
11-
ART1 is particularly useful in applications where it is critical to learn new
12-
patterns without forgetting previously learned ones, making it suitable for
11+
ART1 is particularly useful in applications where it is critical to learn new
12+
patterns without forgetting previously learned ones, making it suitable for
1313
real-time data clustering and pattern recognition tasks.
1414
1515
References:
16-
1. Carpenter, G. A., & Grossberg, S. (1987). "A Adaptive Resonance Theory."
17-
In: Neural Networks for Pattern Recognition, Oxford University Press,
18-
pp. 194–203.
19-
2. Carpenter, G. A., & Grossberg, S. (1988). "The ART of Adaptive Pattern
20-
Recognition by a Self-Organizing Neural Network." IEEE Transactions on
21-
Neural Networks, 1(2), 115-130. DOI: 10.1109/TNN.1988.82656
16+
1. Carpenter, G. A., & Grossberg, S. (1987). "A Adaptive Resonance Theory."
17+
In: Neural Networks for Pattern Recognition, Oxford University Press,
18+
pp.
19+
2. Carpenter, G. A., & Grossberg, S. (1988). "The ART of Adaptive Pattern
20+
Recognition by a Self-Organizing Neural Network." IEEE Transactions on
21+
Neural Networks, 1(2)DOI: 10.1109/TNN.1988.82656
2222
2323
"""
2424

2525
import numpy as np
26+
from typing import List
2627

2728

2829
class ART1:
@@ -33,7 +34,7 @@ class ART1:
3334
num_features (int): Number of features in the input data.
3435
vigilance (float): Threshold for similarity that determines whether
3536
an input matches an existing cluster.
36-
weights (list): List of cluster weights representing the learned categories.
37+
weights (List[np.ndarray]): List cluster weights representing learned categories.
3738
"""
3839

3940
def __init__(self, num_features: int, vigilance: float = 0.7) -> None:
@@ -54,7 +55,7 @@ def __init__(self, num_features: int, vigilance: float = 0.7) -> None:
5455

5556
self.vigilance = vigilance
5657
self.num_features = num_features
57-
self.weights = []
58+
self.weights: List[np.ndarray] = [] # Type annotation added here
5859

5960
def _similarity(self, weight_vector: np.ndarray, input_vector: np.ndarray) -> float:
6061
"""
@@ -72,7 +73,7 @@ def _similarity(self, weight_vector: np.ndarray, input_vector: np.ndarray) -> fl
7273
or len(input_vector) != self.num_features
7374
):
7475
raise ValueError(
75-
"Both weight_vector and input_vector must have the same number of features."
76+
"Both weight_vector and input_vector must have the same features."
7677
)
7778

7879
return np.dot(weight_vector, input_vector) / self.num_features
@@ -152,7 +153,7 @@ def art1_example() -> None:
152153
"""
153154
Example function demonstrating the usage of the ART1 model.
154155
155-
This function creates a dataset, trains the ART1 model, and prints assigned clusters.
156+
This function creates a dataset, trains the ART1 model, and prints clusters.
156157
157158
Examples:
158159
>>> art1_example()

0 commit comments

Comments
 (0)
Please sign in to comment.