项目作者: devopshq

项目描述 :
Library contains some routines for work with fuzzy logic operators, fuzzy datasets and fuzzy scales. See article (ru): https://math-n-algo.blogspot.com/2014/08/FuzzyClassificator.html#chapter_3
高级语言: Python
项目地址: git://github.com/devopshq/FuzzyRoutines.git
创建时间: 2019-09-01T10:30:42Z
项目社区:https://github.com/devopshq/FuzzyRoutines

开源协议:MIT License

下载


FuzzyRoutines

Library contains some routines for work with fuzzy logic operators, fuzzy datasets and fuzzy scales.

FuzzyRoutines build status FuzzyRoutines on PyPI FuzzyRoutines license

Index:

Install" class="reference-link">Install

You can install FuzzyRoutines using pip:

  1. pip install fuzzyroutines [--upgrade] [--pre]

or using setuptools to build local version:

  1. git clone https://github.com/devopshq/FuzzyRoutines.git
  2. cd FuzzyRoutines
  3. python setup.py install

After installing you can check the version of the FuzzyRoutines library:

  1. pip show fuzzyroutines

Usage examples" class="reference-link">Usage examples

You can see and run Example.py script:

  1. cd fuzzyroutines
  2. python Examples.py

Example.py contains some examples of working with fuzzy library. Just copying and run examples below. Do not forget to import FuzzyRoutines module before use:

  1. from fuzzyroutines.FuzzyRoutines import *

Work with membership functions

Usage of some membership functions:

  1. mjuPars = {'a': 7, 'b': 4, 'c': 0} # hyperbolic params example
  2. funct = MFunction(userFunc='hyperbolic', **mjuPars) # creating instance of hyperbolic function
  3. print('Printing Membership function with parameters: ', funct)
  4. mjuPars = {'a': 0, 'b': 0.3, 'c': 0.4} # bell params example
  5. funct = MFunction(userFunc='bell', **mjuPars) # creating instance of bell function
  6. print('Printing Membership function with parameters: ', funct)
  7. mjuPars = {'a': 0, 'b': 1} # parabolic params example
  8. funct = MFunction(userFunc='parabolic', **mjuPars) # creating instance of parabolic function
  9. print('Printing Membership function with parameters: ', funct)
  10. mjuPars = {'a': 0.2, 'b': 0.8, 'c': 0.7} # triangle params example
  11. funct = MFunction(userFunc='triangle', **mjuPars) # creating instance of triangle function
  12. print('Printing Membership function with parameters: ', funct)
  13. mjuPars = {'a': 0.5, 'b': 0.15} # exponential params example
  14. funct = MFunction(userFunc='exponential', **mjuPars) # creating instance of exponential function
  15. print('Printing Membership function with parameters: ', funct)
  16. mjuPars = {'a': 15, 'b': 0.5} # sigmoidal params example
  17. funct = MFunction(userFunc='sigmoidal', **mjuPars) # creating instance of sigmoidal function
  18. print('Printing Membership function with parameters: ', funct)
  19. funct = MFunction(userFunc='desirability') # creating instance of desirability function without parameters
  20. print('Printing Membership function with parameters: ', funct)
  21. mjuPars = {'a': 0.1, 'b': 1, 'c': 0.5, 'd': 0.8} # trapezium params example
  22. funct = MFunction(userFunc='trapezium', **mjuPars) # creating instance of trapezium function
  23. print('Printing Membership function with parameters: ', funct)

Output:

  1. Printing Membership function with parameters: Hyperbolic(x, {"a": 7, "b": 4, "c": 0})
  2. Printing Membership function with parameters: Bell(x, {"a": 0, "b": 0.3, "c": 0.4})
  3. Printing Membership function with parameters: Parabolic(x, {"a": 0, "b": 1})
  4. Printing Membership function with parameters: Triangle(x, {"a": 0.2, "b": 0.8, "c": 0.7})
  5. Printing Membership function with parameters: Exponential(x, {"a": 0.5, "b": 0.15})
  6. Printing Membership function with parameters: Sigmoidal(x, {"a": 15, "b": 0.5})
  7. Printing Membership function with parameters: Desirability(y)
  8. Printing Membership function with parameters: Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8})

