It is difficult to visualize or compare different paths of steps because they are just lists of separate events. This makes it hard to see how different sequences relate to one another.
It takes a sequence of steps and converts them into a single mathematical map. This allows you to see how different paths relate to each other in a shared space.
It allows you to see the relationships between different paths in a single view.
It was run inside an isolated container with no network access. This is the exact command and the real output it produced — captured process output, not written by a model.
$ python3 main.py Error: Missing input sequence file path
A screenshot of that run.
A clean run proves this does what is shown above, in a CPU-only sandbox. It is a small research demo — not a production tool, and nothing here was published anywhere.
All of it — 58 lines, one file, standard library only.
#!/usr/bin/env python3
import sys
import math
from collections import defaultdict
def main(sequence):
transitions = defaultdict(lambda: defaultdict(int))
for i in range(len(sequence) - 1):
current = sequence[i]
next_state = sequence[i + 1]
transitions[current][next_state] += 1
probabilities = {}
for state in transitions:
total = sum(transitions[state].values())
probabilities[state] = {next_state: count / total for next_state, count in transitions[state].items()}
all_states = set(sequence)
embedding = {}
entropy = {}
# Calculate entropy for each state
for state in all_states:
if state in probabilities:
ent = 0.0
for prob in probabilities[state].values():
ent -= prob * math.log2(prob)
entropy[state] = ent
else:
entropy[state] = 0.0
# Build embedding
for state in all_states:
if state in probabilities:
embedding[state] = {next_state: prob for next_state, prob in probabilities[state].items()}
else:
embedding[state] = {}
return embedding, entropy
if __name__ == "__main__":
if len(sys.argv) < 2:
sequence = ['A', 'B', 'A', 'C', 'B', 'D']
embedding, entropy = main(sequence)
else:
try:
with open(sys.argv[1], 'r') as f:
sequence = [line.strip() for line in f.readlines() if line.strip()]
embedding, entropy = main(sequence)
except FileNotFoundError:
print(f"Error: File '{sys.argv[1]}' not found")
sys.exit(1)
print("State Transition Embeddings with Entropy:")
for state in embedding:
transitions = embedding[state]
ent = entropy[state]
print(f"{state}: {transitions}, Entropy: {ent:.4f}")