-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterizePerformance.py
More file actions
116 lines (95 loc) · 3.2 KB
/
CharacterizePerformance.py
File metadata and controls
116 lines (95 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
print("load_make_fungible.py")
import copy
import torch
import torch.nn as nn
import numpy as np
import h5py
import sys
import os
import matplotlib.pyplot as plt
import itertools as itt
import functools as ft
sys.path.append(os.getcwd())
from Hamiltonian import Hamiltonian
from generation_network_topology import CNA
from input_func import input_func, input_func_uni
from datafuncs import *
def rerange(x_og, y):
'''Linearly scale the range of "x" to that of "y"'''
x = copy.deepcopy(x_og)
with torch.no_grad():
x -= x.min()
x /= x.max()
x *= y.max() - y.min()
x += y.min()
return x
def SmartSample(data_size, fn, net_index=0, input_width=14):
with torch.no_grad():
big_in = input_func(data_size, fn, input_width)
#big_in = input_func_uni(data_size, fn, input_width)
big_in = rerange(big_in, standard_in)
#
big_out = netl[net_index](big_in)
big_lab = np.array([out_i.squeeze().numpy() for out_i in big_out])
return big_lab
def SampleRandomConfigs(data_size, fn):
big_out = torch.randint(0, 2, (data_size, 1, fn, fn))
big_out *= 2
big_out -= 1
big_lab = np.array([Hamiltonian(i.squeeze().numpy()) for i in big_out])
return big_lab
if __name__ == "__main__":
try:
fn = int(sys.argv[1])
except:
fn = 6
netl = []
for r in range(1, 10): #Loads several networks.
net = CNA()
net.load_state_dict(
torch.load(f"candidate_networks/inet{fn}_{r}.pt")
)
netl.append(net)
data_size = 100000 #mult
standard_in = input_func(data_size, fn, 14)
# Compare top 10 historgrams
slnl = ft.partial(np.unique, return_counts=True)
N_sample = 1000
smarts = (SmartSample(N_sample, fn, net_index=i) for i in range(len(netl)))
smarts = map(slnl, smarts)
# Plot 10 best.
plt.figure()
for smart_i in smarts:
plt.bar(smart_i[0], smart_i[1], align='edge')
plt.title("Histograms of Top 10 networks")
plt.xlabel("Derived Quantity Value [Energy]")
plt.ylabel("Number of Configurations")
#plt.savefig("top_10_historgrams.png")
plt.show()
plt.close()
# Compare best network against random sample.
smart = SmartSample(N_sample, fn)
smart_sl, smart_nl = np.unique(smart, return_counts=True)
#
rand = SampleRandomConfigs(N_sample, fn)
rand_sl, rand_nl = np.unique(rand, return_counts=True)
# Plot histogrmas
bar_width=0.8
plt.figure()
plt.bar(smart_sl, smart_nl, width=bar_width, align='edge')
plt.bar(rand_sl, rand_nl, width=-bar_width, align='edge')
plt.legend(["PickAI", "Random"])
plt.title("PickAI Distribution of Sample Derived Quantities")
plt.xlabel("Derived Quantity Value")
plt.ylabel("Number of Occurrences")
plt.show()
plt.close()
# Show just random configurations.
#plt.figure()
#plt.bar(rand_sl, rand_nl, color='orange', width=4)#, align='edge')
#plt.title("Internal Energies of 2D Ising Configurations")
#plt.xlabel("Internal Energies")
#plt.ylabel("Count")
#plt.xlim([-(72+4), 72+4])
#plt.savefig("BestNetwork_vs_RandomSample.png")
#plt.show()