{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# TauVector" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.741577Z", "start_time": "2021-02-15T09:50:56.083243Z" } }, "outputs": [], "source": [ "from fractions import Fraction\n", "import poisson_approval as pa" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A Tau-Vector and its Basic Properties" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The most usual way to define a tau-vector (ballot shares) is to deduce it from applying a given strategy in a given profile, like in the tutorial on *ProfileNoisyDiscrete*. That being said, a tau-vector can also be defined directly:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.752547Z", "start_time": "2021-02-15T09:51:01.745566Z" } }, "outputs": [], "source": [ "tau = pa.TauVector({'a': Fraction(1, 10), 'ab': Fraction(3, 5), 'c': Fraction(3, 10)})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Share of the ballot $ab$:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.788977Z", "start_time": "2021-02-15T09:51:01.758530Z" } }, "outputs": [ { "data": { "text/plain": [ "Fraction(3, 5)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.ab" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Share of single / double votes:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.810947Z", "start_time": "2021-02-15T09:51:01.791969Z" } }, "outputs": [ { "data": { "text/plain": [ "Fraction(2, 5)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.share_single_votes" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.828899Z", "start_time": "2021-02-15T09:51:01.812941Z" } }, "outputs": [ { "data": { "text/plain": [ "Fraction(3, 5)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.share_double_votes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Scores:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.851837Z", "start_time": "2021-02-15T09:51:01.830894Z" } }, "outputs": [ { "data": { "text/plain": [ "{a: 7/10, b: 3/5, c: 3/10}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.scores" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Winners:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.875773Z", "start_time": "2021-02-15T09:51:01.854842Z" } }, "outputs": [ { "data": { "text/plain": [ "{'a'}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.winners" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Events: Duos, Pivots and Trios" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An *Event* provides the asymptotic development of the probability when the expected number of voters $n$ tend to infinity, as well as the offsets for each type of ballot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Duo between $a$ and $b$:\n", "\n", "($a$ and $b$ have the same score, but not necessarily higher than $c$.)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.893725Z", "start_time": "2021-02-15T09:51:01.879764Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.duo_ab" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Access the asymptotic development and the offsets:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.913673Z", "start_time": "2021-02-15T09:51:01.896717Z" } }, "outputs": [ { "data": { "text/plain": [ "exp(- 0.1 n + o(1))" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.duo_ab.asymptotic" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.930626Z", "start_time": "2021-02-15T09:51:01.915666Z" } }, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.duo_ab.phi_a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pivots between $a$ and $b$:\n", "\n", "(For the definition of each variant, cf. the *Reference* section.)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.950575Z", "start_time": "2021-02-15T09:51:01.932621Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_weak_ab" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:01.987477Z", "start_time": "2021-02-15T09:51:01.953566Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_strict_ab" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.017402Z", "start_time": "2021-02-15T09:51:01.991464Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_tij_abc" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.048653Z", "start_time": "2021-02-15T09:51:02.021384Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.pivot_tjk_abc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Trios:\n", "\n", "(For the definition of each variant, cf. the *Reference* section.)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.083608Z", "start_time": "2021-02-15T09:51:02.051651Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.trio" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.115473Z", "start_time": "2021-02-15T09:51:02.087548Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.trio_1t_a" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.145657Z", "start_time": "2021-02-15T09:51:02.118465Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.trio_2t_ab" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print the order of the magnitudes of the pivots:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.187016Z", "start_time": "2021-02-15T09:51:02.149645Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mu_ac > mu_ab > mu_bc\n" ] } ], "source": [ "tau.print_magnitudes_order()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print all the weak pivots:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.218461Z", "start_time": "2021-02-15T09:51:02.189539Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pivot_weak_ab: \n", "pivot_weak_ac: \n", "pivot_weak_bc: \n", "trio: \n" ] } ], "source": [ "tau.print_weak_pivots()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Print all the pivots:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.264528Z", "start_time": "2021-02-15T09:51:02.222451Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pivot_weak_ab: \n", "pivot_weak_ac: \n", "pivot_weak_bc: \n", "pivot_strict_ab: \n", "pivot_strict_ac: \n", "pivot_strict_bc: \n", "pivot_tij_abc: \n", "pivot_tij_acb: \n", "pivot_tij_bac: \n", "pivot_tij_bca: \n", "pivot_tij_cab: \n", "pivot_tij_cba: \n", "pivot_tjk_abc: \n", "pivot_tjk_acb: \n", "pivot_tjk_bac: \n", "pivot_tjk_bca: \n", "pivot_tjk_cab: \n", "pivot_tjk_cba: \n", "trio: \n", "trio_1t_a: \n", "trio_1t_b: \n", "trio_1t_c: \n", "trio_2t_ab: \n", "trio_2t_ac: \n", "trio_2t_bc: \n", "duo_ab: \n", "duo_ac: \n", "duo_bc: \n" ] } ], "source": [ "tau.print_all_pivots()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Best Responses" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The *focus* of a tau-vector is defined as:\n", "\n", "* *Direct*: the three weak pivots have distinct magnitudes.\n", "* *Forward-Focused*: the two lowest magnitudes are equal, the highest one is different.\n", "* *Backward-Focused*: the two highest magnitudes are equal, the lowest one is different.\n", "* *Unfocused*: the three magnitudes are equal." ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.283478Z", "start_time": "2021-02-15T09:51:02.269515Z" } }, "outputs": [ { "data": { "text/plain": [ "Focus.DIRECT" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.focus" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Best response for each ranking:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.326446Z", "start_time": "2021-02-15T09:51:02.287529Z" } }, "outputs": [ { "data": { "text/plain": [ "{abc: , acb: , bac: , bca: , cab: , cba: }" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.d_ranking_best_response" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Characteristics of the best response for voters with ranking $abc$:" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.356286Z", "start_time": "2021-02-15T09:51:02.333344Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.d_ranking_best_response['abc']" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.388238Z", "start_time": "2021-02-15T09:51:02.361270Z" } }, "outputs": [ { "data": { "text/plain": [ "'a'" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.d_ranking_best_response['abc'].ballot" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.427625Z", "start_time": "2021-02-15T09:51:02.392186Z" } }, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.d_ranking_best_response['abc'].utility_threshold" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.466486Z", "start_time": "2021-02-15T09:51:02.431579Z" } }, "outputs": [ { "data": { "text/plain": [ "'Asymptotic method'" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.d_ranking_best_response['abc'].justification" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.510369Z", "start_time": "2021-02-15T09:51:02.470475Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tau.d_ranking_best_response['abc'].pivot_tij" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Strategy with Attached Profile and Implicit Tau" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As mentioned in the tutorial on *ProfileNoisyDiscrete*, you can define a strategy with an attached profile:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.550749Z", "start_time": "2021-02-15T09:51:02.514358Z" } }, "outputs": [], "source": [ "profile = pa.ProfileNoisyDiscrete({\n", " ('abc', 0.4, 0.01): Fraction(1, 10),\n", " ('bac', 0.2, 0.01): Fraction(6, 10),\n", " ('cab', 0.7, 0.01): Fraction(3, 10)\n", "})\n", "strategy = pa.StrategyOrdinal({'abc': 'a', 'bac': 'ab', 'cab': 'c'}, profile=profile)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This defines a tau vector:" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.568705Z", "start_time": "2021-02-15T09:51:02.554740Z" } }, "outputs": [ { "data": { "text/plain": [ " ==> a" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "strategy.tau" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In that case, the strategy has shortcuts for all the properties of the tau vector. Thus for example, instead of writing:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.579671Z", "start_time": "2021-02-15T09:51:02.571909Z" } }, "outputs": [ { "data": { "text/plain": [ "{a: 7/10, b: 3/5, c: 3/10}" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "strategy.tau.scores" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can simply write:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.590817Z", "start_time": "2021-02-15T09:51:02.581666Z" } }, "outputs": [ { "data": { "text/plain": [ "{a: 7/10, b: 3/5, c: 3/10}" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "strategy.scores" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similarly, instead of writing:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.605602Z", "start_time": "2021-02-15T09:51:02.593634Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pivot_weak_ab: \n", "pivot_weak_ac: \n", "pivot_weak_bc: \n", "trio: \n" ] } ], "source": [ "strategy.tau.print_weak_pivots()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can write:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.616573Z", "start_time": "2021-02-15T09:51:02.609592Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pivot_weak_ab: \n", "pivot_weak_ac: \n", "pivot_weak_bc: \n", "trio: \n" ] } ], "source": [ "strategy.print_weak_pivots()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Symbolic Computation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Up to now, all the computations we made were numeric. When defining a profile or a tau-vector, you can use the option ``symbolic=True``. In that case, all computations will be symbolic if possible. Note, however, that this option is much slower than numeric computation." ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:02.630207Z", "start_time": "2021-02-15T09:51:02.620211Z" } }, "outputs": [], "source": [ "profile = pa.ProfileNoisyDiscrete({\n", " ('abc', 0.4, 0.01): Fraction(1, 10),\n", " ('bac', 0.2, 0.01): Fraction(6, 10),\n", " ('cab', 0.7, 0.01): Fraction(3, 10)\n", "}, symbolic=True)\n", "strategy = pa.StrategyOrdinal({'abc': 'a', 'bac': 'ab', 'cab': 'c'}, profile=profile)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "ExecuteTime": { "end_time": "2021-02-15T09:51:04.500063Z", "start_time": "2021-02-15T09:51:02.633199Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "pivot_weak_ab: \n", "pivot_weak_ac: \n", "pivot_weak_bc: \n", "trio: \n" ] } ], "source": [ "strategy.print_weak_pivots()" ] } ], "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.7.3" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }