Coder Social home page Coder Social logo

valdecy / pydecision Goto Github PK

View Code? Open in Web Editor NEW
248.0 7.0 57.0 431 KB

pyDecision is a comprehensive Python library that encompasses a wide array of Multi-Criteria Decision Analysis (MCDA) methods. These powerful and versatile tools assist in making effective decisions by comparing alternatives based on multiple criteria, making it a valuable resource for researchers, analysts, and decision-makers.

License: Other

Python 100.00%
promethee ahp electre python-mcda-library gaia chatgpt mcda mcdm electre-i electre-ii electre-iii electre-iv electre-tri topsis

pydecision's Introduction

pyDecision

Introduction

A python library with the following MCDA methods: AHP (Analytic Hierarchy Process); Fuzzy AHP; PPF AHP (Proportional Picture Fuzzy AHP); ARAS (Additive Ratio ASsessment); Fuzzy ARAS; Borda; BWM (Best-Worst Method); Simplified BWM; Fuzzy BWM; CILOS (Criterion Impact LOSs); CoCoSo (COmbined COmpromise SOlution); CODAS (Combinative Distance-based Assessment); Copeland; COPRAS (Complex PRoportional Assessment); Fuzzy COPRAS; CRADIS (Compromise Ranking of Alternatives from Distance to Ideal Solution); CRITIC (CRiteria Importance Through Intercriteria Correlation); Fuzzy CRITIC; DEMATEL (DEcision MAking Trial and Evaluation Laboratory); Fuzzy DEMATEL; EDAS (Evaluation based on Distance from Average Solution); Fuzzy EDAS; Entropy; ELECTRE (I, I_s, I_v, II, III, IV, Tri-B); FUCOM (Full Consistency Method); Fuzzy FUCOM; GRA (Grey Relational Analysis); IDOCRIW (Integrated Determination of Objective CRIteria Weights); MABAC (Multi-Attributive Border Approximation area Comparison); MACBETH (Measuring Attractiveness by a Categorical Based Evaluation TecHnique); MAIRCA (Multi-Attributive Ideal-Real Comparative Analysis); MARA (Magnitude of the Area for the Ranking of Alternatives) ; MARCOS (Measurement of Alternatives and Ranking according to COmpromise Solution); MAUT (Multi-attribute Utility Theory); MEREC (MEthod based on the Removal Effects of Criteria); MOORA (Multi-Objective Optimization on the basis of Ratio Analysis); Fuzzy MOORA; MOOSRA (Multi-Objective Optimisation on the Basis of Simple Ratio Analysis); MULTIMOORA (Multi-Objective Optimization on the basis of Ratio Analisys Multiplicative Form); OCRA (Operational Competitiveness RAting); Fuzzy OCRA ; OPA (Ordinal Priority Approach); ORESTE (Organisation Rangement Et SynThesE de donnees relationnelles); PIV (Proximity Indexed Value); PROMETHEE (I, II, III, IV, V, VI, Gaia); EC PROMETHEE; RAFSI (Ranking of Alternatives through Functional mapping of criterion sub-intervals into a Single Interval); REGIME (REGIonal Multicriteria Elimination); ROC (Rank Ordered Centroid); ROV (Range Of Value); RRW (Rank Reciprocal Weighting); RSW (Rank Summed Weight); SAW (Simple Additive Weighting); SECA (Simultaneous Evaluation of Criteria and Alternatives); SMART (Simple Multi-Attribute Rating Technique); SPOTIS (Stable Preference Ordering Towards Ideal Solution); TODIM (TOmada de Decisao Interativa e Multicriterio - Interactive and Multicriteria Decision Making); PSI (Preference Selection Index); MPSI (Modified Preference Selection Index); TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution); Fuzzy TOPSIS; VIKOR (VIseKriterijumska Optimizacija I Kompromisno Resenje); Fuzzy VIKOR; WINGS (Weighted Influence Non-linear Gauge System); WISP (Integrated Simple Weighted Sum Product); Simple WISP; WSM (Weighted Sum Model); Fuzzy WSM; WPM (Weighted Product Model); Fuzzy WPM; WASPAS (Weighted Aggregates Sum Product Assessment); Fuzzy WASPAS.

