Skip to main content

MohuPy is a fuzzy set calculation library, which contains fuzzy numbers, fuzzy measure, fuzzy sets and fuzzy membership functions.

Project description

MohuPy-2

MohuPy

简体中文 | English

MohuPy is a fuzzy mathematics computing toolkit, including the operations of q-rung orthopair fuzzy number(q-rofn), interval-valued q-rung orthopair fuzzy number(iv-q-rofn) and q-rung orthopair hesitant fuzzy numbers(q-rohfn) under algebraic norms. It also provides high-order operations and automatic differentiation for fuzzy vectors and the computational graph model of fuzzy number. It can be used to deal with irregular fuzzy computation, fuzzy decision-making related problems, general higher-order fuzzy computation problems, and differential derivative calculation problems of complex fuzzy functions.

Features

  • Addition, subtraction, multiplication and division of q-rofn, iv-q-rofn, q-rohfn sets with matrices and vectors;
  • Operations on high-dimensional fuzzy numbers, matrix operations and vector operations;
  • Fuzzy tensor operation and automatic differentiation of q-rofn, fuzzy computational graph model of q-rofn;
  • Representation of non-additive measure, Möbius transformation, calculation of non-additive measure;
  • Derivatives of non-additive measure set functions, Shannon entropy, Sugeno integral, Choquet integral and Shilkret integral;
  • Eight commonly used membership functions;
  • The basic usage of higher order fuzzy set and fuzzy vector, including arbitrary random shape, save, load, maximum minimum sum, etc.

Installation

pip install mohupy

Requirements

  1. python >= 3.10
  2. numpy >= 1.24
  3. scipy >= 1.10.0
  4. matplotlib >= 3.8.0
  5. pandas >= 1.5.0
  6. networkx >= 3.1.0

Get started

1. Create fuzzy number

Importing packages is simple, just

import mohupy as mp

Then, create a 3-rofn <0.7,0.4> as follows:

x = mp.fuzznum(3, 0.7, 0.4)
print(x)

Then it will be displayed as follows:

<0.7,0.4>

If you need to check the score, membership and non-membership degree of <0.7,0.4>, you can do it as follows:

print(x.score)
print(x.md, x.nmd)
0.2789999999999999
0.7 0.4

Note: The initial fuzzy number type is q-rofn, and the type of fuzzy number can be adjusted by mp.config.set_mtype() ,the global variable function. The type of fuzzy number is represented by .mtype , and .mtype='qrofn' represents q-rofn, .mtype='ivfn' represents iv-q-rofn and .mtype='qrohfn' represents q-rohfn.

mp.config.set_mtype('ivfn')
print(mp.config.Config.mtype)
'ivfn'

3. Fuzzy set(vector)

Fuzzy vectors can be created using mp.fuzzset() to create an empty fuzzy set(vector).

y = mp.fuzzset()
print(y)
Fuzzarray([], qrung=None, mtype=qrofn)

It is worth noting that this is an empty initialized fuzzy set(vector). Therefore, qrung = None, which represents a fuzzy number, is a null value that can be assigned in subsequent operations. For example, you can create a random iv-1-rofn fuzzy matrix:

mp.config.set_mtype('ivfn')
fuzzy_matrix = mp.rand_fuzz(5,2)
fuzzy_matrix
Fuzzarray([[<[0.1211 0.3985],[0.0445 0.5733]> <[0.1978 0.6394],[0.1696 0.3151]>]
           [<[0.3597 0.5338],[0.3082 0.3306]> <[0.3761 0.5476],[0.0515 0.372 ]>]
           [<[0.437  0.5267],[0.3074 0.3981]> <[0.2731 0.4707],[0.2992 0.4142]>]
           [<[0.0881 0.3158],[0.1707 0.5903]> <[0.1358 0.6692],[0.1511 0.2643]>]
           [<[0.0571 0.1164],[0.363  0.4567]> <[0.0259 0.0657],[0.2901 0.6906]>]], qrung=1, mtype=ivfn)

Of course, it is very simple to do the calculation directly on fuzzy_matrix. For example, the square can be calculated as follows

fuzzy_matrix ** 2
Fuzzarray([[<[0.0147 0.1588],[0.087  0.8179]> <[0.0391 0.4088],[0.3105 0.5309]>]
           [<[0.1294 0.285 ],[0.5214 0.5519]> <[0.1414 0.2998],[0.1003 0.6056]>]
           [<[0.191  0.2774],[0.5203 0.6377]> <[0.0746 0.2216],[0.5088 0.6568]>]
           [<[0.0078 0.0997],[0.3123 0.8321]> <[0.0184 0.4479],[0.2794 0.4588]>]
           [<[0.0033 0.0136],[0.5942 0.7049]> <[0.0007 0.0043],[0.4961 0.9043]>]], qrung=1, mtype=ivfn)

4. Fuzzy Tensor and Automatic Differentiation

Note that the current fuzzy tensor only supports q-rofn, and the description of iv-q-rofn and q-rohfn in the existing literature is lacking. A fuzzy tensor can be created by function tensor = mp.Fuzztensor(). Now, randomly generate a 2D fuzzy tensor and find the derivative with respect to x for a specific function f(x) = 0.2 * x.

x = mp.rand_tensor(5,2)
fx = 0.2 * x
fx.backward()
print(x)
print(fx)
print(x.grad)
Fuzztensor([[<0.0293,0.3409> <0.1657,0.4683>]
            [<0.142,0.3044> <0.6446,0.2342>]
            [<0.7509,0.0453> <0.0425,0.0003>]
            [<0.8818,0.1123> <0.2809,0.6213>]
            [<0.3699,0.4671> <0.1744,0.081>]], qrung=1, mtype=qrofn)

Fuzztensor([[<0.0059,0.8063> <0.0356,0.8592>]
            [<0.0302,0.7883> <0.1869,0.748>]
            [<0.2427,0.5385> <0.0086,0.1925>]
            [<0.3476,0.6458> <0.0638,0.9092>]
            [<0.0882,0.8588> <0.0376,0.6049>]], qrung=1, mtype=qrofn)

Fuzztensor([[<0.2,0.8> <0.2,0.8>]
            [<0.2,0.8> <0.2,0.8>]
            [<0.2,0.8> <0.2,0.8>]
            [<0.2,0.8> <0.2,0.8>]
            [<0.2,0.8> <0.2,0.8>]], qrung=1, mtype=qrofn)

5. Fuzzy measure

MohuPy also includes a non-additive measure calculation package. The main fuzzy measures include Dirac measure, Additive measure, Symmetric measure, lambda fuzzy measure and so on. In addition, it also includes Shapley index, Banzhaf index and fuzzy measure Shannon entropy. In terms of non-additive measure integrals, it includes Choquet Integral, Sugeno Integral and Shilkret Integral. Taking the array [0.4, 0.25, 0.37, 0.2] as an example, the dictionary representation of this array under lambda fuzzy measure is as follows

measure = [0.4,0.25,0.37,0.2]
mp.dict_rep(measure, mp.lambda_meas, measure)
{'{}': -0.0,
 'C1': 0.4,
 'C2': 0.25,
 'C1,C2': 0.60597,
 'C3': 0.37,
 'C1,C3': 0.704836,
 'C2,C3': 0.579272,
 'C1,C2,C3': 0.877251,
 'C4': 0.2,
 'C1,C4': 0.564776,
 'C2,C4': 0.427985,
 'C1,C2,C4': 0.752608,
 'C3,C4': 0.537418,
 'C1,C3,C4': 0.842768,
 'C2,C3,C4': 0.728261,
 'C1,C2,C3,C4': 1.0}

In particular, the Hasse diagram can also be used to view the measure value of the array under the lambda fuzzy measure.

mp.hasse_diagram(measure, mp.lambda_meas)
hasse diagram

If the Choquet integral of this array is required, it can be computed by the following code

mp.integral.choquet(measure, mp.lambda_meas)
0.34044280478185107

6. Fuzzy Plot

The dot graph of the fuzzy number makes it easy to see the position of the fuzzy number in the fuzzy area. In addition, you can also see the addition area, subtraction area, multiplication area and division area of the fuzzy number. MohuPy has built-in drawing methods, and they are very easy to write. For example, to draw a 3-rofn <0.7,0.4> and draw each of its operation areas, you can write it like this:

x = mp.fuzznum(3, 0.7,0.4)
mp.fuzz_plot(x)
fuzzyplot

Look at each domain of the fuzzy number separately and write code,

mp.fuzz_plot(x, add=True)
mp.fuzz_plot(x, sub=True)
mp.fuzz_plot(x, mul=True)
mp.fuzz_plot(x, div=True)
add sub
mul div

Even more, you can draw the distribution of all fuzzy numbers of a fuzzy set. Take 15 random iv-2-qrofns as an example,

mp.config.set_mtype('ivfn')
x = mp.rand_fuzz(15,qrung=2)
mp.fuzz_plot(x, alpha=0.1)
15ivfn

TODO

  • Adopt fuzzy regedit framework
  • q-rung orthopair hesitant fuzzy sets
  • Add more Archimedean norm operations and register (Einstein, Frank, Hamacher)
  • Gradient and automatic differentiation of fuzzy functions
  • Integrate the operations of fuzzy numbers and fuzzy sets into computational graph models
  • Fuzzy membership generator with membership degree function and non-membership degree function

Update Log

Update log: Log

Contact

email: yibocat@yeah.net

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mohupy-0.3.0.tar.gz (59.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mohupy-0.3.0-py3-none-any.whl (91.1 kB view details)

Uploaded Python 3

File details

Details for the file mohupy-0.3.0.tar.gz.

File metadata

  • Download URL: mohupy-0.3.0.tar.gz
  • Upload date:
  • Size: 59.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for mohupy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9730d38a5cf230c37617d6f9b182fb167715e5fc52ac59aadd7744efc5140351
MD5 ab23e1c5706568c0089ffac4548756a1
BLAKE2b-256 66e3a3d160d68dd6cde94b7285c537ba5cc381ca8f21a278ec99b49b97f652dd

See more details on using hashes here.

File details

Details for the file mohupy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mohupy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 91.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.9

File hashes

Hashes for mohupy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f30914da2ee69b0654f4212989c6c7ff7607bcbacb2020191ec5fbb9956ca0c9
MD5 491ef9f0a8f5e32a30888fd86baa189d
BLAKE2b-256 739fee8abb8cf639e04d3a015b932965a136fe394a7d053c82c5092db1bc7f9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page