for i in election_names:
        vars()["{}part".format(i)] = np.array(part[i].percents("Dem"))
        vars()["{}".format(i)].append(sorted(vars()["{}part".format(i)]))
        vars()["{}wins".format(i)].append(part[i].wins("Dem"))
        vars()["{}comp".format(i)].append(
            subset_list(vars()["{}part".format(i)], comp_lower, comp_higher))
        accumulating_election = accumulating_election + vars()["{}part".format(
            i)]

    avg = accumulating_election / num_elections
    AVG.append(sorted(avg))
    avgwins.append(subset_list(avg, 0.5, 1))
    avgcomp.append(subset_list(avg, comp_lower, comp_higher))
    avg_elect = avg[0]
    PB.append(gm.partisan_bias(avg_elect))
    MM.append(gm.mean_median(avg_elect))
    dem_vote_wins = avg_elect[avg_elect > 0.5]
    rep_vote_wins = avg_elect[avg_elect < 0.5]
    DemWinPerc.append(np.average(dem_vote_wins))
    RepWinPerc.append(1 - np.average(rep_vote_wins))

print("end")
time_elapsed = (time.time() - start_time) / 60
print("--- %s minutes ---" % time_elapsed)

act_accumulating_election = np.zeros((1, num_dist))
for i in election_names:
    vars()["{}winsfreq".format(i)] = {
        value: len(list(freq))
        for value, freq in groupby(sorted(vars()["{}wins".format(i)]))
    }
Esempio n. 2
0
    dem_voteshares_elections = total_dem_votes / (total_dem_votes +
                                                  total_rep_votes)
    dem_voteshare = np.average(dem_voteshares_elections, axis=0)

    # ---- Partisan Fairness Metrics ----
    dem_voteshares = avg_election_votes[avg_election_votes > 0.5]
    rep_voteshares = avg_election_votes[avg_election_votes < 0.5]
    avg_dem_win = np.average(dem_voteshares)
    avg_rep_win = 1 - np.average(rep_voteshares)

    # EG assumes equal turnout -- gets a different result than gerrychain
    EG = gm.EG(avg_election_votes)

    partisan_bias = gm.partisan_bias(avg_election_votes)

    mean_median = gm.mean_median(avg_election_votes)

    avgactWins = subset_list(avg_election_votes, 0.5, 1)
    # ---- Competitiveness -----
    competitive_vote_shares = avg_election_dict
    avgactcomp = subset_list(avg_election_votes, comp_lower, comp_higher)

    # ---- Export to JSON ------

    plan = {
        "state": state,
        "planName": district_assignment_col,
        "numDists": num_dist,
        "countySplits": num_splits,
        "lowerBoundCountySplits": lower_county_splits,
        "upperBoundCountySplits": upper_county_splits,
Esempio n. 3
0
# AVG Election vote shares
vote_shares = [
    np.array(sorted(prop_partition[election_names[i]].percents("Dem")))
    for i in range(num_elections)
]
avg_election = np.average(vote_shares, axis=0)

# ---- Partisan Fairness Metrics ----

# EG assumes equal turnout -- gets a different result than gerrychain
EG = gm.EG(avg_election)

partisan_bias = gm.partisan_bias(avg_election)

mean_median = gm.mean_median(avg_election)

# ---- Competitiveness -----
competitive_vote_shares = avg_election

# ---- Export to JSON ------

chain_obj = {
    "numDists": num_dist,
    "countySplits": num_county_splits,
    "lowerBoundCountySplits": lower_county,
    "upperBoundCountySplits": upper_county,
    "minPolsby-Popper": min_pp,
    "avgPolsby-Popper": avg_pp,
    "minReock": min_reock,
    "avgReock": avg_reock,