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 8196fd2

Browse files
committedOct 31, 2024·
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b52bc75 commit 8196fd2

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed
 

‎neural_network/adaptive_resonance_theory_1.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
- - - - - -- - - - - - - - - - - - - - - - - - - - - - -
2+
- - - - - -- - - - - - - - - - - - - - - - - - - - - - -
33
Name - - ART1 - Adaptive Resonance Theory 1
44
Goal - - Cluster Binary Data
55
Detail: Unsupervised clustering model using a vigilance parameter
@@ -10,54 +10,55 @@
1010
Author: Your Name
1111
Github: your_email@example.com
1212
Date: 2024.10.31
13-
- - - - - -- - - - - - - - - - - - - - - - - - - - - - -
13+
- - - - - -- - - - - - - - - - - - - - - - - - - - - - -
1414
"""
1515

1616
import numpy as np
1717

18+
1819
class ART1:
1920
def __init__(self, num_features, vigilance=0.8):
2021
"""
2122
Initialize the ART1 model with the number of features and the vigilance parameter.
22-
23+
2324
Parameters:
2425
num_features (int): Number of features in input binary data.
2526
vigilance (float): Vigilance parameter to control cluster formation (0 < vigilance <= 1).
2627
"""
2728
self.num_features = num_features
2829
self.vigilance = vigilance
2930
self.weights = [] # Stores the weights for clusters
30-
31+
3132
def _similarity(self, x, w):
3233
"""
3334
Calculate similarity between input vector x and weight vector w.
34-
35+
3536
Parameters:
3637
x (np.array): Input binary vector.
3738
w (np.array): Cluster weight vector.
38-
39+
3940
Returns:
4041
float: Similarity value based on the intersection over the input length.
4142
"""
4243
return np.sum(np.minimum(x, w)) / np.sum(x)
43-
44+
4445
def _weight_update(self, x, w):
4546
"""
4647
Update weights for a cluster based on input vector.
47-
48+
4849
Parameters:
4950
x (np.array): Input binary vector.
5051
w (np.array): Cluster weight vector.
51-
52+
5253
Returns:
5354
np.array: Updated weight vector.
5455
"""
5556
return np.minimum(x, w)
56-
57+
5758
def train(self, data):
5859
"""
5960
Train the ART1 model to form clusters based on the vigilance parameter.
60-
61+
6162
Parameters:
6263
data (np.array): Binary dataset with each row as a sample.
6364
"""
@@ -72,14 +73,14 @@ def train(self, data):
7273
break
7374
if not assigned:
7475
self.weights.append(x.copy())
75-
76+
7677
def predict(self, x):
7778
"""
7879
Predict the cluster for a new input vector or classify it as a new cluster.
79-
80+
8081
Parameters:
8182
x (np.array): Input binary vector.
82-
83+
8384
Returns:
8485
int: Cluster index for the input or -1 if classified as a new cluster.
8586
"""
@@ -89,11 +90,11 @@ def predict(self, x):
8990
if similarity >= self.vigilance:
9091
return i
9192
return -1
92-
93+
9394
def get_weights(self):
9495
"""
9596
Retrieve the weight vectors of the clusters.
96-
97+
9798
Returns:
9899
list: List of weight vectors for each cluster.
99100
"""

0 commit comments

Comments
 (0)
Please sign in to comment.