From b72c6450771c903f63766d52adc63fdec6b04327 Mon Sep 17 00:00:00 2001 From: Lior Assouline Date: Sat, 6 Nov 2021 23:49:18 +0200 Subject: [PATCH] Update fuzzy_art.py Added Fast commit slow recode eq.8 in paper https://doi.org/10.1016/0893-6080(91)90056-B --- src/fuzzy_art.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fuzzy_art.py b/src/fuzzy_art.py index de0dda4..3599929 100644 --- a/src/fuzzy_art.py +++ b/src/fuzzy_art.py @@ -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 @@ -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