Ejemplo n.º 1
0
def generate_roommates_asymmetric_votes(num_agents: int = None):
    """ One of four extreme points for Compass """
    votes = [list(range(num_agents)) for _ in range(num_agents)]

    votes = [rotate(vote, shift) for shift, vote in enumerate(votes)]

    return convert(votes)
Ejemplo n.º 2
0
def generate_roommates_ic_votes(num_agents: int = None):
    """ Impartial Culture """

    votes = [
        list(np.random.permutation(num_agents)) for _ in range(num_agents)
    ]

    return convert(votes)
Ejemplo n.º 3
0
def generate_roommates_gs_ideal_votes(num_agents=None, params=None):

    m = num_agents
    n = num_agents

    decomposition_tree = _balanced(m)

    all_inner_nodes = get_all_inner_nodes(decomposition_tree)

    SIG = np.zeros([n, len(all_inner_nodes)])
    for s in range(1, n):
        SIG[s] = next_sig(SIG[s-1])

    EXT_SIG = np.zeros([n, len(all_inner_nodes)])
    for i, sig in enumerate(SIG):
        ctr = 0
        for k in range(int(math.log(n, 2))):
            # print('k', k, int(n/2**(k+1)))
            for t in range(int(n/2**(k+1))):
                # print('t', t)
                EXT_SIG[i][ctr] = sig[k]
                ctr += 1
                # EXT_SIG[k][2*i] = sig[i]
                # EXT_SIG[k][2*i+1] = sig[i]

    # print(SIG)
    # print(EXT_SIG)

    compute_depth(decomposition_tree)

    votes = []
    for i in range(n):

        signature = list(SIG[i])
        # signature  = [0,0,1,0,0,0,0]
        # signature.reverse()
        # print(signature)

        # print(SIG[i])

        for j, node in enumerate(all_inner_nodes):
            node.reverse = SIG[i][node.depth]
            # print(node.reverse)

        raw_vote = sample_a_vote(decomposition_tree)
        vote = [int(candidate.replace('x', '')) for candidate in raw_vote]
        votes.append(vote)

        for i, node in enumerate(all_inner_nodes):
            node.reverse = False

    # print(votes)
    # print(remove_first(votes))

    # order votes
    votes = sorted(votes, key=lambda x: x[0])

    return convert(votes)
Ejemplo n.º 4
0
def generate_roommates_gs_votes(num_agents=None, params=None):

    if params is None:
        params = {}

    if params is not None and 'tree' not in params:
        params = {'tree': 'random'}

    while True:
        m = num_agents
        n = num_agents

        if params['tree'] == 'random':
            func = lambda m, r: 1./(m-1) * binom(m - 1, r) * \
                                binom(m - 1 + r, m)
            buckets = [func(m, r) for r in range(1, m)]

            denominator = sum(buckets)
            # print(buckets)
            buckets = [buckets[i]/denominator for i in range(len(buckets))]

            num_internal_nodes = \
                np.random.choice(len(buckets), 1, p=buckets)[0]+1

            decomposition_tree = \
                _decompose_tree(num_agents, num_internal_nodes)

        elif params['tree'] == 'caterpillar':
            decomposition_tree = _caterpillar(m)

        elif params['tree'] == 'balanced':
            decomposition_tree = _balanced(m)

        all_inner_nodes = get_all_inner_nodes(decomposition_tree)

        votes = []
        for i in range(n):

            signature = [np.random.choice([0, 1])
                         for _ in range(len(all_inner_nodes))]

            for i, node in enumerate(all_inner_nodes):
                node.reverse = signature[i]

            raw_vote = sample_a_vote(decomposition_tree)
            vote = [int(candidate.replace('x', '')) for candidate in raw_vote]
            votes.append(vote)

            for i, node in enumerate(all_inner_nodes):
                node.reverse = False

        # return votes, decomposition_tree
        return convert(votes)
Ejemplo n.º 5
0
Archivo: urn.py Proyecto: szufix/mapel
def generate_roommates_urn_votes(num_agents: int = None, params=None):
    votes = np.zeros([num_agents, num_agents], dtype=int)
    urn_size = 1.
    for j in range(num_agents):
        rho = np.random.uniform(0, urn_size)
        if rho <= 1.:
            votes[j] = np.random.permutation(num_agents)
        else:
            votes[j] = votes[np.random.randint(0, j)]
        urn_size += params['alpha']

    return convert(votes)
Ejemplo n.º 6
0
def generate_roommates_norm_mallows_votes(num_agents=None, params=None):

    if 'norm-phi' not in params:
        params['norm-phi'] = np.random.rand()

    params['phi'] = phi_from_relphi(num_agents, relphi=params['norm-phi'])

    if 'weight' not in params:
        params['weight'] = 0.

    votes = generate_mallows_votes(num_agents, num_agents, params)

    return convert(votes)
Ejemplo n.º 7
0
def generate_roommates_malasym_votes(num_agents: int = None, params=None):
    """ Mallows on top of Asymmetric instance """

    votes = [list(range(num_agents)) for _ in range(num_agents)]

    votes = [rotate(vote, shift) for shift, vote in enumerate(votes)]

    if 'norm-phi' not in params:
        params['norm-phi'] = np.random.rand()

    params['phi'] = phi_from_relphi(num_agents, relphi=params['norm-phi'])
    votes = mallows_votes(votes, params['phi'])

    return convert(votes)
Ejemplo n.º 8
0
def generate_roommates_group_ic_votes(num_agents: int = None,
                                      params: dict = None):
    """ Impartial Culture with two groups """

    if 'proportion' not in params:
        params['proportion'] = 0.5

    size_1 = int(params['proportion'] * num_agents)
    size_2 = int(num_agents - size_1)

    votes_1 = [
        list(np.random.permutation(size_1)) +
        list(np.random.permutation([j for j in range(size_1, num_agents)]))
        for _ in range(size_1)
    ]

    votes_2 = [
        list(np.random.permutation([j for j in range(size_1, num_agents)])) +
        list(np.random.permutation(size_1)) for _ in range(size_2)
    ]

    votes = votes_1 + votes_2

    return convert(votes)
Ejemplo n.º 9
0
def generate_roommates_id_votes(num_agents: int = None):
    """ One of four extreme points for Compass """

    votes = [list(range(num_agents)) for _ in range(num_agents)]

    return convert(votes)