Skip to content

Commit

Permalink
Activationa and Monitoring example
Browse files Browse the repository at this point in the history
  • Loading branch information
EltonCN committed Oct 18, 2024
1 parent e60d45a commit f064510
Show file tree
Hide file tree
Showing 4 changed files with 442 additions and 372 deletions.
371 changes: 0 additions & 371 deletions dev/simple_test.ipynb

This file was deleted.

405 changes: 405 additions & 0 deletions examples/Activation and Monitoring.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ packages = find:
where = src

[options.extras_require]
tests = mypy; testbook; ipython; ipykernel
tests = mypy; testbook; ipython; ipykernel; numpy; matplotlib
36 changes: 36 additions & 0 deletions tests/examples/test_activation_and_monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import math

import numpy as np
from testbook import testbook
from testbook.client import TestbookNotebookClient

from ..utils import get_examples_path

examples_path = get_examples_path()

@testbook(os.path.join(examples_path, "Activation and Monitoring.ipynb"), execute=True)
def test_activation(tb :TestbookNotebookClient):
activation_hist = tb.ref("activation_hist.tolist()")
input_hist = tb.ref("input_hist.tolist()")
sensory_output_hist = tb.ref("sensory_output_hist.tolist()")
action_hist = tb.ref("action_hist.tolist()")

last_sensory_output = sensory_output_hist[0]
for i, (activation, input_value, sensory_output, action) in enumerate(zip(activation_hist, input_hist, sensory_output_hist, action_hist)):
assert math.isclose(input_value, i/100)

assert math.isclose(activation, np.clip(input_value, 0.0, 1.0), abs_tol=0.021)

if i >= 50 and activation < 0.7:
expected_sensory = last_sensory_output
else:
expected_sensory = input_value * 10

assert math.isclose(sensory_output, expected_sensory, abs_tol=0.21)

last_sensory_output = sensory_output

assert math.isclose(action_hist[0], True )
assert math.isclose(action_hist[55], False )
assert math.isclose(action_hist[-1], True )

0 comments on commit f064510

Please sign in to comment.