Class ParticipationModel
Bases: Model
The ParticipationModel class provides a base environment for multi-agent simulations within a grid-based world (split into territories) that reacts dynamically to frequently held collective decision-making processes ("elections"). It incorporates voting agents with personalities, color cells (grid fields), and areas (election territories). This model is designed to analyze different voting rules and their impact.
This class provides mechanisms for creating and managing cells, agents, and areas, along with data collection for analysis. Colors in the model mutate depending on a predefined mutation rate and are influenced by elections. Agents interact based on their personalities, knowledge, and experiences.
Attributes:
Name | Type | Description |
---|---|---|
grid |
SingleGrid
|
Grid representing the environment with a single occupancy per cell (the color). |
height |
int
|
The height of the grid. |
width |
int
|
The width of the grid. |
colors |
ndarray
|
Array containing the unique color identifiers. |
voting_rule |
Callable
|
A function defining the social welfare function to aggregate agent preferences. This callable typically takes agent rankings as input and returns a single aggregate result. |
distance_func |
Callable
|
A function used to calculate a distance metric when comparing rankings. It takes two rankings and returns a numeric distance score. |
mu |
float
|
Mutation rate; the probability of each color cell to mutate after an elections. |
color_probs |
ndarray
|
Probabilities used to determine individual color mutation outcomes. |
options |
ndarray
|
Matrix (array of arrays) where each subarray represents an option (color-ranking) available to agents. |
option_vec |
ndarray
|
Array holding the indices of the available options for computational efficiency. |
color_cells |
list[ColorCell]
|
List of all color cells. Initialized during the model setup. |
voting_agents |
list[VoteAgent]
|
List of all voting agents. Initialized during the model setup. |
personalities |
list
|
List of unique personalities available for agents. |
personality_distribution |
ndarray
|
The (global) probability distribution of personalities among all agents. |
areas |
list[Area]
|
List of areas (regions or territories within the grid) in which elections take place. Initialized during model setup. |
global_area |
Area
|
The area encompassing the entire grid. |
av_area_height |
int
|
Average height of areas in the simulation. |
av_area_width |
int
|
Average width of areas created in the simulation. |
area_size_variance |
float
|
Variance in area sizes to introduce non-uniformity among election territories. |
common_assets |
int
|
Total resources to be distributed among all agents. |
av_area_color_dst |
ndarray
|
Current (area)-average color distribution. |
election_costs |
float
|
Cost associated with participating in elections. |
max_reward |
float
|
Maximum reward possible for an agent each election. |
known_cells |
int
|
Number of cells each agent knows the color of. |
datacollector |
DataCollector
|
A tool for collecting data (metrics and statistics) at each simulation step. |
scheduler |
CustomScheduler
|
The scheduler responsible for executing the step function. |
draw_borders |
bool
|
Only for visualization (no effect on simulation). |
_preset_color_dst |
ndarray
|
A predefined global color distribution (set randomly) that affects cell initialization globally. |
Source code in democracy_sim/participation_model.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 |
|
adjust_color_pattern(color_patches_steps, patch_power)
Adjusting the color pattern to make it less predictable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_patches_steps
|
int
|
How often to run the color-patches step. |
required |
patch_power
|
float
|
The power of the patching (like a radius of impact). |
required |
Source code in democracy_sim/participation_model.py
839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
|
color_by_dst(color_distribution)
staticmethod
Selects a color (int) from range(len(color_distribution)) based on the given color_distribution array, where each entry represents the probability of selecting that index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_distribution
|
array
|
Array determining the selection probabilities. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The selected index based on the given probabilities. |
Example
color_distribution = [0.2, 0.3, 0.5] Color 1 will be selected with a probability of 0.3.
Source code in democracy_sim/participation_model.py
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 |
|
color_patches(cell, patch_power)
This method is used to create a less random initial color distribution using a similar logic to the color patches model. It uses a (normalized) bias coordinate to center the impact of the color patches structures impact around.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cell
|
ColorCell
|
The cell that may change its color accordingly |
required |
patch_power
|
float
|
Like a radius of impact around the bias point. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
The consensus color or the cell's own color if no consensus. |
Source code in democracy_sim/participation_model.py
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 |
|
create_all_options(n, include_ties=False)
staticmethod
Creates a matrix (an array of all possible ranking vectors), if specified including ties. Rank values start from 0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The number of items to rank (number of colors in our case) |
required |
include_ties
|
bool
|
If True, rankings include ties. |
False
|
Returns:
Type | Description |
---|---|
np.array: A matrix containing all possible ranking vectors. |
Source code in democracy_sim/participation_model.py
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 |
|
create_color_distribution(heterogeneity)
This method is used to create a color distribution that has a bias according to the given heterogeneity factor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
heterogeneity
|
float
|
Factor used as sigma in 'random.gauss'. |
required |
Source code in democracy_sim/participation_model.py
855 856 857 858 859 860 861 862 863 864 865 866 867 868 |
|
create_personalities(n)
Creates n unique "personalities," where a "personality" is a specific permutation of self.num_colors color indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
Number of unique personalities to generate. |
required |
Returns:
Type | Description |
---|---|
np.ndarray: Array of shape |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Example
for n=2 and self.num_colors=3, the function could return:
[[1, 0, 2], [2, 1, 0]]
Source code in democracy_sim/participation_model.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 |
|
init_color_probs(election_impact)
This method initializes a probability array for the mutation of colors. The probabilities reflect the election outcome with some impact factor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
election_impact
|
float
|
The impact the election has on the mutation. |
required |
Source code in democracy_sim/participation_model.py
658 659 660 661 662 663 664 665 666 667 668 669 |
|
initialize_all_areas()
Initializes all areas on the grid in the model.
This method divides the grid into approximately evenly distributed areas,
ensuring that the areas are spaced as uniformly as possible based
on the grid dimensions and the average area size specified by
av_area_width
and av_area_height
.
The grid may contain more or fewer areas than an exact square
grid arrangement due to num_areas
not always being a perfect square.
If the number of areas is not a perfect square, the remaining areas
are placed randomly on the grid to ensure that num_areas
areas are initialized.
Returns:
Type | Description |
---|---|
None
|
None. initializes |
Example
- Given
num_areas = 4
andgrid.width = grid.height = 10
, this method might initialize areas with approximate distances to maximize uniform distribution (like a 2x2 grid). - For
num_areas = 5
, four areas will be initialized evenly, and the fifth will be placed randomly due to the uneven distribution.
Source code in democracy_sim/participation_model.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
|
initialize_area(a_id, x_coord, y_coord)
This method initializes one area in the models' grid.
Source code in democracy_sim/participation_model.py
671 672 673 674 675 676 677 678 679 680 681 |
|
initialize_global_area()
This method initializes the global area spanning the whole grid.
Returns:
Name | Type | Description |
---|---|---|
Area |
The global area (with unique_id set to -1 and idx to (0, 0)). |
Source code in democracy_sim/participation_model.py
747 748 749 750 751 752 753 754 755 756 757 758 |
|
initialize_voting_agents()
This method initializes as many voting agents as set in the model with a randomly chosen personality. It places them randomly on the grid. It also ensures that each agent is assigned to the color cell it is standing on.
Source code in democracy_sim/participation_model.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 |
|
pers_dist(size)
staticmethod
This method creates a normalized normal distribution array for picking and depicting the distribution of personalities in the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
The mean value of the normal distribution. |
required |
Returns:
Type | Description |
---|---|
np.array: Normalized (sum is one) array mimicking a gaussian curve. |
Source code in democracy_sim/participation_model.py
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
|
step()
Advance the model by one step.
Source code in democracy_sim/participation_model.py
825 826 827 828 829 830 831 832 833 834 835 836 |
|
update_av_area_color_dst()
This method updates the av_area_color_dst attribute of the model. Beware: On overlapping areas, cells are counted several times.
Source code in democracy_sim/participation_model.py
912 913 914 915 916 917 918 919 920 921 |
|