Fuzzy logic tool box as matlab
Project description
FuzzyLogic library
Authors: V.S. Luferov
Fuzzy Variables
Fuzzy Rules
subtract clusteting
(Data for su/examples/subclust.m.csv)[/examples/subclust.m.csv]
import numpy as np
from pprint import pprint
from fuzzy_logic.clustering import SubtractClustering
import csv
data = np.zeros([3, 600])
with open('m.csv') as f:
spamreader = csv.reader(f, delimiter=',')
for i, row in enumerate(spamreader):
data[0, i] = float(row[0])
data[1, i] = float(row[1])
data[2, i] = float(row[2])
sc = SubtractClustering(data, np.array([0.6] * 3))
pprint(sc())
Mamdani Fuzzy System
from pprint import pprint
from fuzzy_logic.terms import Term
from fuzzy_logic.variables import FuzzyVariable
from fuzzy_logic.mamdani_fs import MamdaniFuzzySystem
from fuzzy_logic.mf import TriangularMF
t1 = Term('mf1', TriangularMF(0, 0, 0.5))
t2 = Term('mf2', TriangularMF(0, 0.5, 1))
t3 = Term('mf3', TriangularMF(0.5, 1, 1))
input1: FuzzyVariable = FuzzyVariable('input1', 0, 1, t1, t2, t3)
input2: FuzzyVariable = FuzzyVariable(
'input2', 0, 1,
Term('mf1', TriangularMF(0, 0, 0.5)),
Term('mf2', TriangularMF(0, 0.5, 1)),
Term('mf3', TriangularMF(0.5, 1, 1))
)
output = FuzzyVariable(
'output', 0, 1,
Term('mf1', TriangularMF(0, 0, 0.5)),
Term('mf2', TriangularMF(0, 0.5, 1)),
Term('mf3', TriangularMF(0.5, 1, 1))
)
mf: MamdaniFuzzySystem = MamdaniFuzzySystem([input1, input2], [output])
mf.rules.append(mf.parse_rule('if (input1 is mf1) and (input2 is mf1) then (output is mf1)'))
mf.rules.append(mf.parse_rule('if (input1 is mf2) and (input2 is mf2) then (output is mf2)'))
result = mf.calculate({input1: 0.45, input2: 0.45})
pprint(result)
Sugeno Fuzzy System
from pprint import pprint
from fuzzy_logic.terms import Term
from fuzzy_logic.variables import FuzzyVariable, SugenoVariable, LinearSugenoFunction
from fuzzy_logic.sugeno_fs import SugenoFuzzySystem
from fuzzy_logic.mf import TriangularMF
t1: Term = Term('mf1', TriangularMF(0, 0, 0.5))
t2: Term = Term('mf2', TriangularMF(0, 0.5, 1))
t3: Term = Term('mf3', TriangularMF(0.5, 1, 1))
input1: FuzzyVariable = FuzzyVariable('input1', 0, 1, t1, t2, t3)
input2: FuzzyVariable = FuzzyVariable(
'input2', 0, 1,
Term('mf1', TriangularMF(0, 0, 0.5)),
Term('mf2', TriangularMF(0, 0.5, 1)),
Term('mf3', TriangularMF(0.5, 1, 1))
)
output: SugenoVariable = SugenoVariable(
'output',
LinearSugenoFunction('mf1', {input1: 0.1, input2: 0.3}, 0.5),
LinearSugenoFunction('mf2', {input1: 0.4, input2: 0.2}, 0.7)
)
mf: SugenoFuzzySystem = SugenoFuzzySystem([input1, input2], [output])
mf.rules.append(mf.parse_rule('if (input1 is mf1) and (input2 is mf1) then (output is mf1)'))
mf.rules.append(mf.parse_rule('if (input1 is mf2) and (input2 is mf2) then (output is mf2)'))
result = mf.calculate({input1: 0.45, input2: 0.45})
pprint(result)
Anfis
import numpy as np
from pprint import pprint
from fuzzy_logic.anfis import Anfis
x: np.ndarray = np.array([
[.1, .3, .5, .7, .9],
[.1, .2, .4, .6, .8]
])
y: np.ndarray = np.array([.01, .06, .2, .42, .72])
anfis: Anfis = Anfis(x, y, .5)
anfis.train()
pprint(f'{anfis.calculate([.2, .3])} == {.2 * .3}')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fuzzy_logic_toolbox-1.0.2.tar.gz
(17.6 kB
view details)
Built Distribution
File details
Details for the file fuzzy_logic_toolbox-1.0.2.tar.gz
.
File metadata
- Download URL: fuzzy_logic_toolbox-1.0.2.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33be3161910c4fed60f714677b88a42ff6c9445211ee5b3523d235b0b1148a19 |
|
MD5 | f7739190b2b00aecc64b5e1433226e05 |
|
BLAKE2b-256 | 8fd65258d7b9696c68519751c85ed294aaee008402f73b454dd206743bffa47b |
File details
Details for the file fuzzy_logic_toolbox-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: fuzzy_logic_toolbox-1.0.2-py3-none-any.whl
- Upload date:
- Size: 23.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b09ebead3a103036a69b8189b0f0e7940fda1f211533f1314c1b3bffe7681efe |
|
MD5 | eb3ca240d08a7f208f18cbd584095cb8 |
|
BLAKE2b-256 | 5ae907dc8c06467aac05130afe1752b8c6bca35e886c609f05d89699cebd4890 |