Calculating Trapezium function’s values in [0, 1]:

  1. xPar = 0
  2. for i in range(0, 10, 1):
  3. xPar = (xPar + i) / 10
  4. res = funct.mju(xPar) # calculate one value of MF with given parameters
  5. print('x = {:.1f}, {} = {:1.4f}'.format(xPar, funct, res))

Output:

  1. x = 0.0, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 0.0000
  2. x = 0.1, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 0.0000
  3. x = 0.2, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 0.2750
  4. x = 0.3, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 0.5525
  5. x = 0.4, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 0.8302
  6. x = 0.5, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 1.0000
  7. x = 0.7, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 1.0000
  8. x = 0.8, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 1.0000
  9. x = 0.9, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 0.6173
  10. x = 1.0, Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}) = 0.0617

Work with fuzzy set

  1. fuzzySet = FuzzySet(funct, (0., 1.)) # creating fuzzy set A = <mju_funct, support_set>
  2. print('Printing fuzzy set after init and before changes:', fuzzySet)
  3. print('Defuz({}) = {:1.2f}'.format(fuzzySet.name, fuzzySet.Defuz()))
  4. changedMjuPars = copy.deepcopy(mjuPars) # change parameters of membership function with deepcopy example:
  5. changedMjuPars['a'] = 0
  6. changedMjuPars['b'] = 1
  7. changedSupportSet = (0.5, 1) # change support set
  8. fuzzySet.name = 'Changed fuzzy set'
  9. fuzzySet.mFunction.parameters = changedMjuPars
  10. fuzzySet.supportSet = changedSupportSet
  11. print('New membership function with parameters: ', fuzzySet.mFunction)
  12. print('New support set: ', fuzzySet.supportSet)
  13. print('New value of Defuz({}) = {:1.2f}'.format(fuzzySet.name, fuzzySet.Defuz()))
  14. print('Printing fuzzy set after changes:', fuzzySet)

Output:

  1. Printing fuzzy set after init and before changes: FuzzySet = <Trapezium(x, {"a": 0.1, "b": 1, "c": 0.5, "d": 0.8}), [0.0, 1.0]>
  2. Defuz(FuzzySet) = 0.59
  3. New membership function with parameters: Trapezium(x, {"a": 0, "b": 1, "c": 0.5, "d": 0.8})
  4. New support set: (0.5, 1)
  5. New value of Defuz(Changed fuzzy set) = 0.59
  6. Printing fuzzy set after changes: Changed fuzzy set = <Trapezium(x, {"a": 0, "b": 1, "c": 0.5, "d": 0.8}), [0.5, 1]>

Work with fuzzy scales

Fuzzy scale is an ordered set of linguistic variables that looks like this:

S = [{‘name’: ‘name_1’, ‘fSet’: fuzzySet_1}, {‘name’: ‘name_2’, ‘fSet’: fuzzySet_2}, …]

where name is a linguistic name of fuzzy set, fSet is a user define fuzzy set of FuzzySet type.

  1. scale = FuzzyScale() # intialize new fuzzy scale with default levels
  2. print('Printing default fuzzy scale in human-readable:', scale)
  3. print('Defuz() of all default levels:')
  4. for item in scale.levels:
  5. print('Defuz({}) = {:1.2f}'.format(item['name'], item['fSet'].Defuz()))

Output:

  1. Printing default fuzzy scale in human-readable: DefaultScale = {Min, Med, High}
  2. Minimum = <Hyperbolic(x, {"a": 7, "b": 4, "c": 0}), [0.0, 1.0]>
  3. Medium = <Bell(x, {"a": 0.35, "b": 0.5, "c": 0.6}), [0.0, 1.0]>
  4. High = <Triangle(x, {"a": 0.7, "b": 1, "c": 1}), [0.0, 1.0]>
  5. Defuz() of all default levels:
  6. Defuz(Min) = 0.10
  7. Defuz(Med) = 0.55
  8. Defuz(High) = 0.90

