<jupyter_start><jupyter_text>**Sample on 10x10 grid graph**<jupyter_code># setting up data
dual_graph = nx.grid_graph([10,10])
A = nx.to_scipy_sparse_matrix(dual_graph)


# starting fake population, 1/4 population republican 3/4 democrat
repvote = np.zeros((10*10,1))
repvote[0:25] = 10
demvote = np.zeros((10*10,1))
demvote[25:] = 10

# 5 disctricts being equally sized columns
dists = np.zeros((10,10))
for i in range(dists.shape[0]):
    dists[i,0] = 1
    dists[i,1] = 1
    dists[i,2] = 2
    dists[i,3] = 2
    dists[i,4] = 3
    dists[i,5] = 3
    dists[i,6] = 4
    dists[i,7] = 4
    dists[i,8] = 5
    dists[i,9] = 5
dists = np.reshape(dists,(10*10,1))

pos = {}
for node in dual_graph.nodes():
    pos[node] = node
# setup the simulation
sim = ising.ising(repvote, demvote, A, target_energy=0, temp=2**35, steps=20)
# run the simulation
seats = []
energies = []

fig = plt.figure(dpi=100)
ax = fig.add_subplot(111)
plt.ion()

fig.show()
fig.canvas.draw()
for newrepvote, newdemvote, energy in sim:
    # setup new plot data
    ax.clear()
    
    # get color values for nodes
    value_map = []
    for i in range(dual_graph.number_of_nodes()):
        if newdemvote[i,0] == 0 and newrepvote[i,0] == 0:
            value_map.append(0.5)
        else:
            value_map.append((newrepvote[i,0]/(newdemvote[i,0] + newrepvote[i,0])))
    value_map = np.array(value_map)
    
    # draw new updated graph
    nx.draw_networkx(dual_graph, pos=pos, with_labels=False, cmap=plt.get_cmap('bwr'), \
                     node_color=value_map,vmin=0, vmax=1, ax=ax)
    #update plot
    fig.canvas.draw()
    
    seats.append(dems_seat_share(newdemvote, newrepvote, dists))
    energies.append(energy)
# plot democrat seat share to energy
fig = plt.figure()
plt.scatter(energies,seats)
plt.show()<jupyter_output><empty_output><jupyter_text>**Ising on real 2016 presidential voter data on the proposed TS plan**<jupyter_code># get data from as defined in config file
config_file = 'sample_config.txt'
penn_dual_graph, pennrepvote, penndemvote, penndists, penn_pos, node_size = pre.get_data(config_file)
draw.draw_state(penn_dual_graph, penndemvote, pennrepvote, penn_pos, node_size)
# get adjacency matrix 
A = nx.to_scipy_sparse_matrix(penn_dual_graph)
# setup ising simulation
penn_sim = ising.ising(pennrepvote, penndemvote, A, target_energy=0, temp=2**35, steps=2000)
pennseats = []
pennenergies = []
penndemvecs = []
pennrepvecs = []
nframes = 100
i=0

for pennnewrepvote, pennnewdemvote, pennenergy in penn_sim:
    # count seats
    seats_won = dems_seat_share(pennnewdemvote, pennnewrepvote, penndists)
    pennseats.append(seats_won)
    # record the energy level of the configuration
    pennenergies.append(pennenergy)
    
    # capture frame
    if i % (len(penn_sim) / nframes) == 0:
        penndemvecs.append(pennnewdemvote)
        pennrepvecs.append(pennnewrepvote)
    i+=1

plt.scatter(pennenergies, pennseats)
plt.show()
anim = draw.ising_anim(penn_dual_graph, penndemvecs, pennrepvecs, penn_pos, node_size)
plt.close()
HTML(anim.to_html5_video())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1282629713180793, 'fraction_numerical': 0.03351595230422172, 'mean_word_length': 4.216806722689076, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '141804', 'license': 'MIT', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1223, 'n_words': 249, 'path': '.ipynb_checkpoints/ising_demo-checkpoint.ipynb', 'repo_name': 'MarshMue/Population-Ising-Demo', 'size': '3103'}