def main(): initial_partition = PA_partition() chain = BasicChain(initial_partition, total_steps=10000) scores = { 'Mean-Median': functools.partial(mean_median, proportion_column_name='VoteA%'), 'Mean-Thirdian': functools.partial(mean_thirdian, proportion_column_name='VoteA%'), 'Efficiency Gap': functools.partial(efficiency_gap, col1='VoteA', col2='VoteB'), } initial_scores = { key: score(initial_partition) for key, score in scores.items() } table = pipe_to_table(chain, scores) return { key: p_value_report(key, table[key], initial_scores[key]) for key in scores }
def main(): initial_partition = PA_partition( '../rundmcmc/testData/PA_graph_with_data.json') chain = BasicChain(initial_partition, total_steps=10000) scores = { 'Mean-Median': functools.partial(mean_median, proportion_column_name='VoteA%'), 'Mean-Thirdian': functools.partial(mean_thirdian, proportion_column_name='VoteA%'), 'Efficiency Gap': functools.partial(efficiency_gap, col1='VoteA', col2='VoteB'), 'L1 Reciprocal Polsby-Popper': L1_reciprocal_polsby_popper } initial_scores = { key: score(initial_partition) for key, score in scores.items() } table = pipe_to_table(chain, scores) fig, axes = plt.subplots(2, 2) quadrants = { 'Mean-Median': (0, 0), 'Mean-Thirdian': (0, 1), 'Efficiency Gap': (1, 0), 'L1 Reciprocal Polsby-Popper': (1, 1) } for key in scores: quadrant = quadrants[key] axes[quadrant].hist(table[key], bins=50) axes[quadrant].set_title(key) axes[quadrant].axvline(x=initial_scores[key], color='r') plt.show()
col2=election_columns[i][1]) } scores_for_plots.append(vscores) scores = {**scores, **vscores} # Compute the values of the intial state and the chain initial_scores = { key: score(initial_partition) for key, score in scores.items() } table = pipe_to_table(chain, scores, display=True, number_to_display=number_to_display, bin_interval=bin_interval) print(steps, " Steps in ", time.time() - start_time, " Seconds") pscores = dict(scores) pscores.pop("Node Flipped:") pscores.pop("Flipped to:") pscores.pop("All Flips:") # P-value reports pv_dict = { key: p_value_report(key, table[key], initial_scores[key]) for key in pscores
functools.partial(how_many_seats_value, col1=election_columns[i][0], col2=election_columns[i][1]) } scores_for_plots.append(vscores) scores = {**scores, **vscores} # Compute the values of the intial state and the chain initial_scores = { key: score(initial_partition) for key, score in scores.items() } table = pipe_to_table(chain, scores, display=True, number_to_display=10) results_df = table.to_dataframe() for name in election_names: print(results_df["demseats" + name].describe()) print() # P-value reports pv_dict = { key: p_value_report(key, table[key], initial_scores[key]) for key in scores } # print(pv_dict) with open(newdir + 'pvals_report_multi.json', 'w') as fp: json.dump(pv_dict, fp)
'Mean-Thirdian': functools.partial(mean_thirdian, proportion_column_name=vote_col1 + "%"), 'Efficiency Gap': functools.partial(efficiency_gap, col1=vote_col1, col2=vote_col2), 'L1 Reciprocal Polsby-Popper': L1_reciprocal_polsby_popper } initial_scores = { key: score(initial_partition) for key, score in scores.items() } table = pipe_to_table(chain, scores, display=True, display_frequency=100, bin_frequency=1) # Histogram Plotting hist_path = "chain_histogram31.png" hist_of_table_scores(table, scores, outputFile=hist_path, num_bins=50) print("plotted histograms") # Trace Plotting trace_path = "chain_traces31.png" trace_of_table_scores(table, scores, outputFile=trace_path)
def test_pipe_to_table_records_all_scores_by_default(self): mock_chain, handlers, values = self.setup() table = pipe_to_table(mock_chain, handlers, display=False) assert all(table[key] == values[key] for key in values)