From a64c2f1e2c8774a2b38170a801bd666e281354e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Fleuret?= Date: Sat, 6 Jul 2024 21:59:08 +0300 Subject: [PATCH] Update. --- grids.py | 75 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/grids.py b/grids.py index 03da16d..03fa375 100755 --- a/grids.py +++ b/grids.py @@ -579,40 +579,52 @@ class Grids(problem.Problem): X[i, j] = c[1] f_X[0:2, 0:2] = c[1] - def task_islands(self, A, f_A, B, f_B): + def task_symbols(self, A, f_A, B, f_B): + nb_rec = 4 + c = torch.randperm(len(self.colors) - 1)[: nb_rec + 1] + 1 + delta = 3 for X, f_X in [(A, f_A), (B, f_B)]: - nb_on_border = 0 - for _ in range(10): - for k in torch.randperm(self.height * self.width): - i, j = k % self.height, k // self.height - border = ( - i == 0 or i == self.height - 1 or j == 0 or j == self.width - 1 - ) - no, nq, nq_diag = self.contact(X, i, j, 1) - - if ( - (nq > 0 and not border) - or (nq == 0 and border and nb_on_border < 4) - ) and nq_diag == 0: - X[i, j] = 1 - if border: - nb_on_border += 1 - while True: - nb_fixes = 0 - for i in range(1, self.height - 1): - for j in range(1, self.width - 1): - if ( - X[i, j] == 1 - and X[i - 1, j] + X[i + 1, j] + X[i, j - 1] + X[i, j + 1] - == 1 - ): - X[i, j] = 0 - nb_fixes += 1 - - if nb_fixes == 0: + i, j = torch.randint(self.height - delta + 1, (nb_rec,)), torch.randint( + self.width - delta + 1, (nb_rec,) + ) + d = (i[None, :] - i[:, None]).abs().max((j[None, :] - j[:, None]).abs()) + d.fill_diagonal_(delta + 1) + if d.min() > delta: break + for k in range(1, nb_rec): + X[i[k] : i[k] + delta, j[k] : j[k] + delta] = c[k] + + ai, aj = i.float().mean(), j.float().mean() + + q = torch.randint(3, (1,)) + 1 + + X[i[0] + delta // 2 - 1, j[0] + delta // 2 - 1] = c[0] + X[i[0] + delta // 2 - 1, j[0] + delta // 2 + 1] = c[0] + X[i[0] + delta // 2 + 1, j[0] + delta // 2 - 1] = c[0] + X[i[0] + delta // 2 + 1, j[0] + delta // 2 + 1] = c[0] + + assert i[q] != ai and j[q] != aj + + X[ + i[0] + delta // 2 + (i[q] - ai).sign().long(), + j[0] + delta // 2 + (j[q] - aj).sign().long(), + ] = c[nb_rec] + + f_X[i[0] : i[0] + delta, j[0] : j[0] + delta] = c[q] + + def task_islands(self, A, f_A, B, f_B): + pass + + # for X, f_X in [(A, f_A), (B, f_B)]: + # n = torch.arange(self.height * self.width).reshape(self.height, self.width) + # k = torch.randperm(self.height * self.width) + # X[...]=-1 + # for q in k: + # i,j=q%self.height,q//self.height + # if + ###################################################################### def all_tasks(self): @@ -627,7 +639,8 @@ class Grids(problem.Problem): self.task_trajectory, self.task_bounce, self.task_scale, - # self.task_islands, + self.task_symbols, + self.task_islands, ] def generate_prompts_and_answers(self, nb, tasks=None, device="cpu"): -- 2.39.5