pyDecision offers an array of features, including the comparison of ranking alternatives and comparison of criterion weights from various methods. The library is also fully integrated with chatGPT, elevating result interpretation through AI. Additionally, pyDecision provides the flexibility to import results from custom methods or those not yet implemented in the library for swift comparison.

Citation

PEREIRA, V.; BASILIO, M.P.; SANTOS, C.H.T (2024). Enhancing Decision Analysis with a Large Language Model: pyDecision a Comprehensive Library of MCDA Methods in Python. arXiv. https://arxiv.org/abs/2404.06370

Usage

  1. Install
pip install pyDecision
  1. Import
# Import AHP
from pyDecision.algorithm import ahp_method

# Parameters
weight_derivation = 'geometric' # 'mean'; 'geometric' or 'max_eigen'

# Dataset
dataset = np.array([
  #g1     g2     g3     g4     g5     g6     g7                  
  [1  ,   1/3,   1/5,   1  ,   1/4,   1/2,   3  ],   #g1
  [3  ,   1  ,   1/2,   2  ,   1/3,   3  ,   3  ],   #g2
  [5  ,   2  ,   1  ,   4  ,   5  ,   6  ,   5  ],   #g3
  [1  ,   1/2,   1/4,   1  ,   1/4,   1  ,   2  ],   #g4
  [4  ,   3  ,   1/5,   4  ,   1  ,   3  ,   2  ],   #g5
  [2  ,   1/3,   1/6,   1  ,   1/3,   1  ,   1/3],   #g6
  [1/3,   1/3,   1/5,   1/2,   1/2,   3  ,   1  ]    #g7
])

# Call AHP Function
weights, rc = ahp_method(dataset, wd = weight_derivation)

# Weigths
for i in range(0, weights.shape[0]):
  print('w(g'+str(i+1)+'): ', round(weights[i], 3))
  
# Consistency Ratio
print('RC: ' + str(round(rc, 2)))
if (rc > 0.10):
  print('The solution is inconsistent, the pairwise comparisons must be reviewed')
else:
  print('The solution is consistent')
  1. Try it in Colab:
  1. Compare Methods:
  1. Advanced MCDA Methods:
  • 3MOAHP - Inconsistency Reduction Technique for AHP and Fuzzy-AHP Methods
  • pyMissingAHP - A Method to Infer AHP Missing Pairwise Comparisons
  • ELECTRE-Tree - Algorithm to infer the ELECTRE Tri-B method parameters
  • Ranking-Trees - Algorithm to infer the ELECTRE II, III, IV, and PROMETHEE I, II, III, IV method parameters

Acknowledgement

This section is dedicated to everyone who helped improve or correct the code. Thank you very much!

pydecision's People

Contributors

sabir97 avatar valdecy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydecision's Issues

Methods use different python types for weight parameter

Some methods use python list for weight and others use numpy array.

E.g., TOPSIS uses weights = np.array([ [0.25, 0.25, 0.25, 0.25] ]), CoCoSo uses weight = [0.25, 0.25, 0.25, 0.25]. When I try to use different methods on the same data, I need to squezee numpy arrays or convert the list to numpy array.

It would be reasonable if all methods use the same type (either python list or numpy array).

Thank you for this library that contains many methods together.

Missing license

Please add a license, for example the MIT license, so that your project can be used by others.

Thank you.

What's the meaning of W Q S P

Thank you very much for your open source. Actually, I want to know the meaning of W, Q, S, P in p_ii.py .Thanks a lot

Non-beneficial criterion representation

Hello,

I want to know if there's a way specify that a criterion is non-beneficial, like in some cases we want to minimize a value for example (prices, costs, distance ...)

AHP Type 2

According to the published codes, this library is not able to be used in AHP Type 2, right? And do you have a solution for this issue?

Documentation about the methods and their parameters.

Hello,

thank you very much for implementing all these approaches. I would like to ask you if I can find somewhere a documentation that describes to your implementations (mainly the considered parameters).

