forked from the-aerospace-corporation/brainblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonline_learning_scalar_sequence_anomalies.py
More file actions
50 lines (39 loc) · 1.52 KB
/
online_learning_scalar_sequence_anomalies.py
File metadata and controls
50 lines (39 loc) · 1.52 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
# ==============================================================================
# online_learning_scalar_sequence_anomalies.py
# ==============================================================================
from brainblocks.blocks import ScalarTransformer, SequenceLearner
values = [
0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.2, 1.0, 1.0] # <-- anomaly is 0.2
scores = [0.0 for _ in range(len(values))]
# Setup blocks
st = ScalarTransformer(
min_val=0.0, # minimum input value
max_val=1.0, # maximum input value
num_s=64, # number of statelets
num_as=8) # number of active statelets
sl = SequenceLearner(
num_spc=10, # number of statelets per column
num_dps=10, # number of dendrites per statelet
num_rpd=12, # number of receptors per dendrite
d_thresh=6, # dendrite threshold
perm_thr=20, # receptor permanence threshold
perm_inc=2, # receptor permanence increment
perm_dec=1) # receptor permanence decrement
# Connect blocks
sl.input.add_child(st.output, 0)
# Loop through the values
for i in range(len(values)):
# Set scalar transformer value
st.set_value(values[i])
# Compute the scalar transformer
st.feedforward()
# Compute the sequence learner
sl.feedforward(learn=True)
# Get anomaly score
scores[i] = sl.get_anomaly_score()
# Print output
print("val, scr")
for i in range(len(values)):
print("%0.1f, %0.1f" % (values[i], scores[i]))