Discrete numeric fuzzy sets in Python algorithms.
Project description
dufuz
Incorporating discrete numeric fuzzy sets in Python algorithms. These sets are more general than fuzzy numbers.
Dependencies: numpy
, torch
, matplotlib
Contact: Manios Krasanakis (maniospas@hotmail.com)
License: Apache 2
:rocket: Quickstart
First create a discrete environment for spawning and executing operations
on numeric fuzzy sets. Provide a GPU torch
device to the environment
to parallelize execution. The device is used as one logical core.
import torch
from dufuz import DiscreteEnvironment
from dufuz import tnorm
env = DiscreteEnvironment(tnorm=tnorm.lukasiewicz,
tol=0.01, breadth=1,
device=torch.device('cuda:0'))
You can write algorithms involving normal Python operations.
If-then-else statements that involve fuzzy comparisons
take the form
condition.choose(result if true, result if false)
and fuzzy boolean arithmetics use the &,|
operations.
As a demonstration. the following code implements the bubblesort algorithm for a list of fuzzy numbers.
def bubblesort(values):
for i in range(len(values)):
for j in range(i+1, len(values)):
vali = values[i]
valj = values[j]
comparison = vali < valj
values[i] = comparison.choose(vali, valj)
values[j] = comparison.choose(valj, vali)
The list can be defined to hold triangle fuzzy numbers per:
values = list(range(8))
values = env.number(values)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.