projects
/
picoclvr.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b622899
)
Update.
master
author
François Fleuret
<francois@fleuret.org>
Mon, 17 Jun 2024 13:53:17 +0000
(15:53 +0200)
committer
François Fleuret
<francois@fleuret.org>
Mon, 17 Jun 2024 13:53:17 +0000
(15:53 +0200)
turing.py
patch
|
blob
|
history
diff --git
a/turing.py
b/turing.py
index
66c7f03
..
2bcdeeb
100755
(executable)
--- a/
turing.py
+++ b/
turing.py
@@
-3,7
+3,7
@@
import torch
import torch
-def generate_turing_sequences(N, nb_iter=5, nb_states=
4, nb_symbols=2
, tape_size=5):
+def generate_turing_sequences(N, nb_iter=5, nb_states=
3, nb_symbols=4
, tape_size=5):
next_state = torch.randint(nb_states, (N, nb_states, nb_symbols))
next_symbol = torch.randint(nb_symbols, (N, nb_states, nb_symbols))
next_move = torch.randint(3, (N, nb_states, nb_symbols))
next_state = torch.randint(nb_states, (N, nb_states, nb_symbols))
next_symbol = torch.randint(nb_symbols, (N, nb_states, nb_symbols))
next_move = torch.randint(3, (N, nb_states, nb_symbols))
@@
-11,13
+11,15
@@
def generate_turing_sequences(N, nb_iter=5, nb_states=4, nb_symbols=2, tape_size
all_n = torch.arange(N)
tape = torch.randint(nb_symbols, (N, tape_size))
all_n = torch.arange(N)
tape = torch.randint(nb_symbols, (N, tape_size))
- position = torch.randint(tape_size, (N,))
- state = torch.randint(nb_states, (N,))
+ # position = torch.randint(tape_size, (N,))
+ # state = torch.randint(nb_states, (N,))
+ position = torch.zeros(N, dtype=torch.int64)
+ state = torch.zeros(N, dtype=torch.int64)
result = []
for _ in range(nb_iter):
result = []
for _ in range(nb_iter):
- result.append(tape)
+ result.append(tape
.clone()
)
current_symbol = tape[all_n, position]
tape[all_n, position] = next_symbol[all_n, state, current_symbol]
position = (position + next_move[all_n, state, current_symbol] - 1) % tape_size
current_symbol = tape[all_n, position]
tape[all_n, position] = next_symbol[all_n, state, current_symbol]
position = (position + next_move[all_n, state, current_symbol] - 1) % tape_size
@@
-33,10
+35,10
@@
def generate_turing_sequences(N, nb_iter=5, nb_states=4, nb_symbols=2, tape_size
if __name__ == "__main__":
print("Basic check.")
if __name__ == "__main__":
print("Basic check.")
- tapes = generate_turing_sequences(
5
)
+ tapes = generate_turing_sequences(
1, nb_iter=10
)
for i in range(tapes.size(1)):
for i in range(tapes.size(1)):
- print(f"- {i:03d} ------------------------")
+
#
print(f"- {i:03d} ------------------------")
# for s, h, r in zip(state, position, tape):
# print("".join([f"{x}" for x in r]))
# print(" " * h + f"^[{s}]")
# for s, h, r in zip(state, position, tape):
# print("".join([f"{x}" for x in r]))
# print(" " * h + f"^[{s}]")