SpikeNet 1.0.0__tar.gz → 1.0.1__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.1
4
4
  Summary: Spiking neural network library for games
5
5
  Author: Danic_Programmer
6
6
  License: MIT
@@ -808,4 +808,63 @@ def DeleteAllBrain():
808
808
  global _sinapce
809
809
  _neurons = []
810
810
  _sinapce = []
811
+ return
812
+ def SaveBrain(state, file_name="Brain_out.brain"):
813
+ neurons = state["neurons"]
814
+ synapses = state["synapses"]
815
+
816
+ n_text = ""
817
+ 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
+ n_text += f"{n['id']},{n['type']},{n['layer']},0\n"
824
+
825
+ s_text = ""
826
+ for i, s in enumerate(synapses):
827
+ s_type = "excitatory" if s["weight"] >= 0 else "inhibitory"
828
+ s_text += f"{i},{s['pre']},{s['post']},{s['weight']:.4f},{s['delay']:.2f},{s_type}\n"
829
+
830
+ BrainTxt = ""
831
+ BrainTxt += "Neurons\n"
832
+ BrainTxt += n_text
833
+ BrainTxt += "\nNeuronsEnd"
834
+ BrainTxt += "\nSinapce\n"
835
+ BrainTxt += s_text
836
+ BrainTxt += "\nSinapceEnd"
837
+
838
+ with open(os.path.join(user_script_dir, file_name), "w", encoding="utf-8") as f:
839
+ f.write(BrainTxt)
840
+ return BrainTxt
841
+
842
+
843
+ def Reward(state, reward):
844
+ if reward == 0:
845
+ return
846
+
847
+ 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
854
+
855
+ for s in synapses:
856
+ pre = s["pre"]
857
+ post = s["post"]
858
+
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
811
870
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SpikeNet
3
- Version: 1.0.0
3
+ Version: 1.0.1
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.1"
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