stdpneuron 0.1.0__tar.gz → 0.1.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.5
2
2
  Name: stdpneuron
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: idk
5
5
  Project-URL: Documentation, https://github.com/Guille-ux/stdpneuron#readme
6
6
  Project-URL: Issues, https://github.com/Guille-ux/stdpneuron/issues
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2026-present Guille-ux <guilleleiratemes@gmail.com>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.1.0"
4
+ __version__ = "0.1.2"
@@ -0,0 +1,80 @@
1
+ import json
2
+ import random
3
+
4
+ class NeuronMass:
5
+ def __init__(self, n_neurons=100, n_cons=50, v_decay=0.5, t_decay=0.5):
6
+ self.n_neurons = n_neurons
7
+ self.n_cons = n_cons
8
+ self.total_cons = n_cons * n_neurons
9
+ self.connections_in = [0] * self.total_cons # en q neurona entra
10
+ self.connections_out = [0] * self.total_cons # de q neurona sale
11
+ self.threeholds = [1] * self.n_neurons
12
+ self.voltage = [0] * self.n_neurons
13
+ self.temperature = [0] * self.total_cons
14
+ self.plasticity = [1] * self.total_cons
15
+ self.bias = [1] * self.total_cons
16
+ self.pr = 0
17
+ self.outputs = [0] * self.n_neurons
18
+ self.v_decay = v_decay
19
+ self.t_decay = t_decay
20
+ def save_model(self, name):
21
+ dict = {"n_neurons":self.n_neurons,
22
+ "n_cons":self.n_cons,
23
+ "total_cons":self.total_cons,
24
+ "connections_in":self.connections_in,
25
+ "connections_out":self.connections_out,
26
+ "threeholds":self.threeholds,
27
+ "plasticity":self.plasticity,
28
+ "biases":self.bias,
29
+ "v_decay":self.v_decay,
30
+ "t_decay":self.t_decay
31
+ }
32
+ with open(name, "w") as f:
33
+ json.dump(dict, f)
34
+ def load_model(self, name):
35
+ with open(name, "r") as f:
36
+ dict = json.load(f)
37
+ self.n_neurons = dict["n_neurons"]
38
+ self.n_cons = dict["n_cons"]
39
+ self.total_cons = dict["total_cons"]
40
+ self.connections_in = dict["connections_in"]
41
+ self.connections_out = dict["connections_out"]
42
+ self.threeholds = dict["threeholds"]
43
+ self.plasticity = dict["plasticity"]
44
+ self.bias = dict["biases"]
45
+ self.v_decay = dict["v_decay"]
46
+ self.t_decay = dict["t_decay"]
47
+ def generate_connections(self):
48
+ for i in range(self.n_neurons):
49
+ for j in range(self.n_cons):
50
+ self.connections_out[i*self.n_cons+j] = i
51
+ self.connections_in[i*self.n_cons+j] = random.randint(0, self.n_neurons-1)
52
+ # esta función genera conexiones neuronales aleatorias, bruh
53
+ def tick(self):
54
+ # PROCESAR ACTIVACIÓN DE NEURONAS
55
+ for i in range(self.n_neurons):
56
+ cons_ids = []
57
+ delta_voltage = 0
58
+ for j in range(self.total_cons):
59
+ if self.connections_in[j] == i: # es decir, esta conexión entra en la neurona q estamos mirando?
60
+ cons_ids.append(j)
61
+ delta_voltage += self.bias[j]*self.outputs[self.connections_out[j]] * self.voltage[self.connections_out[j]]
62
+ self.temperature[j] += 1
63
+ self.voltage[i] += delta_voltage
64
+ if self.voltage[i] > self.threeholds[i]:
65
+ self.outputs[i] = 1
66
+ else:
67
+ self.outputs[i] = 0
68
+ self.voltage[i] *= self.v_decay
69
+ # CALCULAR CAMBIOS EN LAS CONEXIONES Y APLICARLOS
70
+ for i in range(self.total_cons):
71
+ neuron_in = self.connections_in[i]
72
+ neuron_out = self.connections_out[i]
73
+ if self.outputs[neuron_in] == 1:
74
+ self.bias[i] += self.plasticity[i] * (self.temperature[i])
75
+ else:
76
+ self.bias[i] -= self.plasticity[i] * self.temperature[i]
77
+
78
+ self.bias[i] += self.pr * self.plasticity[i] * self.temperature[i]
79
+
80
+ self.temperature[i] *= self.t_decay
@@ -1,80 +0,0 @@
1
- import json
2
- import random
3
-
4
- class NeuronMass:
5
- def __init__(self, n_neurons=100, n_cons=50, v_decay=0.5, t_decay=0.5):
6
- self.n_neurons = n_neurons
7
- self.n_cons = n_cons
8
- self.total_cons = n_cons * n_neurons
9
- self.connections_in = [0] * self.total_cons # en q neurona entra
10
- self.connections_out = [0] * self.total_cons # de q neurona sale
11
- self.threeholds = [1] * self.n_neurons
12
- self.voltage = [0] * self.n_neurons
13
- self.temperature = [0] * self.total_cons
14
- self.plasticity = [1] * self.total_cons
15
- self.bias = [1] * self.total_cons
16
- self.pr = 0
17
- self.outputs = [0] * self.n_neurons
18
- self.v_decay = v_decay
19
- self.t_decay = t_decay
20
- def save_model(self, name):
21
- dict = {"n_neurons":self.n_neurons,
22
- "n_cons":self.n_cons,
23
- "total_cons":self.total_cons,
24
- "connections_in":self.connections_in,
25
- "connections_out":self.connections_out,
26
- "threeholds":self.threeholds,
27
- "plasticity":self.plasticity,
28
- "biases":self.bias,
29
- "v_decay":self.v_decay,
30
- "t_decay":self.t_decay
31
- }
32
- with open(name, "w") as f:
33
- json.dump(dict, f)
34
- def load_model(self, name):
35
- with open(name, "r") as f:
36
- dict = json.load(f)
37
- self.n_neurons = dict["n_neurons"]
38
- self.n_cons = dict["n_cons"]
39
- self.total_cons = dict["total_cons"]
40
- self.connections_in = dict["connections_in"]
41
- self.connections_out = dict["connections_out"]
42
- self.threeholds = dict["threeholds"]
43
- self.plasticity = dict["plasticity"]
44
- self.bias = dict["biases"]
45
- self.v_decay = dict["v_decay"]
46
- self.t_decay = dict["t_decay"]
47
- def generate_connections(self):
48
- for i in range(self.n_neurons):
49
- for j in range(self.n_cons):
50
- self.connections_out[i*self.n_cons+j] = i
51
- self.connections_in[i*self.n_cons+j] = random.randint(0, self.n_neurons)
52
- # esta función genera conexiones neuronales aleatorias, bruh
53
- def tick(self):
54
- # PROCESAR ACTIVACIÓN DE NEURONAS
55
- for i in range(self.n_neurons):
56
- cons_ids = []
57
- delta_voltage = 0
58
- for j in range(self.total_cons):
59
- if self.connections_in[j] == i: # es decir, esta conexión entra en la neurona q estamos mirando?
60
- cons_ids.append(j)
61
- delta_voltage += self.bias[j]*self.outputs[self.connections_out[j]] * self.voltage[self.connections_out[j]]
62
- self.temperature[j] += 1
63
- self.voltage[i] += delta_voltage
64
- if self.voltage[i] > self.threeholds[i]:
65
- self.outputs[i] = 1
66
- else:
67
- self.outputs[i] = 0
68
- self.voltage[i] *= self.v_decay
69
- # CALCULAR CAMBIOS EN LAS CONEXIONES Y APLICARLOS
70
- for i in range(self.total_cons):
71
- neuron_in = self.connections_in[i]
72
- neuron_out = self.connections_out[i]
73
- if self.outputs[neuron_in] == 1:
74
- self.bias[i] += self.plasticity[i] * (self.temperature[i])
75
- else:
76
- self.bias[i] -= self.plasticity[i] * self.temperature[i]
77
-
78
- self.bias[i] += self.pr * self.plasticity[i] * self.temperature[i]
79
-
80
- self.temperature[i] *= self.t_decay
File without changes
File without changes
File without changes
File without changes