Add new fuzzy levels:

  1. print('Define some new levels:')
  2. minFunct = MFunction('hyperbolic', **{'a': 2, 'b': 20, 'c': 0})
  3. levelMin = FuzzySet(membershipFunction=minFunct, supportSet=(0., 0.5), linguisticName='min')
  4. print('Printing Level 1 in human-readable:', levelMin)
  5. medFunct = MFunction('bell', **{'a': 0.4, 'b': 0.55, 'c': 0.7})
  6. levelMed = FuzzySet(membershipFunction=medFunct, supportSet=(0.25, 0.75), linguisticName='med')
  7. print('Printing Level 2 in human-readable:', levelMed)
  8. maxFunct = MFunction('triangle', **{'a': 0.65, 'b': 1, 'c': 1})
  9. levelMax = FuzzySet(membershipFunction=maxFunct, supportSet=(0.7, 1.), linguisticName='max')
  10. print('Printing Level 3 in human-readable:', levelMax)

Output:

  1. Define some new levels:
  2. Printing Level 1 in human-readable: min = <Hyperbolic(x, {"a": 2, "b": 20, "c": 0}), [0.0, 0.5]>
  3. Printing Level 2 in human-readable: med = <Bell(x, {"a": 0.4, "b": 0.55, "c": 0.7}), [0.25, 0.75]>
  4. Printing Level 3 in human-readable: max = <Triangle(x, {"a": 0.65, "b": 1, "c": 1}), [0.7, 1.0]>

Change scale levels:

  1. scale.name = 'New Scale'
  2. scale.levels = [{'name': levelMin.name, 'fSet': levelMin}, {'name': levelMed.name, 'fSet': levelMed},
  3. {'name': levelMax.name, 'fSet': levelMax}] # add new ordered set of linguistic variables into scale
  4. print('Changed List of levels as objects:', scale.levels)
  5. print('Printing changed fuzzy scale in human-readable:', scale)
  6. print('Defuz() of all New Scale levels:')
  7. for item in scale.levels:
  8. print('Defuz({}) = {:1.2f}'.format(item['name'], item['fSet'].Defuz()))

Output:

  1. Changed List of levels as objects: [{'name': 'min', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB3F17B8>}, {'name': 'med', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB337D68>}, {'name': 'max', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB3F18D0>}]
  2. Printing changed fuzzy scale in human-readable: New Scale = {min, med, max}
  3. min = <Hyperbolic(x, {"a": 2, "b": 20, "c": 0}), [0.0, 0.5]>
  4. med = <Bell(x, {"a": 0.4, "b": 0.55, "c": 0.7}), [0.25, 0.75]>
  5. max = <Triangle(x, {"a": 0.65, "b": 1, "c": 1}), [0.7, 1.0]>
  6. Defuz() of all New Scale levels:
  7. Defuz(min) = 0.24
  8. Defuz(med) = 0.61
  9. Defuz(max) = 0.89

Work with Universal Fuzzy Scale

Universal fuzzy scales S_f = {Min, Low, Med, High, Max} pre-defined in UniversalFuzzyScale() class.

  1. uniFScale = UniversalFuzzyScale()
  2. print('Levels of Universal Fuzzy Scale:', uniFScale.levels)
  3. print('Printing scale:', uniFScale)
  4. print('Defuz() of all Universal Fuzzy Scale levels:')
  5. for item in uniFScale.levels:
  6. print('Defuz({}) = {:1.2f}'.format(item['name'], item['fSet'].Defuz()))

Output:

  1. Levels of Universal Fuzzy Scale: [{'name': 'Min', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB34F7B8>}, {'name': 'Low', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB34F198>}, {'name': 'Med', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB34F048>}, {'name': 'High', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB34F0F0>}, {'name': 'Max', 'fSet': <fuzzyroutines.FuzzyRoutines.FuzzySet object at 0x000001AECB34F710>}]
  2. Printing scale: FuzzyScale = {Min, Low, Med, High, Max}
  3. Min = <Hyperbolic(x, {"a": 8, "b": 20, "c": 0}), [0.0, 0.23]>
  4. Low = <Bell(x, {"a": 0.17, "b": 0.23, "c": 0.34}), [0.17, 0.4]>
  5. Med = <Bell(x, {"a": 0.34, "b": 0.4, "c": 0.6}), [0.34, 0.66]>
  6. High = <Bell(x, {"a": 0.6, "b": 0.66, "c": 0.77}), [0.6, 0.83]>
  7. Max = <Parabolic(x, {"a": 0.77, "b": 0.95}), [0.77, 1.0]>
  8. Defuz() of all Universal Fuzzy Scale levels:
  9. Defuz(Min) = 0.06
  10. Defuz(Low) = 0.29
  11. Defuz(Med) = 0.50
  12. Defuz(High) = 0.71
  13. Defuz(Max) = 0.93

