From b00de087f8e931d3aa6e109b9f14a65227f4b53a Mon Sep 17 00:00:00 2001 From: Maxime MORGE <maxime.morge@univ-lille.fr> Date: Wed, 26 Mar 2025 14:04:26 +0100 Subject: [PATCH] Investment game results --- README.md | 82 ++-- data/investment/investment.csv | 140 +++++- data/investment/investment.old.csv | 97 ----- figures/investment/investment.svg | 527 +++++++++++++++-------- src/investment/investment.py | 56 ++- src/investment/investment_draw.py | 2 +- src/investment/investment_experiments.py | 6 +- 7 files changed, 532 insertions(+), 378 deletions(-) delete mode 100644 data/investment/investment.old.csv diff --git a/README.md b/README.md index e6bb90c..6205016 100644 --- a/README.md +++ b/README.md @@ -15,47 +15,55 @@ directions to overcome the current limitations of LLMs. ## Consistency -To assess the decision-making consistency of various LLMs, we introduce an -investment game that allows us to observe whether LLMs follow stable -decision-making patterns or react erratically to variations in the game’s -parameters. - -An investor must allocate a basket (p_t^A, p_t^B) of 100 points between Asset A -and Asset B. The value of these points depends on two random parameters (a_t, -b_t), which determine how much money is received per allocated point. - -For example, if a = 0.8 and b = 0.5, this means that each point allocated to -Asset A is worth $0.8, while each point allocated to Asset B yields $0.5. The -game is played 25 times to analyze the consistency of the investor’s -decision-making. - -The investor’s decisions are then evaluated using an index called the Critical -Cost Efficiency Index (CCEI), which measures whether decisions adhere to a -certain level of economic rationality. This index is commonly used in -experimental economics and behavioral sciences to determine whether an -individual’s choices comply with the Generalized Axiom of Revealed Preference -(GARP). If an individual violates rational choice consistency, it is possible to -make a minimal budget adjustment (reducing resources) to align their decisions -with rationality. The CCEI quantifies the smallest budget reduction necessary to -make the choices consistent with rational principles. - -Each basket’s budget is calculated as follows: +To evaluate the decision-making consistency of various LLMs, we introduce an investment +game designed to test whether these models follow stable decision-making patterns or +react erratically to changes in the game’s parameters. + +In the game, an investor allocates a basket \((p_t^A, p_t^B)\) of 100 points between two assets: +Asset A and Asset B. The value of these points depends on two random parameters \((a_t, b_t)\), +which determine the monetary return per allocated point. + +For example, if \(a_t = 0.8\) and \(b_t = 0.5\), each point assigned to Asset A is worth $0.8, +while each point allocated to Asset B yields $0.5. The game is played 25 times to assess +the consistency of the investor’s decisions. + +To evaluate the rationality of the decisions, we use the **Critical Cost Efficiency Index (CCEI)**, +a widely used measure in experimental economics and behavioral sciences. The CCEI assesses +whether choices adhere to the **Generalized Axiom of Revealed Preference (GARP)**, +a fundamental principle of rational decision-making. + +If an individual violates rational choice consistency, +the CCEI determines the minimal budget adjustment required to make their +decisions align with rationality. Mathematically, the budget for each basket is calculated as: + +\[ I_t = p_t^A \times a_t + p_t^B \times b_t +\] -The CCEI index is derived from observed decisions. It is based on a linear -optimization problem that seeks the smallest necessary adjustment to budget -constraints to make the decisions conform to a rational model. +The CCEI is derived from observed decisions by solving a linear optimization +problem that finds the largest \(\lambda\) (where \(0 \leq \lambda \leq 1\)) +such that for every observation, the adjusted decisions satisfy the rationality constraint: + +\[ +p^_t \cdot x_s \leq \lambda I_t +\] + +This means that if we slightly reduce the budget (multiplying it by \(\lambda\)), +the choices will become consistent with rational decision-making. +A CCEI close to 1 indicates high rationality and consistency with economic theory. +A low CCEEI** suggests irrational or inconsistent decision-making. + +To ensure response consistency, each model undergoes 30 iterations of the game +with a fixed temperature of 0.0. + +The results indicate significant differences in decision-making consistency among the evaluated models. +Mistral-Small demonstrates the highest level of rationality, with CCEI values consistently above 0.75. +Llama 3 performs moderately well, with CCEI values ranging between 0.2 and 0.74. +DeepSeek R1 exhibits inconsistent behavior, with CCEI scores varying widely between 0.15 and 0.83 + + -We aim to find the largest \lambda (0 ≤ λ ≤ 1) such that, for every observation, -the adjusted decisions satisfy the rationality constraint: p^_t \cdot x_s \leq -\lambda I_t This means that if we slightly reduce the individual’s budget (by -multiplying it by \lambda), their choices will become consistent with -rationality. -A CCEI close to 1 indicates that the choices are rational and consistent with -rational choice theory, whereas a low CCEI suggests irrational behavior. For -each model, 30 iterations of the game are conducted with a fixed temperature of -0.0 to maximize response consistency. ## Preferences diff --git a/data/investment/investment.csv b/data/investment/investment.csv index 43aa27b..c7d1789 100644 --- a/data/investment/investment.csv +++ b/data/investment/investment.csv @@ -1,21 +1,121 @@ iteration,model,temperature,ccei -1,optimal,0.0,1.0 -2,optimal,0.0,1.0 -3,optimal,0.0,1.0 -4,optimal,0.0,1.0 -5,optimal,0.0,1.0 -6,optimal,0.0,1.0 -7,optimal,0.0,1.0 -8,optimal,0.0,1.0 -9,optimal,0.0,1.0 -10,optimal,0.0,1.0 -1,random,0.0,1.0 -2,random,0.0,1.0 -3,random,0.0,1.0 -4,random,0.0,1.0 -5,random,0.0,1.0 -6,random,0.0,1.0 -7,random,0.0,1.0 -8,random,0.0,1.0 -9,random,0.0,1.0 -10,random,0.0,1.0 +1,random,0.0,0.30081300813008127 +2,random,0.0,0.29500000000000004 +3,random,0.0,0.24739884393063583 +4,random,0.0,0.2987012987012987 +5,random,0.0,0.3548387096774194 +6,random,0.0,0.3986486486486487 +7,random,0.0,0.2810650887573965 +8,random,0.0,0.35494880546075086 +9,random,0.0,0.272 +10,random,0.0,0.22171945701357465 +11,random,0.0,0.3150105708245243 +12,random,0.0,0.25641025641025644 +13,random,0.0,0.1569506726457399 +14,random,0.0,0.247787610619469 +15,random,0.0,0.5156950672645739 +16,random,0.0,0.2645739910313901 +17,random,0.0,0.40444444444444444 +18,random,0.0,0.27455919395465994 +19,random,0.0,0.20800000000000002 +20,random,0.0,0.20930232558139536 +21,random,0.0,0.3823529411764706 +22,random,0.0,0.49244712990936557 +23,random,0.0,0.2 +24,random,0.0,0.46881287726358145 +25,random,0.0,0.30916414904330314 +26,random,0.0,0.21908602150537634 +27,random,0.0,0.21929824561403508 +28,random,0.0,0.23555555555555555 +29,random,0.0,0.4501510574018127 +30,random,0.0,0.2896174863387978 +1,llama3,0.0,0.5533333333333333 +2,llama3,0.0,0.23636363636363636 +3,llama3,0.0,0.38461538461538464 +4,llama3,0.0,0.391304347826087 +5,llama3,0.0,0.379746835443038 +6,llama3,0.0,0.4473684210526316 +7,llama3,0.0,0.2 +8,llama3,0.0,0.45454545454545453 +9,llama3,0.0,0.6133333333333333 +10,llama3,0.0,0.4314720812182741 +11,llama3,0.0,0.665 +12,llama3,0.0,0.43533930857874514 +13,llama3,0.0,0.5 +14,llama3,0.0,0.519277108433735 +15,llama3,0.0,0.27586206896551724 +16,llama3,0.0,0.5555555555555556 +17,llama3,0.0,0.5 +18,llama3,0.0,0.35714285714285715 +19,llama3,0.0,0.4246575342465753 +20,llama3,0.0,0.25 +21,llama3,0.0,0.23809523809523808 +22,llama3,0.0,0.3333333333333333 +23,llama3,0.0,0.475 +24,llama3,0.0,0.6666666666666666 +25,llama3,0.0,0.3151079136690647 +26,llama3,0.0,0.3368421052631579 +27,llama3,0.0,0.742 +28,llama3,0.0,0.5333333333333333 +29,llama3,0.0,0.5172413793103449 +30,llama3,0.0,0.5 +1,mistral-small,0.0,1.0 +2,mistral-small,0.0,0.6222222222222222 +3,mistral-small,0.0,0.8866666666666667 +4,mistral-small,0.0,0.90625 +5,mistral-small,0.0,0.6785714285714286 +6,mistral-small,0.0,0.90625 +7,mistral-small,0.0,0.5555555555555556 +8,mistral-small,0.0,0.8844444444444444 +9,mistral-small,0.0,0.8266666666666667 +10,mistral-small,0.0,0.3333333333333333 +11,mistral-small,0.0,0.8333333333333334 +12,mistral-small,0.0,0.8888888888888888 +13,mistral-small,0.0,0.925 +14,mistral-small,0.0,0.78 +15,mistral-small,0.0,0.804 +16,mistral-small,0.0,0.75 +17,mistral-small,0.0,0.84 +18,mistral-small,0.0,0.625 +19,mistral-small,0.0,0.90625 +20,mistral-small,0.0,0.8166666666666667 +21,mistral-small,0.0,0.875 +22,mistral-small,0.0,0.9866666666666667 +23,mistral-small,0.0,0.7733333333333333 +24,mistral-small,0.0,0.92 +25,mistral-small,0.0,0.8571428571428571 +26,mistral-small,0.0,0.9375 +27,mistral-small,0.0,0.7150000000000001 +28,mistral-small,0.0,0.9625 +29,mistral-small,0.0,0.8928571428571429 +30,mistral-small,0.0,0.802 +1,deepseek-r1,0.0,0.25 +2,deepseek-r1,0.0,0.5882352941176471 +3,deepseek-r1,0.0,0.42207792207792205 +4,deepseek-r1,0.0,0.335 +5,deepseek-r1,0.0,0.22105263157894736 +6,deepseek-r1,0.0,0.22999999999999998 +7,deepseek-r1,0.0,0.3058510638297872 +8,deepseek-r1,0.0,0.32142857142857145 +9,deepseek-r1,0.0,0.6711409395973154 +10,deepseek-r1,0.0,0.25 +11,deepseek-r1,0.0,0.75 +12,deepseek-r1,0.0,0.8315217391304347 +13,deepseek-r1,0.0,0.4597701149425288 +14,deepseek-r1,0.0,0.32142857142857145 +15,deepseek-r1,0.0,0.16875 +16,deepseek-r1,0.0,0.25157232704402516 +17,deepseek-r1,0.0,0.574712643678161 +18,deepseek-r1,0.0,0.28776978417266186 +19,deepseek-r1,0.0,0.32142857142857145 +20,deepseek-r1,0.0,0.7304347826086957 +21,deepseek-r1,0.0,0.17329910141206675 +22,deepseek-r1,0.0,0.175 +23,deepseek-r1,0.0,0.45454545454545453 +24,deepseek-r1,0.0,0.2992700729927008 +25,deepseek-r1,0.0,0.34 +26,deepseek-r1,0.0,0.2 +27,deepseek-r1,0.0,0.3333333333333333 +28,deepseek-r1,0.0,0.1870967741935484 +29,deepseek-r1,0.0,0.2575 +30,deepseek-r1,0.0,0.1514285714285714 diff --git a/data/investment/investment.old.csv b/data/investment/investment.old.csv deleted file mode 100644 index d6fb25e..0000000 --- a/data/investment/investment.old.csv +++ /dev/null @@ -1,97 +0,0 @@ -iteration,model,temperature,ccei -1,random,0.0,0.1993 -2,random,0.0,0.2841 -3,random,0.0,0.2584 -4,random,0.0,0.3276 -5,random,0.0,0.3676 -6,random,0.0,0.1505 -7,random,0.0,0.1047 -8,random,0.0,0.1385 -9,random,0.0,0.1866 -10,random,0.0,0.3135 -11,random,0.0,0.1835 -12,random,0.0,0.29 -13,random,0.0,0.2523 -14,random,0.0,0.2014 -15,random,0.0,0.1676 -16,random,0.0,0.2469 -17,random,0.0,0.2429 -18,random,0.0,0.1676 -19,random,0.0,0.1818 -20,random,0.0,0.3804 -21,random,0.0,0.2718 -22,random,0.0,0.336 -23,random,0.0,0.2473 -24,random,0.0,0.1942 -25,random,0.0,0.2857 -26,random,0.0,0.2163 -27,random,0.0,0.4202 -28,random,0.0,0.1175 -29,random,0.0,0.2494 -30,random,0.0,0.2693 -1,llama3,0.0,0.3636 -2,llama3,0.0,0.1515 -3,llama3,0.0,0.4684 -4,llama3,0.0,0.1515 -5,llama3,0.0,0.3636 -6,llama3,0.0,0.2222 -7,llama3,0.0,0.2222 -8,llama3,0.0,0.5242 -9,llama3,0.0,0.2632 -10,llama3,0.0,0.3 -11,llama3,0.0,0.1429 -12,llama3,0.0,0.1466 -13,llama3,0.0,0.3226 -14,llama3,0.0,0.1695 -15,llama3,0.0,0.25 -16,llama3,0.0,0.2381 -17,llama3,0.0,0.3391 -18,llama3,0.0,0.4386 -19,llama3,0.0,0.1639 -20,llama3,0.0,0.2909 -21,llama3,0.0,0.3077 -22,llama3,0.0,0.3906 -23,llama3,0.0,0.4 -24,llama3,0.0,0.1563 -25,llama3,0.0,0.2727 -26,llama3,0.0,0.2381 -27,llama3,0.0,0.2759 -28,llama3,0.0,0.1818 -29,llama3,0.0,0.2899 -30,llama3,0.0,0.2857 -1,mistral-small,0.0,0.1429 -2,mistral-small,0.0,0.1111 -3,mistral-small,0.0,0.1 -4,mistral-small,0.0,0.1111 -5,mistral-small,0.0,0.1111 -6,mistral-small,0.0,0.1 -7,mistral-small,0.0,0.1667 -8,mistral-small,0.0,0.1429 -9,mistral-small,0.0,0.1309 -10,mistral-small,0.0,0.2222 -11,mistral-small,0.0,0.1667 -12,mistral-small,0.0,0.125 -13,mistral-small,0.0,0.1 -14,mistral-small,0.0,0.1111 -15,mistral-small,0.0,0.2 -16,mistral-small,0.0,0.1111 -17,mistral-small,0.0,0.1111 -18,mistral-small,0.0,0.1111 -19,mistral-small,0.0,0.1493 -20,mistral-small,0.0,0.1429 -21,mistral-small,0.0,0.125 -22,mistral-small,0.0,0.1111 -23,mistral-small,0.0,0.125 -24,mistral-small,0.0,0.2 -25,mistral-small,0.0,0.1429 -26,mistral-small,0.0,0.1 -27,mistral-small,0.0,0.1111 -28,mistral-small,0.0,0.1111 -29,mistral-small,0.0,0.1111 -30,mistral-small,0.0,0.1111 -1,deepseek-r1, 0.0,0.1667 -2,deepseek-r1,0.0,0.2097 -3,deepseek-r1,0.0,0.3333 -4,deepseek-r1,0.0,0.1905 -5,deepseek-r1,0.0,0.2754 -6,deepseek-r1,0.0,0.1111 \ No newline at end of file diff --git a/figures/investment/investment.svg b/figures/investment/investment.svg index 7c81295..1edd557 100644 --- a/figures/investment/investment.svg +++ b/figures/investment/investment.svg @@ -6,7 +6,7 @@ <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <cc:Work> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> - <dc:date>2025-03-24T14:46:52.844601</dc:date> + <dc:date>2025-03-26T13:51:51.025345</dc:date> <dc:format>image/svg+xml</dc:format> <dc:creator> <cc:Agent> @@ -41,7 +41,7 @@ z <g id="xtick_1"> <g id="text_1"> <!-- random --> - <g style="fill: #262626" transform="translate(166.450409 414.133865) rotate(-20) scale(0.11 -0.11)"> + <g style="fill: #262626" transform="translate(143.200409 414.133865) rotate(-20) scale(0.11 -0.11)"> <defs> <path id="ArialMT-72" d="M 416 0 L 416 3319 @@ -215,7 +215,7 @@ z <g id="xtick_2"> <g id="text_2"> <!-- llama3 --> - <g style="fill: #262626" transform="translate(354.748692 412.460852) rotate(-20) scale(0.11 -0.11)"> + <g style="fill: #262626" transform="translate(284.998692 412.460852) rotate(-20) scale(0.11 -0.11)"> <defs> <path id="ArialMT-6c" d="M 409 0 L 409 4581 @@ -270,7 +270,7 @@ z <g id="xtick_3"> <g id="text_3"> <!-- mistral-small --> - <g style="fill: #262626" transform="translate(526.975147 422.487172) rotate(-20) scale(0.11 -0.11)"> + <g style="fill: #262626" transform="translate(410.725147 422.487172) rotate(-20) scale(0.11 -0.11)"> <defs> <path id="ArialMT-69" d="M 425 3934 L 425 4581 @@ -368,29 +368,12 @@ z </g> </g> </g> - <g id="text_4"> - <!-- Model --> - <g style="fill: #262626" transform="translate(352.659375 437.13095) scale(0.12 -0.12)"> - <defs> - <path id="ArialMT-4d" d="M 475 0 -L 475 4581 -L 1388 4581 -L 2472 1338 -Q 2622 884 2691 659 -Q 2769 909 2934 1394 -L 4031 4581 -L 4847 4581 -L 4847 0 -L 4263 0 -L 4263 3834 -L 2931 0 -L 2384 0 -L 1059 3900 -L 1059 0 -L 475 0 -z -" transform="scale(0.015625)"/> - <path id="ArialMT-65" d="M 2694 1069 + <g id="xtick_4"> + <g id="text_4"> + <!-- deepseek-r1 --> + <g style="fill: #262626" transform="translate(550.499645 422.322106) rotate(-20) scale(0.11 -0.11)"> + <defs> + <path id="ArialMT-65" d="M 2694 1069 L 3275 997 Q 3138 488 2766 206 Q 2394 -75 1816 -75 @@ -414,6 +397,98 @@ Q 2219 2931 1791 2931 Q 1403 2931 1139 2672 Q 875 2413 847 1978 z +" transform="scale(0.015625)"/> + <path id="ArialMT-70" d="M 422 -1272 +L 422 3319 +L 934 3319 +L 934 2888 +Q 1116 3141 1344 3267 +Q 1572 3394 1897 3394 +Q 2322 3394 2647 3175 +Q 2972 2956 3137 2557 +Q 3303 2159 3303 1684 +Q 3303 1175 3120 767 +Q 2938 359 2589 142 +Q 2241 -75 1856 -75 +Q 1575 -75 1351 44 +Q 1128 163 984 344 +L 984 -1272 +L 422 -1272 +z +M 931 1641 +Q 931 1000 1190 694 +Q 1450 388 1819 388 +Q 2194 388 2461 705 +Q 2728 1022 2728 1688 +Q 2728 2322 2467 2637 +Q 2206 2953 1844 2953 +Q 1484 2953 1207 2617 +Q 931 2281 931 1641 +z +" transform="scale(0.015625)"/> + <path id="ArialMT-6b" d="M 425 0 +L 425 4581 +L 988 4581 +L 988 1969 +L 2319 3319 +L 3047 3319 +L 1778 2088 +L 3175 0 +L 2481 0 +L 1384 1697 +L 988 1316 +L 988 0 +L 425 0 +z +" transform="scale(0.015625)"/> + <path id="ArialMT-31" d="M 2384 0 +L 1822 0 +L 1822 3584 +Q 1619 3391 1289 3197 +Q 959 3003 697 2906 +L 697 3450 +Q 1169 3672 1522 3987 +Q 1875 4303 2022 4600 +L 2384 4600 +L 2384 0 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#ArialMT-64"/> + <use xlink:href="#ArialMT-65" transform="translate(55.615234 0)"/> + <use xlink:href="#ArialMT-65" transform="translate(111.230469 0)"/> + <use xlink:href="#ArialMT-70" transform="translate(166.845703 0)"/> + <use xlink:href="#ArialMT-73" transform="translate(222.460938 0)"/> + <use xlink:href="#ArialMT-65" transform="translate(272.460938 0)"/> + <use xlink:href="#ArialMT-65" transform="translate(328.076172 0)"/> + <use xlink:href="#ArialMT-6b" transform="translate(383.691406 0)"/> + <use xlink:href="#ArialMT-2d" transform="translate(433.691406 0)"/> + <use xlink:href="#ArialMT-72" transform="translate(466.992188 0)"/> + <use xlink:href="#ArialMT-31" transform="translate(500.292969 0)"/> + </g> + </g> + </g> + <g id="text_5"> + <!-- Model --> + <g style="fill: #262626" transform="translate(352.659375 437.13095) scale(0.12 -0.12)"> + <defs> + <path id="ArialMT-4d" d="M 475 0 +L 475 4581 +L 1388 4581 +L 2472 1338 +Q 2622 884 2691 659 +Q 2769 909 2934 1394 +L 4031 4581 +L 4847 4581 +L 4847 0 +L 4263 0 +L 4263 3834 +L 2931 0 +L 2384 0 +L 1059 3900 +L 1059 0 +L 475 0 +z " transform="scale(0.015625)"/> </defs> <use xlink:href="#ArialMT-4d"/> @@ -427,13 +502,13 @@ z <g id="matplotlib.axis_2"> <g id="ytick_1"> <g id="line2d_1"> - <path d="M 90 369.36 -L 648 369.36 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> + <path d="M 90 352.050909 +L 648 352.050909 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> </g> - <g id="text_5"> - <!-- 0.1 --> - <g style="fill: #262626" transform="translate(65.21 373.296797) scale(0.11 -0.11)"> + <g id="text_6"> + <!-- 0.2 --> + <g style="fill: #262626" transform="translate(65.21 355.987706) scale(0.11 -0.11)"> <defs> <path id="ArialMT-30" d="M 266 2259 Q 266 3072 433 3567 @@ -467,35 +542,6 @@ L 1222 0 L 581 0 z " transform="scale(0.015625)"/> - <path id="ArialMT-31" d="M 2384 0 -L 1822 0 -L 1822 3584 -Q 1619 3391 1289 3197 -Q 959 3003 697 2906 -L 697 3450 -Q 1169 3672 1522 3987 -Q 1875 4303 2022 4600 -L 2384 4600 -L 2384 0 -z -" transform="scale(0.015625)"/> - </defs> - <use xlink:href="#ArialMT-30"/> - <use xlink:href="#ArialMT-2e" transform="translate(55.615234 0)"/> - <use xlink:href="#ArialMT-31" transform="translate(83.398438 0)"/> - </g> - </g> - </g> - <g id="ytick_2"> - <g id="line2d_2"> - <path d="M 90 298.072871 -L 648 298.072871 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> - </g> - <g id="text_6"> - <!-- 0.2 --> - <g style="fill: #262626" transform="translate(65.21 302.009668) scale(0.11 -0.11)"> - <defs> <path id="ArialMT-32" d="M 3222 541 L 3222 0 L 194 0 @@ -528,30 +574,15 @@ z </g> </g> </g> - <g id="ytick_3"> - <g id="line2d_3"> - <path d="M 90 226.785743 -L 648 226.785743 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> + <g id="ytick_2"> + <g id="line2d_2"> + <path d="M 90 280.778182 +L 648 280.778182 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> </g> <g id="text_7"> - <!-- 0.3 --> - <g style="fill: #262626" transform="translate(65.21 230.722539) scale(0.11 -0.11)"> - <use xlink:href="#ArialMT-30"/> - <use xlink:href="#ArialMT-2e" transform="translate(55.615234 0)"/> - <use xlink:href="#ArialMT-33" transform="translate(83.398438 0)"/> - </g> - </g> - </g> - <g id="ytick_4"> - <g id="line2d_4"> - <path d="M 90 155.498614 -L 648 155.498614 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> - </g> - <g id="text_8"> <!-- 0.4 --> - <g style="fill: #262626" transform="translate(65.21 159.435411) scale(0.11 -0.11)"> + <g style="fill: #262626" transform="translate(65.21 284.714979) scale(0.11 -0.11)"> <defs> <path id="ArialMT-34" d="M 2069 0 L 2069 1097 @@ -579,49 +610,129 @@ z </g> </g> </g> - <g id="ytick_5"> - <g id="line2d_5"> - <path d="M 90 84.211485 -L 648 84.211485 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> + <g id="ytick_3"> + <g id="line2d_3"> + <path d="M 90 209.505455 +L 648 209.505455 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> + </g> + <g id="text_8"> + <!-- 0.6 --> + <g style="fill: #262626" transform="translate(65.21 213.442251) scale(0.11 -0.11)"> + <defs> + <path id="ArialMT-36" d="M 3184 3459 +L 2625 3416 +Q 2550 3747 2413 3897 +Q 2184 4138 1850 4138 +Q 1581 4138 1378 3988 +Q 1113 3794 959 3422 +Q 806 3050 800 2363 +Q 1003 2672 1297 2822 +Q 1591 2972 1913 2972 +Q 2475 2972 2870 2558 +Q 3266 2144 3266 1488 +Q 3266 1056 3080 686 +Q 2894 316 2569 119 +Q 2244 -78 1831 -78 +Q 1128 -78 684 439 +Q 241 956 241 2144 +Q 241 3472 731 4075 +Q 1159 4600 1884 4600 +Q 2425 4600 2770 4297 +Q 3116 3994 3184 3459 +z +M 888 1484 +Q 888 1194 1011 928 +Q 1134 663 1356 523 +Q 1578 384 1822 384 +Q 2178 384 2434 671 +Q 2691 959 2691 1453 +Q 2691 1928 2437 2201 +Q 2184 2475 1800 2475 +Q 1419 2475 1153 2201 +Q 888 1928 888 1484 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#ArialMT-30"/> + <use xlink:href="#ArialMT-2e" transform="translate(55.615234 0)"/> + <use xlink:href="#ArialMT-36" transform="translate(83.398438 0)"/> + </g> + </g> + </g> + <g id="ytick_4"> + <g id="line2d_4"> + <path d="M 90 138.232727 +L 648 138.232727 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> </g> <g id="text_9"> - <!-- 0.5 --> - <g style="fill: #262626" transform="translate(65.21 88.148282) scale(0.11 -0.11)"> + <!-- 0.8 --> + <g style="fill: #262626" transform="translate(65.21 142.169524) scale(0.11 -0.11)"> <defs> - <path id="ArialMT-35" d="M 266 1200 -L 856 1250 -Q 922 819 1161 601 -Q 1400 384 1738 384 -Q 2144 384 2425 690 -Q 2706 997 2706 1503 -Q 2706 1984 2436 2262 -Q 2166 2541 1728 2541 -Q 1456 2541 1237 2417 -Q 1019 2294 894 2097 -L 366 2166 -L 809 4519 -L 3088 4519 -L 3088 3981 -L 1259 3981 -L 1013 2750 -Q 1425 3038 1878 3038 -Q 2478 3038 2890 2622 -Q 3303 2206 3303 1553 -Q 3303 931 2941 478 -Q 2500 -78 1738 -78 -Q 1113 -78 717 272 -Q 322 622 266 1200 + <path id="ArialMT-38" d="M 1131 2484 +Q 781 2613 612 2850 +Q 444 3088 444 3419 +Q 444 3919 803 4259 +Q 1163 4600 1759 4600 +Q 2359 4600 2725 4251 +Q 3091 3903 3091 3403 +Q 3091 3084 2923 2848 +Q 2756 2613 2416 2484 +Q 2838 2347 3058 2040 +Q 3278 1734 3278 1309 +Q 3278 722 2862 322 +Q 2447 -78 1769 -78 +Q 1091 -78 675 323 +Q 259 725 259 1325 +Q 259 1772 486 2073 +Q 713 2375 1131 2484 +z +M 1019 3438 +Q 1019 3113 1228 2906 +Q 1438 2700 1772 2700 +Q 2097 2700 2305 2904 +Q 2513 3109 2513 3406 +Q 2513 3716 2298 3927 +Q 2084 4138 1766 4138 +Q 1444 4138 1231 3931 +Q 1019 3725 1019 3438 +z +M 838 1322 +Q 838 1081 952 856 +Q 1066 631 1291 507 +Q 1516 384 1775 384 +Q 2178 384 2440 643 +Q 2703 903 2703 1303 +Q 2703 1709 2433 1975 +Q 2163 2241 1756 2241 +Q 1359 2241 1098 1978 +Q 838 1716 838 1322 z " transform="scale(0.015625)"/> </defs> <use xlink:href="#ArialMT-30"/> <use xlink:href="#ArialMT-2e" transform="translate(55.615234 0)"/> - <use xlink:href="#ArialMT-35" transform="translate(83.398438 0)"/> + <use xlink:href="#ArialMT-38" transform="translate(83.398438 0)"/> + </g> + </g> + </g> + <g id="ytick_5"> + <g id="line2d_5"> + <path d="M 90 66.96 +L 648 66.96 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #cccccc; stroke-linecap: round"/> + </g> + <g id="text_10"> + <!-- 1.0 --> + <g style="fill: #262626" transform="translate(65.21 70.896797) scale(0.11 -0.11)"> + <use xlink:href="#ArialMT-31"/> + <use xlink:href="#ArialMT-2e" transform="translate(55.615234 0)"/> + <use xlink:href="#ArialMT-30" transform="translate(83.398438 0)"/> </g> </g> </g> - <g id="text_10"> + <g id="text_11"> <!-- CCEI Value --> <g style="fill: #262626" transform="translate(58.825 249.064687) rotate(-90) scale(0.12 -0.12)"> <defs> @@ -722,97 +833,97 @@ z </g> </g> <g id="patch_3"> - <path d="M 127.2 309.282772 -L 238.8 309.282772 -L 238.8 237.26495 -L 127.2 237.26495 -L 127.2 309.282772 + <path d="M 117.9 338.325073 +L 201.6 338.325073 +L 201.6 296.842598 +L 117.9 296.842598 +L 117.9 338.325073 z -" clip-path="url(#pd32a051487)" style="fill: #333333; stroke: #1f1f1f; stroke-linejoin: miter"/> +" clip-path="url(#peb2dec3e2c)" style="fill: #333333; stroke: #1f1f1f; stroke-linejoin: miter"/> </g> <g id="line2d_6"> - <path d="M 183 309.282772 -L 183 366.009505 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 159.75 338.325073 +L 159.75 367.392124 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_7"> - <path d="M 183 237.26495 -L 183 141.098614 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 159.75 296.842598 +L 159.75 239.548667 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_8"> - <path d="M 155.1 366.009505 -L 210.9 366.009505 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> + <path d="M 138.825 367.392124 +L 180.675 367.392124 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> </g> <g id="line2d_9"> - <path d="M 155.1 141.098614 -L 210.9 141.098614 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> + <path d="M 138.825 239.548667 +L 180.675 239.548667 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> </g> <g id="line2d_10"/> <g id="patch_4"> - <path d="M 313.2 303.847129 -L 424.8 303.847129 -L 424.8 201.853069 -L 313.2 201.853069 -L 313.2 303.847129 + <path d="M 257.4 301.476746 +L 341.1 301.476746 +L 341.1 238.453523 +L 257.4 238.453523 +L 257.4 301.476746 z -" clip-path="url(#pd32a051487)" style="fill: #409884; stroke: #1f1f1f; stroke-linejoin: miter"/> +" clip-path="url(#peb2dec3e2c)" style="fill: #409884; stroke: #1f1f1f; stroke-linejoin: miter"/> </g> <g id="line2d_11"> - <path d="M 369 303.847129 -L 369 338.777822 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 299.25 301.476746 +L 299.25 352.050909 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_12"> - <path d="M 369 201.853069 -L 369 66.96 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 299.25 238.453523 +L 299.25 158.901818 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_13"> - <path d="M 341.1 338.777822 -L 396.9 338.777822 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> + <path d="M 278.325 352.050909 +L 320.175 352.050909 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> </g> <g id="line2d_14"> - <path d="M 341.1 66.96 -L 396.9 66.96 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> + <path d="M 278.325 158.901818 +L 320.175 158.901818 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> </g> <g id="line2d_15"/> <g id="patch_5"> - <path d="M 499.2 361.447129 -L 610.8 361.447129 -L 610.8 338.777822 -L 499.2 338.777822 -L 499.2 361.447129 + <path d="M 396.9 147.141818 +L 480.6 147.141818 +L 480.6 100.369091 +L 396.9 100.369091 +L 396.9 147.141818 z -" clip-path="url(#pd32a051487)" style="fill: #e77759; stroke: #1f1f1f; stroke-linejoin: miter"/> +" clip-path="url(#peb2dec3e2c)" style="fill: #e77759; stroke: #1f1f1f; stroke-linejoin: miter"/> </g> <g id="line2d_16"> - <path d="M 555 361.447129 -L 555 369.36 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 438.75 147.141818 +L 438.75 201.586263 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_17"> - <path d="M 555 338.777822 -L 555 321.811485 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 438.75 100.369091 +L 438.75 66.96 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_18"> - <path d="M 527.1 369.36 -L 582.9 369.36 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> + <path d="M 417.825 201.586263 +L 459.675 201.586263 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> </g> <g id="line2d_19"> - <path d="M 527.1 321.811485 -L 582.9 321.811485 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> + <path d="M 417.825 66.96 +L 459.675 66.96 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> </g> <g id="line2d_20"> <defs> - <path id="mba13d3f3f8" d="M 0 3 + <path id="m157d9f288c" d="M 0 3 C 0.795609 3 1.55874 2.683901 2.12132 2.12132 C 2.683901 1.55874 3 0.795609 3 0 C 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 @@ -824,48 +935,86 @@ C -1.55874 2.683901 -0.795609 3 0 3 z " style="stroke: #1f1f1f"/> </defs> - <g clip-path="url(#pd32a051487)"> - <use xlink:href="#mba13d3f3f8" x="555" y="282.247129" style="fill-opacity: 0; stroke: #1f1f1f"/> - <use xlink:href="#mba13d3f3f8" x="555" y="298.072871" style="fill-opacity: 0; stroke: #1f1f1f"/> - <use xlink:href="#mba13d3f3f8" x="555" y="298.072871" style="fill-opacity: 0; stroke: #1f1f1f"/> + <g clip-path="url(#peb2dec3e2c)"> + <use xlink:href="#m157d9f288c" x="438.75" y="225.343838" style="fill-opacity: 0; stroke: #1f1f1f"/> + <use xlink:href="#m157d9f288c" x="438.75" y="304.535758" style="fill-opacity: 0; stroke: #1f1f1f"/> </g> </g> + <g id="patch_6"> + <path d="M 536.4 339.578182 +L 620.1 339.578182 +L 620.1 264.232727 +L 536.4 264.232727 +L 536.4 339.578182 +z +" clip-path="url(#peb2dec3e2c)" style="fill: #6b72da; stroke: #1f1f1f; stroke-linejoin: miter"/> + </g> <g id="line2d_21"> - <path d="M 127.2 264.496634 -L 238.8 264.496634 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 578.25 339.578182 +L 578.25 369.36 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_22"> - <path d="M 313.2 245.106535 -L 424.8 245.106535 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 578.25 264.232727 +L 578.25 156.050909 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> </g> <g id="line2d_23"> - <path d="M 499.2 361.447129 -L 610.8 361.447129 -" clip-path="url(#pd32a051487)" style="fill: none; stroke: #1f1f1f"/> + <path d="M 557.325 369.36 +L 599.175 369.36 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> </g> - <g id="patch_6"> + <g id="line2d_24"> + <path d="M 557.325 156.050909 +L 599.175 156.050909 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f; stroke-linecap: round"/> + </g> + <g id="line2d_25"> + <g clip-path="url(#peb2dec3e2c)"> + <use xlink:href="#m157d9f288c" x="578.25" y="126.999526" style="fill-opacity: 0; stroke: #1f1f1f"/> + </g> + </g> + <g id="line2d_26"> + <path d="M 117.9 321.638378 +L 201.6 321.638378 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> + </g> + <g id="line2d_27"> + <path d="M 257.4 266.041168 +L 341.1 266.041168 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> + </g> + <g id="line2d_28"> + <path d="M 396.9 120.923636 +L 480.6 120.923636 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> + </g> + <g id="line2d_29"> + <path d="M 536.4 311.55381 +L 620.1 311.55381 +" clip-path="url(#peb2dec3e2c)" style="fill: none; stroke: #1f1f1f"/> + </g> + <g id="patch_7"> <path d="M 90 384.48 L 90 51.84 " style="fill: none; stroke: #cccccc; stroke-width: 1.25; stroke-linejoin: miter; stroke-linecap: square"/> </g> - <g id="patch_7"> + <g id="patch_8"> <path d="M 648 384.48 L 648 51.84 " style="fill: none; stroke: #cccccc; stroke-width: 1.25; stroke-linejoin: miter; stroke-linecap: square"/> </g> - <g id="patch_8"> + <g id="patch_9"> <path d="M 90 384.48 L 648 384.48 " style="fill: none; stroke: #cccccc; stroke-width: 1.25; stroke-linejoin: miter; stroke-linecap: square"/> </g> - <g id="patch_9"> + <g id="patch_10"> <path d="M 90 51.84 L 648 51.84 " style="fill: none; stroke: #cccccc; stroke-width: 1.25; stroke-linejoin: miter; stroke-linecap: square"/> </g> - <g id="text_11"> + <g id="text_12"> <!-- CCEI Distribution by Model --> <g style="fill: #262626" transform="translate(284.972656 45.84) scale(0.14 -0.14)"> <defs> @@ -975,7 +1124,7 @@ z </g> </g> <defs> - <clipPath id="pd32a051487"> + <clipPath id="peb2dec3e2c"> <rect x="90" y="51.84" width="558" height="332.64"/> </clipPath> </defs> diff --git a/src/investment/investment.py b/src/investment/investment.py index 4c54be5..e1104bd 100644 --- a/src/investment/investment.py +++ b/src/investment/investment.py @@ -24,7 +24,7 @@ class AgentResponse(BaseModel): # The investment game simulation class class Investment: def __init__(self, model: str, temperature: float, max_retries: int = 3): - self.debug = True + self.debug = False self.model = model self.temperature = temperature self.strategy = random @@ -159,39 +159,33 @@ class Investment: """ Computes the Critical Cost Efficiency Index (CCEI). """ - n = len(prices) # Number of observations - c = [1] # Minimize theta - A_ub = [] # Constraint matrix - b_ub = [] # Right-hand side values - for t in range(n): - for s in range(n): - lhs = np.dot(prices[t], choices[s]) # p_t * x_s - rhs = np.dot(prices[t], choices[t]) # p_t * x_t - if lhs > rhs: # Only add constraints where direct revealed preference exists - A_ub.append([-budgets[t]]) # -theta * I_t - b_ub.append(lhs - rhs) - # Ensure A_ub is a valid 2D array - if A_ub: - A_ub = np.array(A_ub, dtype=float) - if A_ub.ndim == 1: # Ensure it's 2D - A_ub = A_ub.reshape(-1, 1) - else: - A_ub = np.zeros((1, 1), dtype=float) # If no constraints, use a trivial 1x1 matrix - # Ensure b_ub is also valid - b_ub = np.array(b_ub, dtype=float) if b_ub else np.zeros(1, dtype=float) - - bounds = [(0, 1)] # Theta bounds - # Solve the linear program - result = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=bounds, method="highs") - if result.success: - return round(result.x[0], 4) # Return optimized theta value - else: - print("CCEI computation failed. Check constraints.") - return 0 # Return 0 if LP fails + num_rounds = len(prices) + lambdas = [] + for i in range(num_rounds): + # Objective: Maximize lambda (minimize -lambda) + c = [-1] + # Constraints: p_t * x_s <= lambda * I_t for all rounds s + A = [] + b = [] + for j in range(num_rounds): + p_t = prices[i] + x_s = choices[j] + I_t = budgets[i] + A.append([p_t[0] * x_s[0] + p_t[1] * x_s[1]]) + b.append(I_t) + # Add constraint that lambda is between 0 and 1 + bounds = [(0, 1)] + # Solve the linear programming problem + res = linprog(c, A_ub=A, b_ub=b, bounds=bounds, method='highs') + if res.success: + lambdas.append(res.x[0]) + else: + lambdas.append(0) + return min(lambdas) # The CCEI is the minimum lambda across all rounds # Run the async function and return the response if __name__ == "__main__": game_agent = Investment(model="mistral-small", temperature=0.0) # Toggle strategy here - response = asyncio.run(game_agent.run_rounds(10)) + response = asyncio.run(game_agent.run_rounds(30)) print(response) diff --git a/src/investment/investment_draw.py b/src/investment/investment_draw.py index d2e47da..baa7ab3 100644 --- a/src/investment/investment_draw.py +++ b/src/investment/investment_draw.py @@ -4,7 +4,7 @@ import matplotlib.pyplot as plt # Custom color palette color_palette = { - 'random': '#333333', # + 'random' : '#333333', # Black 'gpt-4.5-preview-2025-02-27': '#7abaff', # Blue 'llama3': '#32a68c', # Green 'mistral-small': '#ff6941', # Orange diff --git a/src/investment/investment_experiments.py b/src/investment/investment_experiments.py index ed828f0..a51056a 100644 --- a/src/investment/investment_experiments.py +++ b/src/investment/investment_experiments.py @@ -3,9 +3,9 @@ import csv from investment import Investment # Assuming this is in a separate file # Define models, temperature, and iterations -models = ["optimal", "random"] # "gpt-4.5-preview-2025-02-27" "random", "llama3", "mistral-small", "deepseek-r1" +models = ["optimal", "random", "llama3", "mistral-small", "deepseek-r1"] # "gpt-4.5-preview-2025-02-27", "optimal", "random", "llama3", "mistral-small", "deepseek-r1" temperature = 0.0 -iterations = 10 +iterations = 30 output_file = "../../data/investment/investment.csv" async def run_experiment(): @@ -22,7 +22,7 @@ async def run_experiment(): # Run DictatorConsistency experiment game_agent = Investment(model=model, temperature=temperature) - ccei_value = await game_agent.run_rounds(10) # Run 25 rounds + ccei_value = await game_agent.run_rounds(25) # Run 25 rounds # Write results to CSV writer.writerow([iteration, model, temperature, ccei_value]) -- GitLab