X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=wireworld.py;h=65b12adda45e27ef20d3b4d646f092f663b37356;hb=3dca75c7144421022e45cea9288cd87957ff5867;hp=9e7d5135f26c094ec684bcbd80d8c65a788e02a3;hpb=488d9393dba8dcb18f1a7f1bfb88b5e867267787;p=culture.git diff --git a/wireworld.py b/wireworld.py index 9e7d513..65b12ad 100755 --- a/wireworld.py +++ b/wireworld.py @@ -121,9 +121,9 @@ class Wireworld(problem.Problem): weight = torch.full((1, 1, 3, 3), 1.0) - # mask = (torch.rand(result[:, 0].size()) < 0.01).long() - # rand = torch.randint(4, mask.size()) - # result[:, 0] = mask * rand + (1 - mask) * result[:, 0] + mask = (torch.rand(result[:, 0].size()) < 0.01).long() + rand = torch.randint(4, mask.size()) + result[:, 0] = mask * rand + (1 - mask) * result[:, 0] # empty->empty # head->tail @@ -314,7 +314,7 @@ class Wireworld(problem.Problem): if __name__ == "__main__": import time - wireworld = Wireworld(height=8, width=10, nb_iterations=2, speed=5) + wireworld = Wireworld(height=8, width=10, nb_iterations=5, speed=1) start_time = time.perf_counter() frame_sequences = wireworld.generate_frame_sequences(nb=96) @@ -323,19 +323,20 @@ if __name__ == "__main__": # print(wireworld.seq2str(seq[:4])) - # for t in range(frame_sequences.size(1)): - # img = wireworld.seq2img(frame_sequences[:, t]) - # torchvision.utils.save_image( - # img.float() / 255.0, - # f"/tmp/frame_{t:03d}.png", - # nrow=8, - # padding=6, - # pad_value=0, - # ) + for t in range(frame_sequences.size(1)): + img = wireworld.seq2img(frame_sequences[:, t]) + torchvision.utils.save_image( + img.float() / 255.0, + f"/tmp/frame_{t:03d}.png", + nrow=8, + padding=6, + pad_value=0, + ) # m = (torch.rand(seq.size()) < 0.05).long() # seq = (1 - m) * seq + m * 23 + wireworld = Wireworld(height=8, width=10, nb_iterations=2, speed=5) token_sequences = wireworld.generate_token_sequences(32) wireworld.save_quizzes(token_sequences, "/tmp", "seq") # img = wireworld.seq2img(frame_sequences[:60])