Download STDP_Communicator/test_stdpCommunicator.py from EvolphTech/Wildnerve-tlm01_Hybrid_Model: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/EvolphTech/Wildnerve-tlm01_Hybrid_Model/resolve/main/STDP_Communicator/test_stdpCommunicator.py
- Command line
-
hf download hf://EvolphTech/Wildnerve-tlm01_Hybrid_Model/STDP_Communicator/test_stdpCommunicator.py
-
curl -L -o test_stdpCommunicator.py https://huggingface.co/EvolphTech/Wildnerve-tlm01_Hybrid_Model/resolve/main/STDP_Communicator/test_stdpCommunicator.py
1.45 kB
| # test_stdpCommunicator.py | |
| import os | |
| import sys | |
| import unittest | |
| # Step 1: Determine the parent directory | |
| parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | |
| # Step 2: Append the parent directory to sys.path | |
| if parent_dir not in sys.path: | |
| sys.path.insert(0, parent_dir) | |
| from communicator import Synapse, SpikeEncoder | |
| class TestCommunicatorComponents(unittest.TestCase): | |
| def test_synapse_initialization(self): | |
| models = ["UI/UX", "Backend"] | |
| synapse = Synapse(models) | |
| self.assertEqual(synapse.weights, {"UI/UX": 0.5, "Backend": 0.5}) | |
| def test_synapse_update_weights(self): | |
| models = ["UI/UX", "Backend"] | |
| synapse = Synapse(models, learning_rate=0.1, decay=0.9) | |
| synapse.update_weights(["UI/UX"]) | |
| self.assertTrue(synapse.weights["UI/UX"] > 0.5) | |
| self.assertTrue(synapse.weights["Backend"] < 0.5) | |
| def test_spike_encoder_encode(self): | |
| encoder = SpikeEncoder(threshold=0.5) | |
| activations = {"UI/UX": 0.6, "Backend": 0.4} | |
| spikes = encoder.encode(activations) | |
| self.assertEqual(spikes, {"UI/UX": 1, "Backend": 0}) | |
| def test_spike_encoder_decode(self): | |
| encoder = SpikeEncoder() | |
| spikes = {"UI/UX": 1, "Backend": 0} | |
| decoded = encoder.decode(spikes) | |
| self.assertEqual(decoded, {"UI/UX": 1.0, "Backend": 0.0}) | |
| if __name__ == '__main__': | |
| unittest.main() |