Skip to content

Instantly share code, notes, and snippets.

@mleyvaz
Created July 21, 2017 23:41
Show Gist options
  • Save mleyvaz/6c5d93448e8c63eb357d65853691d00a to your computer and use it in GitHub Desktop.
Save mleyvaz/6c5d93448e8c63eb357d65853691d00a to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fuzzy Decision Map Example #\n",
"## Maikel Leyva Vázquez ##\n",
"Mayo 2017"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"\n",
"Step 1: Compare the importance among criteria to derive the local weight vector using the eigenvalue approach. This should be done by domain experts according to the preference scale shown bellow.\n",
"\n",
"Table 1. Scale for realshionship among criteria\n",
"\n",
"|Description|Numerical Value|\n",
"|--|-------------------------------|\n",
"|Equal importance |1|\n",
"|Moderate importance |2|\n",
"|Strong importance |3|\n",
"|Very strong importance |4|\n",
"|Extreme importance |5|\n",
"Table 1.\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1. 0.25 0.2 0.2 0.33 3. 1. 0.2 0.25 0.25 0.5 ]\n",
" [ 4. 1. 1. 1. 2. 1. 0.33 0.33 1. 1. 1. ]\n",
" [ 5. 1. 1. 1. 4. 2. 2. 0.5 0.5 0.33 0.5 ]\n",
" [ 5. 1. 1. 1. 2. 3. 1. 0.33 0.25 0.25 0.33]\n",
" [ 3. 0.5 0.25 0.5 1. 3. 2. 2. 0.33 0.5 0.33]\n",
" [ 0.33 1. 0.33 0.33 0.33 1. 0.5 0.5 0.25 0.2 0.33]\n",
" [ 1. 3. 0.5 1. 0.5 2. 1. 0.5 0.33 0.25 0.5 ]\n",
" [ 5. 5. 2. 3. 0.5 2. 2. 1. 0.5 0.33 0.5 ]\n",
" [ 4. 4. 2. 4. 3. 4. 3. 2. 1. 0.5 0.5 ]\n",
" [ 4. 4. 3. 4. 2. 5. 4. 3. 2. 1. 0.33]\n",
" [ 2. 2. 2. 3. 3. 3. 2. 2. 2. 3. 1. ]]\n"
]
}
],
"source": [
"a=np.matrix([[1.00,0.25,0.20,0.20,0.33,3.00,1.00,0.20,0.25,0.25,0.50],\n",
" [4.00,1.00,1.00,1.00,2.00,1.00,0.33,0.33,1.00,1.00,1.00],\n",
" [5.00,1.00,1.00,1.00,4.00,2.00,2.00,0.50,0.50,0.33,0.50],\n",
" [5.00,1.00,1.00,1.00,2.00,3.00,1.00,0.33,0.25,0.25,0.33],\n",
" [3.00,0.50,0.25,0.50,1.00,3.00,2.00,2.00,0.33,0.50,0.33],\n",
" [0.33,1.00,0.33,0.33,0.33,1.00,0.50,0.50,0.25,0.20,0.33], \n",
" [1.00,3.00,0.50,1.00,0.50,2.00,1.00,0.50,0.33,0.25,0.50],\n",
" [5.00,5.00,2.00,3.00,0.50,2.00,2.00,1.00,0.50,0.33,0.50],\n",
" [4.00,4.00,2.00,4.00,3.00,4.00,3.00,2.00,1.00,0.50,0.50],\n",
" [4.00,4.00,3.00,4.00,2.00,5.00,4.00,3.00,2.00,1.00,0.33],\n",
" [2.00,2.00,2.00,3.00,3.00,3.00,2.00,2.00,2.00,3.00,1.00]])\n",
"print (a)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Eigen value method is applied"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0.10114946]\n",
" [ 0.2240859 ]\n",
" [ 0.23404327]\n",
" [ 0.18179133]\n",
" [ 0.18529311]\n",
" [ 0.08191048]\n",
" [ 0.14962954]\n",
" [ 0.28632044]\n",
" [ 0.38587305]\n",
" [ 0.47227449]\n",
" [ 0.44762893]]\n"
]
}
],
"source": [
"#print (a.sum(axis=0)) #Suma por columnas\n",
"b=a/a.sum(axis=0) # Se normalizan la matriz\n",
"\n",
"\n",
"eigen=0.25*(b.sum(axis=1))# se encuentra el promedio\n",
"print(eigen)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Step 2-Despict the fuzzy cognitive map to indict the influence among criteria"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"E=np.matrix([[0,0,0,0,0.64,0,0,0,0,0,0],[0,0,0,0,0,0,0.25,0,0,0,0],\n",
" [0,0,0,0,0,0.22,0.5,0,0,0,0],\n",
" [0,0,0,0,0.72,0,0,0,0,0,0],\n",
" [0,0,0,0,0,0,0,0,0,0,0],\n",
" [0,0,0,0,0,0,0,0,0,0,0], \n",
" [0,0,0,0,0,0,0,0,0,0,0],\n",
" [0,0.25,0,0,0,0,0.67,0,0,0,0],\n",
" [0,0,0,0,0,0,0,0,0,0,0.56],\n",
" [0,0,0,0.19,0,0,0,0,0,0,0.67],\n",
" [0,0,0,0,0.28,0,0,0,0,0,0]])\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Step 2-Found the steady-step matrix. Linear function "
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"[[ 0. 0. 0. 0. 0.64 0. 0. 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. 0.25 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0. 0. 0. 0. 0.22 0.5 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0. 0. 0. 0.72 0. 0. 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0.25 0. 0. 0. 0. 0.7325 0. 0. 0.\n",
" 0. ]\n",
" [ 0. 0. 0. 0. 0.1568 0. 0. 0. 0. 0.\n",
" 0.56 ]\n",
" [ 0. 0. 0. 0.19 0.3244 0. 0. 0. 0. 0.\n",
" 0.67 ]\n",
" [ 0. 0. 0. 0. 0.28 0. 0. 0. 0. 0.\n",
" 0. ]]\n"
]
}
],
"source": [
"def steady(M): \n",
" C=M\n",
" I=np.identity(len(M))\n",
" M.dot(I)\n",
" flag=True\n",
" print(flag)\n",
" c=0\n",
" C=M\n",
" T=M\n",
" while flag: \n",
" c=c+1\n",
" #print(flag)\n",
" C=M.dot(C+I) \n",
" #print(T)\n",
" #print(C) \n",
" flag=not((C==T).all())\n",
" #print(flag)\n",
" if c==50:\n",
" flag=False\n",
" T=C\n",
" #print(c)\n",
" return C\n",
"Ef=steady(E) \n",
"print(Ef)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Step 4 -Derive the global weight vector"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0.05261132]\n",
" [ 0.06682977]\n",
" [ 0.08166517]\n",
" [ 0.07696188]\n",
" [ 0.04843403]\n",
" [ 0.0214107 ]\n",
" [ 0.03911188]\n",
" [ 0.11139439]\n",
" [ 0.16259815]\n",
" [ 0.21052621]\n",
" [ 0.1284565 ]]\n"
]
}
],
"source": [
"\n",
"eigenn=(eigen/np.amax(eigen))\n",
"#print(eigenn)\n",
"# Normalizar la matriz\n",
"\n",
"Efn=Ef/np.amax(Ef.sum(axis=1)) #row sum\n",
"\n",
"w=eigenn+Efn.dot(eigenn)\n",
"\n",
"#print(w)\n",
"#Finally, normalize the global weight (W).\n",
"print(w/w.sum(axis=0))"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Referencias ##"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Yu, R., & Tzeng, G. H. (2006). A soft computing method for multi-criteria decision making with dependence and feedback. Applied Mathematics and Computation, 180(1), 63-75."
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"An extension of fuzzy decision maps for multi-criteria decision-making"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"http://www.sciencedirect.com/science/article/pii/S1110866513000212"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment