SpikeNet 1.0.0__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SpikeNet
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: Spiking neural network library for games
5
5
  Author: Danic_Programmer
6
6
  License: MIT
@@ -2,7 +2,7 @@ import os
2
2
  import sys
3
3
  import random
4
4
 
5
- __version__ = "1.0.0"
5
+ __version__ = "1.0.2"
6
6
 
7
7
  _neurons = []
8
8
  _sinapce = []
@@ -726,10 +726,12 @@ def StartBrain(brain_index=0):
726
726
  "V": [-65.0] * N,
727
727
  "refract": [0] * N,
728
728
  "spike_cnt": [0.0] * N,
729
+ "eligibility": [0.0] * N,
729
730
  "delay_buffer": [],
730
731
  "delay_head": 0,
731
732
  "sensor_ids": [],
732
733
  "motor_ids": [],
734
+ "t": 0,
733
735
  }
734
736
 
735
737
  for n in neurons:
@@ -779,6 +781,7 @@ def StepBrain(state, sensors):
779
781
  state["V"][nid] = -75.0
780
782
  state["refract"][nid] = 2
781
783
  state["spike_cnt"][nid] += 1
784
+ state["eligibility"][nid] += 1.0
782
785
  for k in range(n_syn):
783
786
  if synapses[k]["pre"] == nid:
784
787
  slot = (state["delay_head"] + int(synapses[k]["delay"])) % buf_len
@@ -786,12 +789,16 @@ def StepBrain(state, sensors):
786
789
 
787
790
  state["delay_head"] = (state["delay_head"] + 1) % buf_len
788
791
 
792
+ for i in range(N):
793
+ state["eligibility"][i] *= 0.95
794
+
789
795
  motors = []
790
796
  for mid in state["motor_ids"]:
791
797
  rate = state["spike_cnt"][mid] / 50.0
792
798
  motors.append(min(1.0, rate))
793
799
  state["spike_cnt"][mid] *= 0.99
794
800
 
801
+ state["t"] += 1
795
802
  return motors
796
803
 
797
804
 
@@ -808,4 +815,51 @@ def DeleteAllBrain():
808
815
  global _sinapce
809
816
  _neurons = []
810
817
  _sinapce = []
818
+ return
819
+
820
+
821
+ def SaveBrain(state, file_name="Brain_out.brain"):
822
+ neurons = state["neurons"]
823
+ synapses = state["synapses"]
824
+
825
+ n_text = ""
826
+ for n in neurons:
827
+ n_text += f"{n['id']},{n['type']},{n['layer']},0\n"
828
+
829
+ s_text = ""
830
+ for i, s in enumerate(synapses):
831
+ s_type = "excitatory" if s["weight"] >= 0 else "inhibitory"
832
+ s_text += f"{i},{s['pre']},{s['post']},{s['weight']:.4f},{s['delay']:.2f},{s_type}\n"
833
+
834
+ BrainTxt = ""
835
+ BrainTxt += "Neurons\n"
836
+ BrainTxt += n_text
837
+ BrainTxt += "\nNeuronsEnd"
838
+ BrainTxt += "\nSinapce\n"
839
+ BrainTxt += s_text
840
+ BrainTxt += "\nSinapceEnd"
841
+
842
+ with open(os.path.join(user_script_dir, file_name), "w", encoding="utf-8") as f:
843
+ f.write(BrainTxt)
844
+ return BrainTxt
845
+
846
+
847
+ def Reward(state, reward, lr=0.01):
848
+ if reward == 0:
849
+ return
850
+
851
+ synapses = state["synapses"]
852
+ elig = state["eligibility"]
853
+
854
+ for s in synapses:
855
+ pre = s["pre"]
856
+ post = s["post"]
857
+
858
+ e = elig[pre] * elig[post]
859
+ if e > 0.01:
860
+ s["weight"] += lr * reward * e
861
+ if s["weight"] > 1.0:
862
+ s["weight"] = 1.0
863
+ if s["weight"] < -1.0:
864
+ s["weight"] = -1.0
811
865
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SpikeNet
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: Spiking neural network library for games
5
5
  Author: Danic_Programmer
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "SpikeNet"
7
- version = "1.0.0"
7
+ version = "1.0.2"
8
8
  description = "Spiking neural network library for games"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
File without changes
File without changes
File without changes