In particular, I would like to know what are the Q S P W F parameters that are associated with the PROMETHEE II method.

TODIM

Hello, nice Python package for MCDA, do you have a solution for TODIM?

Answers not matching with AHP

I was checking the answers against the given Paper (pdf) and realized that answers are not matching for most of the algorithms, for example for AHP following should be the answers:

image

But i am getting following (although keeping input exactly same as given in the paper):
w(g1): 0.175
w(g2): 0.063
w(g3): 0.149
w(g4): 0.019
w(g5): 0.036
w(g6): 0.042
w(g7): 0.167
w(g8): 0.35

PROMETHEE criterion type is necessary

In PROMETHEE specifying the criterion type is necessary and it can't be replaced by using negative values or their inverse. Because in the research paper of PROMETHEE methods 2016, the author of PROMETHEE said that in case the criterion is a minimization criterion then we should either reverse the preference function or add a minus sign to the evaluative difference between the two alternatives. Which is different from using the negatives of two evaluations.
image

Decision analysis - Decision Tree

I created an app in R using shiny and the data.tree to help students with decision analysis / decision trees. Does your pyDecision package offer similar functionality to what is linked below? If not, do you perhaps know of python packages that do?

Data.Tree example:
https://cran.r-project.org/web/packages/data.tree/vignettes/applications.html#jenny-lind-decision-tree-plotting

Decision Analysis tool in Radiant:
https://radiant-rstats.github.io/docs/model/dtree.html

Question

Hello, does the bwm function only solves linear bwm?

Problem with openai dependency

Hi Valdecy,

There seems to be an issue with the openai-dependency in pyDecision:

I installed the latest version in a clean virtual Environment. When I execute your AHP-example i get the follwing error:

Traceback (most recent call last):
  File "/home/alex/Schreibtisch/test_pyDecision/pyD_error.py", line 2, in <module>
    from pyDecision.algorithm import ahp_method
  File "/home/alex/Schreibtisch/test_pyDecision/venv/lib/python3.11/site-packages/pyDecision/algorithm/__init__.py", line 52, in <module>
    from .p_v           import promethee_v
  File "/home/alex/Schreibtisch/test_pyDecision/venv/lib/python3.11/site-packages/pyDecision/algorithm/p_v.py", line 7, in <module>
    from pyDecision.util.ga import genetic_algorithm
  File "/home/alex/Schreibtisch/test_pyDecision/venv/lib/python3.11/site-packages/pyDecision/util/__init__.py", line 2, in <module>
    from .LLM import ask_chatgpt_corr, ask_chatgpt_rank, ask_chatgpt_weights 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alex/Schreibtisch/test_pyDecision/venv/lib/python3.11/site-packages/pyDecision/util/LLM.py", line 7, in <module>
    from openai import OpenAI
ImportError: cannot import name 'OpenAI' from 'openai' (/home/alex/Schreibtisch/test_pyDecision/venv/lib/python3.11/site-packages/openai/__init__.py)

Solution: I updated openai from 0.28.1 to the latest version 1.3.7 by executing:

pip install openai --upgrade

After that it worked fine. So you could raise the version of openai in your setup.py.

Best regards!
Alex

PROMETHEE Distance and Preference Degree Matrices Dimensions

In the promethee methods, i think the distance_array and pd_array have incorrect dimensions.
Distance matrix x axis has: n(n-1) elements (n being number of alternatives) and y axis has: m criteria.
Because each alternative is compared to other alternatives except itself, and those comparisons are done for each criterion.
Meaning the matrix dimensions for distance and preference are: n(n-1) x m
I found this after i was using memory_profiler to calculate the space complexity of different methods, and found that suprinsigly PROMETHEE 2 had took less space than MAUT, SAW and TOPSIS. Which is shouldn't happen.

BORDA research paper

1- I can't access the research paper associated with BORDA on the pyDecision website.
2- Is this method the same as BORDA Count ?
3- Why are the alternatives with lowest value ranked first ?
4- If this is the same as BORDA Count, BORDA Count doesn't support Multi criteria, it's a voting procedure.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.