Skip to content

Commit

Permalink
parallelized fuzzy logic code
Browse files Browse the repository at this point in the history
  • Loading branch information
ichensang committed Jun 26, 2024
1 parent e3e7452 commit ba8b512
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 138 deletions.
4 changes: 2 additions & 2 deletions fuzzylab/FuzzyInferenceSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def addRule(self, rule_matrix):
def __addVariable(self, in_or_out, *varargin, **options):
new_variable = fisvar(*varargin, **options)

if in_or_out == 'input':
if in_or_out is 'input':
self.Inputs.append(new_variable)
if(options.get('NumMFs')):
numMFs = options.get('NumMFs')
Expand Down Expand Up @@ -90,7 +90,7 @@ def __addVariable(self, in_or_out, *varargin, **options):
self.addMF(var_name, mf_type, params, Name='mf'+str(i+1))
b += step

if numMFs == 2:
if numMFs is 2:
i = 0

if(options.get('MFmaxr')):
Expand Down
1 change: 1 addition & 0 deletions fuzzylab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from fuzzylab.trimf import trimf
from fuzzylab.trapmf import trapmf
from fuzzylab.defuzz import defuzz
from fuzzylab.linspace import linspace
from fuzzylab.arange import arange
from fuzzylab.gbellmf import gbellmf
from fuzzylab.gaussmf import gaussmf
Expand Down
13 changes: 10 additions & 3 deletions fuzzylab/defuzz.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# defuzz.py
# Eduardo Avelar
# August 2022
# October 2018

import numpy as np

def defuzz(x, y, defuzz_method):

x = x.reshape(len(x),1)
if defuzz_method == 'centroid':
total_area = sum(y)
total_area = np.sum(y, axis = 0)
inner = np.sum(x*y, axis = 0)
output = sum(y * x) / total_area
return sum(y * x) / total_area

elif defuzz_method == 'bisector':
print("new version to be edited")
total_area = sum(y)
data_n = len(x)
tmp = y[0]
Expand All @@ -19,12 +23,15 @@ def defuzz(x, y, defuzz_method):
break
return x[k]
elif defuzz_method == 'mom':
print("new version to be edited")
return np.mean(x[y == max(y)])
elif defuzz_method == 'som':
print("new version to be edited")
tmp = x[y == max(y)]
which = np.argmin(abs(tmp))
return tmp[which]
elif defuzz_method == 'lom':
print("new version to be edited")
tmp = x[y == max(y)]
which = np.argmax(abs(tmp))
return tmp[which]
Expand Down
Loading

0 comments on commit ba8b512

Please sign in to comment.