SpikeNet 1.0.1__tar.gz → 1.0.3__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.1
3
+ Version: 1.0.3
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.3"
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
 
@@ -809,17 +816,14 @@ def DeleteAllBrain():
809
816
  _neurons = []
810
817
  _sinapce = []
811
818
  return
819
+
820
+
812
821
  def SaveBrain(state, file_name="Brain_out.brain"):
813
822
  neurons = state["neurons"]
814
823
  synapses = state["synapses"]
815
824
 
816
825
  n_text = ""
817
826
  for n in neurons:
818
- layer_parts = n["layer"].split("_")
819
- if len(layer_parts) > 1:
820
- layer_idx = 0
821
- else:
822
- layer_idx = 0
823
827
  n_text += f"{n['id']},{n['type']},{n['layer']},0\n"
824
828
 
825
829
  s_text = ""
@@ -840,31 +844,22 @@ def SaveBrain(state, file_name="Brain_out.brain"):
840
844
  return BrainTxt
841
845
 
842
846
 
843
- def Reward(state, reward):
847
+ def Reward(state, reward, lr=0.01):
844
848
  if reward == 0:
845
849
  return
846
850
 
847
851
  synapses = state["synapses"]
848
- spike_cnt = state["spike_cnt"]
849
- N = len(state["neurons"])
850
-
851
- max_spike = max(spike_cnt) if spike_cnt else 1.0
852
- if max_spike <= 0:
853
- return
852
+ elig = state["eligibility"]
854
853
 
855
854
  for s in synapses:
856
855
  pre = s["pre"]
857
856
  post = s["post"]
858
857
 
859
- pre_activity = spike_cnt[pre] / max_spike
860
- post_activity = spike_cnt[post] / max_spike
861
-
862
- if pre_activity > 0.1 and post_activity > 0.1:
863
- delta = 0.01 * reward * pre_activity * post_activity
864
- s["weight"] += delta
865
-
866
- if s["weight"] > 1.0:
867
- s["weight"] = 1.0
868
- if s["weight"] < -1.0:
869
- s["weight"] = -1.0
858
+ e = elig[pre] * elig[post]
859
+ if e > 0.01:
860
+ s["weight"] += lr * reward * e
861
+ if s["weight"] > 50.0:
862
+ s["weight"] = 50.0
863
+ if s["weight"] < -50.0:
864
+ s["weight"] = -50.0
870
865
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SpikeNet
3
- Version: 1.0.1
3
+ Version: 1.0.3
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.1"
7
+ version = "1.0.3"
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