-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (47 loc) · 1.85 KB
/
Copy pathmain.py
File metadata and controls
60 lines (47 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
from compute_cq_build_unitary import compute_cq_and_unitary
def perturbed_coin(p=0.2, q=0.2, bitstring_length=int(1e3), seed=42):
"""
Generate a binary time series from a two-state perturbed coin process.
The process is a Markov order 1 chain with two internal states.
With probability p, the internal state flips; otherwise it remains the same.
The emitted symbol depends on the current state, producing correlated
binary output.
Arguments:
p (float, optional): Probability of switching internal state at each
timestep (default is 0.2).
bitstring_length (int, optional): Length of the generated binary time
series (default is 1000).
seed (int, optional): Random number generator seed (default is 42).
Returns:
bits (np.ndarray): 1D numpy array of {0, 1} representing the generated
binary time series.
"""
rng = np.random.default_rng(seed)
state = np.random.randint(2)+1
bits = np.empty(bitstring_length, dtype=int)
for ii in range(bitstring_length):
if state == 1:
if rng.random() < p:
state = 2
bits[ii] = 1
else:
bits[ii] = 0
else:
if rng.random() < q:
state = 1
bits[ii] = 0
else:
bits[ii] = 1
return np.array(bits)
def main():
# Generate bitstring
bits = perturbed_coin(p=0.2, q=0.2, bitstring_length=int(1e4), seed=42)
# Run quantum inference protocol
Cq, Unitary, QMS = compute_cq_and_unitary(bits, delta=int(1e-6), L=2)
print("Quantum statistical memory =", Cq)
print("Unitary =", np.around(Unitary, 4))
print("Unitary shape =", Unitary.shape)
print("Quantum memory states =", np.around(QMS, 4))
if __name__ == "__main__":
main()