Use Fuzzy() function to looking for level on Fuzzy Scale:

  1. xPar = 0
  2. for i in range(0, 10, 1):
  3. xPar = (xPar + i) / 10
  4. res = uniFScale.Fuzzy(xPar) # calculate fuzzy level for some real values
  5. print('Fuzzy({:1.1f}, {}) = {}, {}'.format(xPar, uniFScale.name, res['name'], res['fSet']))

Output:

  1. Fuzzy(0.0, FuzzyScale) = Min, Min = <Hyperbolic(x, {"a": 8, "b": 20, "c": 0}), [0.0, 0.23]>
  2. Fuzzy(0.1, FuzzyScale) = Min, Min = <Hyperbolic(x, {"a": 8, "b": 20, "c": 0}), [0.0, 0.23]>
  3. Fuzzy(0.2, FuzzyScale) = Low, Low = <Bell(x, {"a": 0.17, "b": 0.23, "c": 0.34}), [0.17, 0.4]>
  4. Fuzzy(0.3, FuzzyScale) = Low, Low = <Bell(x, {"a": 0.17, "b": 0.23, "c": 0.34}), [0.17, 0.4]>
  5. Fuzzy(0.4, FuzzyScale) = Med, Med = <Bell(x, {"a": 0.34, "b": 0.4, "c": 0.6}), [0.34, 0.66]>
  6. Fuzzy(0.5, FuzzyScale) = Med, Med = <Bell(x, {"a": 0.34, "b": 0.4, "c": 0.6}), [0.34, 0.66]>
  7. Fuzzy(0.7, FuzzyScale) = High, High = <Bell(x, {"a": 0.6, "b": 0.66, "c": 0.77}), [0.6, 0.83]>
  8. Fuzzy(0.8, FuzzyScale) = High, High = <Bell(x, {"a": 0.6, "b": 0.66, "c": 0.77}), [0.6, 0.83]>
  9. Fuzzy(0.9, FuzzyScale) = Max, Max = <Parabolic(x, {"a": 0.77, "b": 0.95}), [0.77, 1.0]>
  10. Fuzzy(1.0, FuzzyScale) = Max, Max = <Parabolic(x, {"a": 0.77, "b": 0.95}), [0.77, 1.0]>

