IPython-Notebook

Demo of pyhasse.fuzzy

Aim of the program

Application of fuzzy concepts within the framework of partial orders is one interesting option to take into regard that not any slight numerical difference is considered as relevant for a ranking.

If not already done

Comment out or delete the following line if the module is installed.

In [1]:
#!pip install pyhasse.fuzzy

import all necessary libraries

In [2]:
import pathlib
from pyhasse.core.csv_io import CSVReader
from pyhasse.core.order import Order
from pyhasse.fuzzy.calc import Fuzzy
import json
from IPython.core.display import display, HTML
from string import Template
In [3]:
TESTFILENAME = '/csvdata/a_test12.txt'
HERE = pathlib.Path('__file__').parent
csv = CSVReader(fn=str(HERE) + TESTFILENAME, ndec=3)
red = csv.calc_reduced_system()
order = Order(csv.dmred,
              csv.redrows,
              csv.cols)
zeta = order.calc_relatmatrix(csv.dmred,
                              csv.redrows,
                              csv.cols)
redrows = csv.redrows
down = order.calc_downset(zeta, redrows)
up = order.calc_upset(zeta, redrows)

Some basic data

In [4]:
# print(csv.rows)
# print(csv.cols)
# print(csv.prop)
# print(csv.obj)
# print(csv.objred)
# print(csv.data)

your/user input

In [5]:
ndec = 3 
acut = 0.6
In [6]:
rows = csv.rows
cols = csv.cols
dm = csv.data
obj = csv.obj
prop = csv.prop
fuzzy = Fuzzy(rows, cols, dm, obj, prop, ndec)
sh = fuzzy.calc_koskomatrix(dm, rows, cols)
relat = fuzzy.fuzzyproduct(sh)
lr = len(relat)
for i1 in range(0, lr):
    for i2 in range(0, lr):
        relat[i1][i2] = round(relat[i1][i2], ndec)
# Note, the values of relat matrix should be sorted increasingly
# and delivered to the user

crisp_relat = fuzzy.calc_crisp_matrix(relat, acut)
objred_fuzzy_act = fuzzy.generate_representative_elements(crisp_relat)
In [7]:
objred_fuzzy_act
Out[7]:
['0', '4', '12', '16']
In [8]:
# todo: show more calcualtiosn...