This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net(nn.Module): | |
def __init__(self, input_size, out_size): | |
super(Net, self).__init__() | |
self.input_size = input_size | |
self.hidden1 = nn.Conv2d(2, 4, 3, stride=1, padding=3, bias=True) | |
self.hidden2 = nn.Conv2d(4, 8, 3, stride=1, padding=2, bias=True) | |
self.hidden3 = nn.Conv2d(8, 4, 3, stride=1, padding=2, bias=True) | |
self.fc1 = nn.Linear(4 * 24 * 24, 128) | |
self.fc2 = nn.Linear(128, out_size) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_gameoflife = Net(W, N_RULES) | |
model_gameoflife.load_state_dict(torch.load("./model_gameoflife2")) | |
video = Animator(CellAuto([4, 6], [1, 6]), model=model_gameoflife) | |
HTML(video(path="images/cell_amim3.gif").to_html5_video()) | |
video = Animator(CellAuto([1, 5], [2, 3]), model=model_gameoflife) | |
HTML(video(path="images/cell_amim4.gif").to_html5_video()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net(nn.Module): | |
def __init__(self, input_size, rule_size): | |
super(Net, self).__init__() | |
self.input_size = input_size | |
self.hidden1 = nn.Conv2d(2, 4, 3, stride=1, padding=3, bias=True) | |
self.hidden2 = nn.Conv2d(4, 8, 3, stride=1, padding=2, bias=True) | |
self.hidden3 = nn.Conv2d(8, 4, 3, stride=1, padding=2, bias=True) | |
self.fc_rule = nn.Linear(rule_size, input_size ** 2) | |
self.fc1 = nn.Linear(4 * 24 * 24, input_size ** 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_gameoflife = Net(W) | |
model_gameoflife.load_state_dict(torch.load("./model_gameoflife1")) | |
video = Animator(CellAuto([2, 3], [3]), model=model_gameoflife) | |
HTML(video(path="images/cell_amim2.gif").to_html5_video()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net(nn.Module): | |
def __init__(self, input_size): | |
super(Net, self).__init__() | |
self.input_size = input_size | |
self.hidden1 = nn.Conv2d(1, 2, 3, stride=1, padding=3) | |
self.hidden2 = nn.Conv2d(2, 4, 3, stride=1, padding=2) | |
self.hidden3 = nn.Conv2d(4, 8, 3, stride=1, padding=2) | |
self.fc1 = nn.Linear(8 * 24 * 24, input_size**2) | |
self.sm = nn.Sigmoid() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
video = Animator(CellAuto([2, 3], [3], distribution=[0.8, 0.2])) | |
HTML(video(path="images/cell_amim1.gif").to_html5_video()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animator: | |
def __init__(self, auto_cell, model=None, cmap='cividis'): | |
self.cellula = auto_cell | |
self.model = model | |
self.cmap = cmap | |
sig = str(self.cellula) | |
assert sig in RULES_MAP, "rule must be part from training set rules" | |
self.rule = RULES_MAP[sig] | |
def prepare_data(self, n_iterations): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
W = H = 16 # height, width | |
class CellAuto: | |
def __init__(self, live: list, dead: list, distribution: list=[.5, .5]): | |
self.live = live # num of neighbors when cell is alive in order to keep alive | |
self.dead = dead # num of neighbors when cell is dead in order cell to be alive again | |
self.data = np.random.choice(2, H*W, p=distribution).astype(np.uint8).reshape((H, W)) | |
def get_live_neighbors(self, i, c): | |
sum = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
feats = np.array([ | |
[-1.05, -0.05], | |
[-0.5, -0.05], | |
[-1.05, -0.15], | |
[-1.05, -0.05], | |
[-0.05, 1.05] | |
]) | |
plot_compare(feats) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_single(n_rows, img, title, i): | |
plt.subplot(2, n_rows, i) | |
plt.title(title) | |
plt.imshow(img) | |
plt.axis('off') | |
def plot_compare(feats): | |
n_rows = feats.shape[0] | |
plt.figure(figsize=(10, 5)) | |
NewerOlder