Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fuzzy_art.py #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/fuzzy_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, pattern_size: int, vigilance: float, choice: float, learn_rat
self.learn_rate = learn_rate
self.categories = []
self.category_counts = []
self.category_committed = []

def train(self, pattern: np.array):
# check that pattern is the correct length
Expand Down Expand Up @@ -52,11 +53,17 @@ def choose_category(self, pattern: np.array):
# add a new one
self.categories.append(np.ones(self.pattern_size))
self.category_counts.append(0)
self.category_committed.append(False)
return N

def learn_pattern(self, J: int, pattern: np.array):
category = self.categories[J]
category = self.learn_rate * np.minimum(pattern, category) + (1 - self.learn_rate) * category
# Fast commit slow recode eq.8 in paper https://doi.org/10.1016/0893-6080(91)90056-B
if self.category_committed[J]:
category = self.learn_rate * np.minimum(pattern, category) + (1 - self.learn_rate) * category
else:
category = np.minimum(pattern, category)
self.category_committed[J] = True
self.categories[J] = category
self.category_counts[J] += 1

Expand Down