{ "cells": [ { "cell_type": "markdown", "id": "f64b3f47", "metadata": {}, "source": [ "# Sets and set functions\n", "\n", "First we configure the notebook so we can use auto-completion." ] }, { "cell_type": "code", "execution_count": 1, "id": "b032368c", "metadata": {}, "outputs": [], "source": [ "%config Completer.use_jedi = False" ] }, { "cell_type": "markdown", "id": "86a7f595", "metadata": {}, "source": [ "We can then import the functions of the `set_functions` module." ] }, { "cell_type": "code", "execution_count": 2, "id": "ab22390a", "metadata": {}, "outputs": [], "source": [ "from mcda.set_functions import *" ] }, { "cell_type": "markdown", "id": "ecf03799", "metadata": {}, "source": [ "## Hashable Set\n", "\n", "Hashable sets are, as they name suggest, python sets with a defined hash method. This enables them to be used as keys in a dictionary.\n", "\n", "You can create a `HashableSet` as you would create a python set:" ] }, { "cell_type": "code", "execution_count": 3, "id": "d9bec4c6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'c01', 'c02', 'c03'}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HashableSet({\"c01\", \"c02\", \"c03\"})" ] }, { "cell_type": "markdown", "id": "b05c6ca2", "metadata": {}, "source": [ "As they are a subclass of python sets, they share most of their methods:" ] }, { "cell_type": "code", "execution_count": 4, "id": "5626d9f4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'c01', 'c03'}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HashableSet({\"c01\", \"c02\", \"c03\"}).difference({\"c02\"})" ] }, { "cell_type": "markdown", "id": "117d7854", "metadata": {}, "source": [ "Note than whenever a set method will return a python set, you can simply put its result in a `HashableSet`:" ] }, { "cell_type": "code", "execution_count": 5, "id": "336c8478", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'c01', 'c03'}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HashableSet({\"c01\", \"c02\", \"c03\"}.difference({\"c02\"}))" ] }, { "cell_type": "markdown", "id": "04373e06", "metadata": {}, "source": [ "As mentionned before, the main purpose of this class is to enable using sets as keys in a dictionary:" ] }, { "cell_type": "code", "execution_count": 6, "id": "76eca454", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{HashableSet(): 0, {'c01', 'c02'}: 1, {'c03'}: 2, {'c01', 'c03'}: 3}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d = {\n", " HashableSet(): 0,\n", " HashableSet({\"c01\", \"c02\"}): 1,\n", " HashableSet({\"c03\"}): 2,\n", " HashableSet({\"c03\", \"c01\"}): 3\n", "}\n", "d" ] }, { "cell_type": "code", "execution_count": 7, "id": "1e4fdec3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d[HashableSet()]" ] }, { "cell_type": "markdown", "id": "d6e649ce", "metadata": {}, "source": [ "As the keys are sets, they are unordered:" ] }, { "cell_type": "code", "execution_count": 8, "id": "8cd57904", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d[HashableSet({\"c02\", \"c01\"})]" ] }, { "cell_type": "code", "execution_count": 9, "id": "eb8a7352", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d[HashableSet({\"c01\", \"c02\"})]" ] }, { "cell_type": "markdown", "id": "795ef3ae", "metadata": {}, "source": [ "## Set functions\n", "\n", "### Creation\n", "\n", "Sets functions are functions defined on a power set. This means they have a value for each possible set in an ensemble. In this package, those functions are represented as classes. They can be initialized by giving them their values for each set using either a dictionary, or directly the list of values in logical order (the same way you read a binary mask w.r.t its integer representation). We can also provide it with the ensemble as a list, to keep the order of elements in the ensemble.\n", "\n", "Say we have the following set function:" ] }, { "cell_type": "code", "execution_count": 10, "id": "453707f1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "({HashableSet(): 0, HashableSet({'c01'}): 0.1, HashableSet({'c02'}): 0.2, HashableSet({'c01', 'c02'}): 0.2, HashableSet({'c03'}): 0.1, HashableSet({'c01', 'c03'}): 0.25, HashableSet({'c02', 'c03'}): 0.5, HashableSet({'c01', 'c02', 'c03'}): 1})" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "criteria = [\"c01\", \"c02\", \"c03\"]\n", "f = SetFunction(\n", " {\n", " (): 0,\n", " (\"c01\",): 0.1,\n", " (\"c02\",): 0.2,\n", " (\"c01\", \"c02\"): 0.2,\n", " (\"c03\",): 0.1,\n", " (\"c01\", \"c03\"): 0.25,\n", " (\"c03\", \"c02\"): 0.5,\n", " tuple(criteria): 1\n", " }\n", ")\n", "f" ] }, { "cell_type": "markdown", "id": "0fd7667c", "metadata": {}, "source": [ "N.B: the internal representation of the class `SetFunction` uses a dictionary with `HashableSet` as keys. But as they are more verbose to write, we recommend using tuples as keys when initializing a `SetFunction` (though any hashable structure could be used).\n", "\n", "N.B: we have wrote the set functions values in the logical order, though it is only mandatory if providing the values as a list." ] }, { "cell_type": "code", "execution_count": 11, "id": "06aa3df9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[HashableSet(),\n", " {'c01'},\n", " {'c02'},\n", " {'c01', 'c02'},\n", " {'c03'},\n", " {'c01', 'c03'},\n", " {'c02', 'c03'},\n", " {'c01', 'c02', 'c03'}]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HashableSet.logical_order(criteria)" ] }, { "cell_type": "markdown", "id": "c9e2ee48", "metadata": {}, "source": [ "We can check the set function ensemble:" ] }, { "cell_type": "code", "execution_count": 12, "id": "94527364", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['c01', 'c02', 'c03']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.ensemble" ] }, { "cell_type": "markdown", "id": "93fe1efc", "metadata": {}, "source": [ "As the constructor infers the ensemble list as the elements in the dictionary keys in the order he meets them, the ensemble could be in a wrong order.\n", "\n", "You can provide the ensemble yourself to fix that:" ] }, { "cell_type": "code", "execution_count": 13, "id": "cddf24ea", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['c01', 'c02', 'c03']" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f2 = SetFunction(\n", " {\n", " (): 0,\n", " (\"c01\",): 0.1,\n", " (\"c01\", \"c03\"): 0.25,\n", " (\"c02\",): 0.2,\n", " (\"c03\",): 0.1,\n", " (\"c01\", \"c02\"): 0.2,\n", " (\"c03\", \"c02\"): 0.5,\n", " tuple(criteria): 1\n", " },\n", " criteria\n", ")\n", "f2.ensemble" ] }, { "cell_type": "markdown", "id": "20eb2172", "metadata": {}, "source": [ "We can also initialize the same set function by giving it the values as a list:" ] }, { "cell_type": "code", "execution_count": 14, "id": "442ce3de", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "({HashableSet(): 0, HashableSet({'c01'}): 0.1, HashableSet({'c02'}): 0.2, HashableSet({'c01', 'c02'}): 0.2, HashableSet({'c03'}): 0.1, HashableSet({'c01', 'c03'}): 0.2, HashableSet({'c02', 'c03'}): 0.5, HashableSet({'c01', 'c02', 'c03'}): 1})" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f2 = SetFunction([0, 0.1, 0.2, 0.2, 0.1, 0.2, 0.5, 1], criteria)\n", "f2" ] }, { "cell_type": "markdown", "id": "a052ded7", "metadata": {}, "source": [ "If we don't provide an ensemble and a list of values is used, the ensemble of positive integers will be assumed:" ] }, { "cell_type": "code", "execution_count": 15, "id": "68ab4e95", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f2 = SetFunction([0, 0.1, 0.2, 0.2, 0.1, 0.2, 0.5, 1])\n", "f2.ensemble" ] }, { "cell_type": "markdown", "id": "98184cff", "metadata": {}, "source": [ "If you want a clearer representation of a set function, you can look at its values dictionary directly:" ] }, { "cell_type": "code", "execution_count": 16, "id": "e485d8da", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{HashableSet(): 0,\n", " {0}: 0.1,\n", " {1}: 0.2,\n", " {0, 1}: 0.2,\n", " {2}: 0.1,\n", " {0, 2}: 0.2,\n", " {1, 2}: 0.5,\n", " {0, 1, 2}: 1}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f2.values" ] }, { "cell_type": "markdown", "id": "cf38ef7a", "metadata": {}, "source": [ "### Call set functions\n", "\n", "In order to get the values of a set function for a particular set of elements, we simply need to provide the elements as arguments of the set functions called as a regular python function:" ] }, { "cell_type": "code", "execution_count": 17, "id": "b74ceb11", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f() # empty set" ] }, { "cell_type": "code", "execution_count": 18, "id": "1ee74d89", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.2" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f(\"c02\")" ] }, { "cell_type": "code", "execution_count": 19, "id": "649cdd17", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.25" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f(\"c01\", \"c03\")" ] }, { "cell_type": "code", "execution_count": 20, "id": "c4b5a3ce", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f(*f.ensemble) # complete set" ] }, { "cell_type": "markdown", "id": "72550444", "metadata": {}, "source": [ "### Usage\n", "\n", "We have a lot of functions defined for set functions. We can split them in different categories:\n", "* Check type constraints of set functions\n", "* Analysis of aggregation represented in set functions\n", "* Transformations\n", "\n", "But before continuing, let's define a set function that will be our example for the following. It is a normal capacity:" ] }, { "cell_type": "code", "execution_count": 21, "id": "f21b782f", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "({HashableSet(): 0.0, HashableSet({0}): 0.07692307692307693, HashableSet({1}): 0.15384615384615385, HashableSet({0, 1}): 0.38461538461538464, HashableSet({2}): 0.23076923076923078, HashableSet({0, 2}): 0.46153846153846156, HashableSet({1, 2}): 0.6153846153846154, HashableSet({0, 1, 2}): 0.8461538461538461, HashableSet({3}): 0.3076923076923077, HashableSet({0, 3}): 0.5384615384615384, HashableSet({1, 3}): 0.6923076923076923, HashableSet({0, 1, 3}): 0.9230769230769231, HashableSet({2, 3}): 0.7692307692307693, HashableSet({0, 2, 3}): 1.0, HashableSet({1, 2, 3}): 1, HashableSet({0, 1, 2, 3}): 1})" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l = [i / 13 for i in range(14)] + [1, 1]\n", "capacity = [0 for _ in range(len(l))]\n", "for i, index in enumerate(HashableSet.cardinal_range(len(l))):\n", " capacity[index] = l[i]\n", "capacity = SetFunction(capacity)\n", "capacity" ] }, { "cell_type": "markdown", "id": "964df946", "metadata": {}, "source": [ "N.B: We are instanciating the capacity in the natural order" ] }, { "cell_type": "code", "execution_count": 22, "id": "8bb2a3f8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[HashableSet(),\n", " {0},\n", " {1},\n", " {2},\n", " {3},\n", " {0, 1},\n", " {0, 2},\n", " {0, 3},\n", " {1, 2},\n", " {1, 3},\n", " {2, 3},\n", " {0, 1, 2},\n", " {0, 1, 3},\n", " {0, 2, 3},\n", " {1, 2, 3},\n", " {0, 1, 2, 3}]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "HashableSet.natural_order([0, 1, 2, 3])" ] }, { "cell_type": "markdown", "id": "493227e7", "metadata": {}, "source": [ "We can also create quickly the uniform capacity of any size:" ] }, { "cell_type": "code", "execution_count": 23, "id": "b0085ad7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "({HashableSet(): 0.0, HashableSet({0}): 0.25, HashableSet({1}): 0.25, HashableSet({0, 1}): 0.5, HashableSet({2}): 0.25, HashableSet({0, 2}): 0.5, HashableSet({1, 2}): 0.5, HashableSet({0, 1, 2}): 0.75, HashableSet({3}): 0.25, HashableSet({0, 3}): 0.5, HashableSet({1, 3}): 0.5, HashableSet({0, 1, 3}): 0.75, HashableSet({2, 3}): 0.5, HashableSet({0, 2, 3}): 0.75, HashableSet({1, 2, 3}): 0.75, HashableSet({0, 1, 2, 3}): 1.0})" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_capacity = SetFunction.uniform_capacity([0, 1, 2, 3])\n", "u_capacity" ] }, { "cell_type": "markdown", "id": "c8297e5c", "metadata": {}, "source": [ "#### Check function type constraints\n", "\n", "The set functions checks if its constraints are valid upon instanciation.\n", "We could also check all the other constraints to have a better understanding of the capacity we defined. Some are implicit, any capacity is a game and obviously a set function, but others are more peculiar." ] }, { "cell_type": "code", "execution_count": 24, "id": "ff0e25ed", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity.is_powerset_function" ] }, { "cell_type": "code", "execution_count": 25, "id": "3fa95f82", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity.is_game" ] }, { "cell_type": "code", "execution_count": 26, "id": "d5982d12", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity.is_monotonous" ] }, { "cell_type": "code", "execution_count": 27, "id": "9f0a569a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity.is_additive" ] }, { "cell_type": "code", "execution_count": 28, "id": "9d9e2ff4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity.is_cardinality_based" ] }, { "cell_type": "markdown", "id": "b7f0c42d", "metadata": {}, "source": [ "We can use those to verify the uniform capacity is indeed uniform (additive, cardinality-based, normal):" ] }, { "cell_type": "code", "execution_count": 29, "id": "72ad1eb6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_capacity.is_additive" ] }, { "cell_type": "code", "execution_count": 30, "id": "ae1f6580", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_capacity.is_cardinality_based" ] }, { "cell_type": "code", "execution_count": 31, "id": "36950f8e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_capacity.is_normal" ] }, { "cell_type": "markdown", "id": "c3045069", "metadata": {}, "source": [ "#### Analysis of aggregation\n", "\n", "This package implements the following metrics (for regular and möbius representation):\n", "* shapley values\n", "* interaction indexes" ] }, { "cell_type": "code", "execution_count": 32, "id": "2ca5c9fa", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 0.134615\n", "1 0.211538\n", "2 0.288462\n", "3 0.365385\n", "dtype: float64" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity.shapley" ] }, { "cell_type": "code", "execution_count": 33, "id": "b5eb7321", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123
0NaN-0.025641-0.025641-0.025641
1-0.025641NaN-0.064103-0.064103
2-0.025641-0.064103NaN-0.064103
3-0.025641-0.064103-0.064103NaN
\n", "
" ], "text/plain": [ " 0 1 2 3\n", "0 NaN -0.025641 -0.025641 -0.025641\n", "1 -0.025641 NaN -0.064103 -0.064103\n", "2 -0.025641 -0.064103 NaN -0.064103\n", "3 -0.025641 -0.064103 -0.064103 NaN" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "capacity.interaction_index" ] }, { "cell_type": "markdown", "id": "77d0f88b", "metadata": {}, "source": [ "#### Transformations\n", "\n", "As of today, the package only implements the Möbius transformation and its inverse." ] }, { "cell_type": "code", "execution_count": 34, "id": "b521e604", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "({HashableSet(): 0.0, HashableSet({0}): 0.07692307692307693, HashableSet({1}): 0.15384615384615385, HashableSet({0, 1}): 0.15384615384615385, HashableSet({2}): 0.23076923076923078, HashableSet({0, 2}): 0.15384615384615385, HashableSet({1, 2}): 0.23076923076923078, HashableSet({0, 1, 2}): -0.15384615384615385, HashableSet({3}): 0.3076923076923077, HashableSet({0, 3}): 0.1538461538461538, HashableSet({1, 3}): 0.23076923076923073, HashableSet({0, 1, 3}): -0.15384615384615374, HashableSet({2, 3}): 0.23076923076923073, HashableSet({0, 2, 3}): -0.15384615384615374, HashableSet({1, 2, 3}): -0.3846153846153846, HashableSet({0, 1, 2, 3}): -0.0769230769230771})" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mobius = capacity.mobius\n", "mobius" ] }, { "cell_type": "markdown", "id": "7489c632", "metadata": {}, "source": [ "We can quickly look at the accuracy of both transformation and its inverse:" ] }, { "cell_type": "code", "execution_count": 35, "id": "b72f0695", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.0 -> 0.0\n", "0.07692307692307693 -> 0.07692307692307693\n", "0.15384615384615385 -> 0.15384615384615385\n", "0.38461538461538464 -> 0.38461538461538464\n", "0.23076923076923078 -> 0.23076923076923078\n", "0.46153846153846156 -> 0.46153846153846156\n", "0.6153846153846154 -> 0.6153846153846154\n", "0.8461538461538461 -> 0.8461538461538461\n", "0.3076923076923077 -> 0.3076923076923077\n", "0.5384615384615384 -> 0.5384615384615384\n", "0.6923076923076923 -> 0.6923076923076923\n", "0.9230769230769231 -> 0.9230769230769229\n", "0.7692307692307693 -> 0.7692307692307693\n", "1.0 -> 1.0\n", "1 -> 1.0\n", "1 -> 1.0\n" ] } ], "source": [ "c = mobius.set_function\n", "for k in capacity._values.keys():\n", " print(f\"{capacity(*k)} -> {c(*k)}\")" ] }, { "cell_type": "markdown", "id": "299db8e3", "metadata": {}, "source": [ "We can use this representation to compute the aggregation analysis metrics:" ] }, { "cell_type": "code", "execution_count": 36, "id": "f12a011e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 0.134615\n", "1 0.211538\n", "2 0.288462\n", "3 0.365385\n", "dtype: float64" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mobius.shapley" ] }, { "cell_type": "code", "execution_count": 37, "id": "c37f5c88", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123
0NaN-0.025641-0.025641-0.025641
1-0.025641NaN-0.064103-0.064103
2-0.025641-0.064103NaN-0.064103
3-0.025641-0.064103-0.064103NaN
\n", "
" ], "text/plain": [ " 0 1 2 3\n", "0 NaN -0.025641 -0.025641 -0.025641\n", "1 -0.025641 NaN -0.064103 -0.064103\n", "2 -0.025641 -0.064103 NaN -0.064103\n", "3 -0.025641 -0.064103 -0.064103 NaN" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mobius.interaction_index" ] }, { "cell_type": "markdown", "id": "ae45d9a3", "metadata": {}, "source": [ "This representation also has constraints that define the type of its underlying set function:" ] }, { "cell_type": "code", "execution_count": 38, "id": "0b7161f8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mobius.is_monotonous" ] }, { "cell_type": "code", "execution_count": 39, "id": "a31cfc4c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mobius.is_normal" ] }, { "cell_type": "code", "execution_count": 40, "id": "f8341c6c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mobius.is_k_additive(1)" ] }, { "cell_type": "code", "execution_count": 41, "id": "9ad6beb4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_capacity.mobius.is_k_additive(1) # equivalent to additivity" ] }, { "cell_type": "code", "execution_count": 42, "id": "13a15869", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_capacity.mobius.is_k_additive(2)" ] }, { "cell_type": "markdown", "id": "ca332407", "metadata": {}, "source": [ "## Reference\n", "\n", "The example used in this notebook corresponds to the R package kappalab example, taken from its [documentation](https://cran.r-project.org/web/packages/kappalab/kappalab.pdf) at page 15. Below the R code corresponding:\n", "\n", "```R\n", "# load library 'kappalab'\n", "library(\"kappalab\")\n", "# a normalized capacity\n", "mu <- capacity(c(0:13/13,1,1))\n", "# compute mobius transform of capacity\n", "m <- Mobius(mu)\n", "# The Shapley values\n", "Shapley.value(mu)\n", "# The interaction index matrix\n", "interaction.indices(mu)\n", "```" ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.10.9" } }, "nbformat": 4, "nbformat_minor": 5 }