Finding fuzzy level using GetLevelByName() function with exact matching:

  1. print('Finding level by name with exact matching:')
  2. res = uniFScale.GetLevelByName('Min')
  3. print('GetLevelByName(Min, {}) = {}, {}'.format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
  4. res = uniFScale.GetLevelByName('High')
  5. print('GetLevelByName(High, {}) = {}, {}'.format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
  6. res = uniFScale.GetLevelByName('max')
  7. print('GetLevelByName(max, {}) = {}, {}'.format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))

Output:

  1. Finding level by name with exact matching:
  2. GetLevelByName(Min, FuzzyScale) = Min, Min = <Hyperbolic(x, {"a": 8, "b": 20, "c": 0}), [0.0, 0.23]>
  3. GetLevelByName(High, FuzzyScale) = High, High = <Bell(x, {"a": 0.6, "b": 0.66, "c": 0.77}), [0.6, 0.83]>
  4. GetLevelByName(max, FuzzyScale) = None, None

Finding fuzzy level using GetLevelByName() function without exact matching:

  1. print('Finding level by name without exact matching:')
  2. res = uniFScale.GetLevelByName('mIn', exactMatching=False)
  3. print("GetLevelByName('mIn', {}) = {}, {}".format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
  4. res = uniFScale.GetLevelByName('max', exactMatching=False)
  5. print("GetLevelByName('max', {}) = {}, {}".format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
  6. res = uniFScale.GetLevelByName('Hig', exactMatching=False)
  7. print("GetLevelByName('Hig', {}) = {}, {}".format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
  8. res = uniFScale.GetLevelByName('LOw', exactMatching=False)
  9. print("GetLevelByName('LOw', {}) = {}, {}".format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
  10. res = uniFScale.GetLevelByName('eD', exactMatching=False)
  11. print("GetLevelByName('eD', {}) = {}, {}".format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))
  12. res = uniFScale.GetLevelByName('Highest', exactMatching=False)
  13. print("GetLevelByName('Highest', {}) = {}, {}".format(uniFScale.name, res['name'] if res else 'None', res['fSet'] if res else 'None'))

Output:

  1. Finding level by name without exact matching:
  2. GetLevelByName('mIn', FuzzyScale) = Min, Min = <Hyperbolic(x, {"a": 8, "b": 20, "c": 0}), [0.0, 0.23]>
  3. GetLevelByName('max', FuzzyScale) = Max, Max = <Parabolic(x, {"a": 0.77, "b": 0.95}), [0.77, 1.0]>
  4. GetLevelByName('Hig', FuzzyScale) = None, None
  5. GetLevelByName('LOw', FuzzyScale) = Low, Low = <Bell(x, {"a": 0.17, "b": 0.23, "c": 0.34}), [0.17, 0.4]>
  6. GetLevelByName('eD', FuzzyScale) = None, None
  7. GetLevelByName('Highest', FuzzyScale) = None, None

Work with fuzzy logic operators

Checks that number is in [0, 1]:

  1. print('IsCorrectFuzzyNumberValue(0.5) =', IsCorrectFuzzyNumberValue(0.5))
  2. print('IsCorrectFuzzyNumberValue(1.1) =', IsCorrectFuzzyNumberValue(1.1))

Output:

  1. IsCorrectFuzzyNumberValue(0.5) = True
  2. IsCorrectFuzzyNumberValue(1.1) = False

Calculates result of fuzzy NOT, fuzzy NOT with alpha parameter and parabolic fuzzy NOT operations:

  1. print('FNOT(0.25) =', FuzzyNOT(0.25))
  2. print('FNOT(0.25, alpha=0.25) =', FuzzyNOT(0.25, alpha=0.25))
  3. print('FNOT(0.25, alpha=0.75) =', FuzzyNOT(0.25, alpha=0.75))
  4. print('FNOT(0.25, alpha=1) =', FuzzyNOT(0.25, alpha=1))
  5. print('FNOTParabolic(0.25, alpha=0.25) =', FuzzyNOTParabolic(0.25, alpha=0.25))
  6. print('FNOTParabolic(0.25, alpha=0.75) =', FuzzyNOTParabolic(0.25, alpha=0.75))

Output:

  1. FNOT(0.25) = 0.75
  2. FNOT(0.25, alpha=0.25) = 0.25
  3. FNOT(0.25, alpha=0.75) = 0.9166666666666666
  4. FNOT(0.25, alpha=1) = 1.0
  5. FNOTParabolic(0.25, alpha=0.25) = 0.25000000000000017
  6. FNOTParabolic(0.25, alpha=0.75) = 0.9820000000000008

Calculates result of fuzzy AND/OR operations:

  1. print('FuzzyAND(0.25, 0.5) =', FuzzyAND(0.25, 0.5))
  2. print('FuzzyOR(0.25, 0.5) =', FuzzyOR(0.25, 0.5))

Output:

  1. FuzzyAND(0.25, 0.5) = 0.25
  2. FuzzyOR(0.25, 0.5) = 0.5

Calculates result of T-Norm operations, where T-Norm is one of conjunctive operators - logic, algebraic, boundary, drastic:

  1. print("TNorm(0.25, 0.5, 'logic') =", TNorm(0.25, 0.5, normType='logic'))
  2. print("TNorm(0.25, 0.5, 'algebraic') =", TNorm(0.25, 0.5, normType='algebraic'))
  3. print("TNorm(0.25, 0.5, 'boundary') =", TNorm(0.25, 0.5, normType='boundary'))
  4. print("TNorm(0.25, 0.5, 'drastic') =", TNorm(0.25, 0.5, normType='drastic'))

Output:

  1. TNorm(0.25, 0.5, 'logic') = 0.25
  2. TNorm(0.25, 0.5, 'algebraic') = 0.125
  3. TNorm(0.25, 0.5, 'boundary') = 0
  4. TNorm(0.25, 0.5, 'drastic') = 0

Calculates result of S-coNorm operations, where S-coNorm is one of disjunctive operators - logic, algebraic, boundary, drastic:

  1. print("SCoNorm(0.25, 0.5, 'logic') =", SCoNorm(0.25, 0.5, normType='logic'))
  2. print("SCoNorm(0.25, 0.5, 'algebraic') =", SCoNorm(0.25, 0.5, normType='algebraic'))
  3. print("SCoNorm(0.25, 0.5, 'boundary') =", SCoNorm(0.25, 0.5, normType='boundary'))
  4. print("SCoNorm(0.25, 0.5, 'drastic') =", SCoNorm(0.25, 0.5, normType='drastic'))

Output:

  1. SCoNorm(0.25, 0.5, 'logic') = 0.5
  2. SCoNorm(0.25, 0.5, 'algebraic') = 0.625
  3. SCoNorm(0.25, 0.5, 'boundary') = 0.75
  4. SCoNorm(0.25, 0.5, 'drastic') = 1

Calculates result of T-Norm operations for N numbers, N > 2:

  1. print("TNormCompose(0.25, 0.5, 0.75, 'logic') =", TNormCompose(0.25, 0.5, 0.75, normType='logic'))
  2. print("TNormCompose(0.25, 0.5, 0.75, 'algebraic') =", TNormCompose(0.25, 0.5, 0.75, normType='algebraic'))
  3. print("TNormCompose(0.25, 0.5, 0.75, 'boundary') =", TNormCompose(0.25, 0.5, 0.75, normType='boundary'))
  4. print("TNormCompose(0.25, 0.5, 0.75, 'drastic') =", TNormCompose(0.25, 0.5, 0.75, normType='drastic'))

Output:

  1. TNormCompose(0.25, 0.5, 0.75, 'logic') = 0.25
  2. TNormCompose(0.25, 0.5, 0.75, 'algebraic') = 0.09375
  3. TNormCompose(0.25, 0.5, 0.75, 'boundary') = 0
  4. TNormCompose(0.25, 0.5, 0.75, 'drastic') = 0

Calculates result of S-coNorm operations for N numbers, N > 2:

  1. print("SCoNormCompose(0.25, 0.5, 0.75, 'logic') =", SCoNormCompose(0.25, 0.5, 0.75, normType='logic'))
  2. print("SCoNormCompose(0.25, 0.5, 0.75, 'algebraic') =", SCoNormCompose(0.25, 0.5, 0.75, normType='algebraic'))
  3. print("SCoNormCompose(0.25, 0.5, 0.75, 'boundary') =", SCoNormCompose(0.25, 0.5, 0.75, normType='boundary'))
  4. print("SCoNormCompose(0.25, 0.5, 0.75, 'drastic') =", SCoNormCompose(0.25, 0.5, 0.75, normType='drastic'))

Output:

  1. SCoNormCompose(0.25, 0.5, 0.75, 'logic') = 0.75
  2. SCoNormCompose(0.25, 0.5, 0.75, 'algebraic') = 0.90625
  3. SCoNormCompose(0.25, 0.5, 0.75, 'boundary') = 1
  4. SCoNormCompose(0.25, 0.5, 0.75, 'drastic') = 1

Working with other methods

Converting some strings to range of sorted unique numbers with DiapasonParser():

  1. print("Converting some strings to range of sorted unique numbers:")
  2. print('String "1,5" converted to:', DiapasonParser("1,5"))
  3. print('String "1-5" converted to:', DiapasonParser("1-5"))
  4. print('String "8-10, 1-5, 6" converted to:', DiapasonParser("8-10, 1-5, 6"))
  5. print('String "11, 11, 12, 12, 1-5, 3-7" converted to:', DiapasonParser("11, 12, 1-5, 3-7"))

Output:

  1. Converting some strings to range of sorted unique numbers:
  2. String "1,5" converted to: [1, 5]
  3. String "1-5" converted to: [1, 2, 3, 4, 5]
  4. String "8-10, 1-5, 6" converted to: [1, 2, 3, 4, 5, 6, 8, 9, 10]
  5. String "11, 11, 12, 12, 1-5, 3-7" converted to: [1, 2, 3, 4, 5, 6, 7, 11, 12]