-
Notifications
You must be signed in to change notification settings - Fork 0
/
histogram.py
49 lines (39 loc) · 1.29 KB
/
histogram.py
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
import numpy as np
import altair as alt, pandas as pd
from network import Network, create_space
N=10 # the length of patterns
P=2 # the number of initial patterns
space = create_space(N)
data = {}
mat = np.random.randint(2, size=(P, N), dtype=np.int8)
mat[mat == 0] = -1
net = Network(patterns=np.array([
[-1, 1, -1, 1, 1, -1, 1, -1, 1, 1],
[1, 1, 1, -1, 1, -1, -1, -1, 1, -1]
]))
def state_type_str(x: int) -> str:
match x:
case 1:
return 'Initial'
case -1:
return 'Opposite'
case _:
return 'Spurious'
for config in space:
stable = net.compute(config)
key=str(stable)
data[key] = data.get(key, [stable, key, 0, state_type_str(net.is_learned_pattern(stable))])
data[key][2] = data[key][2] + 1
data = pd.DataFrame(data).transpose()
data.columns = ['Pattern', 'Label', 'Value', 'Type']
data.index = np.arange(len(data.index))
hist = alt.Chart(data).mark_bar(size=30).encode(
x=alt.X("Label", title='Pattern'),
y=alt.Y("Value", title='# of Attracted States'),
color=alt.Color("Type", scale=alt.Scale(
domain=['Initial', 'Opposite', 'Spurious'],
range=['#1679fa','#d91414','#35b821']))
).properties(
width=40*len(data.index)
).configure_axisX(labelAngle=-45, labelColor='black')
hist.show()