neuronet 8.0.251113 → 9.0.251116
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.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/neuronet/backpropagate.rb +24 -2
- data/lib/neuronet/input_neuron.rb +1 -0
- data/lib/neuronet/neuron_stats.rb +3 -2
- data/lib/neuronet/noisy_backpropagate.rb +9 -3
- data/lib/neuronet/trainable.rb +8 -1
- data/lib/neuronet.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8fcd067b50961b58b6b651d90ecf266b12c8af3b25eb4bb991793f29a0db700a
|
|
4
|
+
data.tar.gz: 0a29c998e309ffb0896f9a1e9b0649cf957ac4648aa6c80233455ca76745d4b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 402fd261d78682ea719677878c038efd81d65255f5aafeffcc4a39a9b5f63e28abcf1d10b22cc6a736b4d9a21ced6941d0aaee40a8aaf4db6c0c59d7c4881f6b
|
|
7
|
+
data.tar.gz: 9d600982412e31bbd631d3c47976e8b29c33d324e7b6d04e164401634448dbc484fe43519ab2e8a4a96fe2580fd876636e7a4ae97d12bdf06206fc691cc2270f
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Neuronet
|
|
2
2
|
|
|
3
|
-
* [VERSION
|
|
3
|
+
* [VERSION 9.0.251116](https://github.com/carlosjhr64/neuronet/releases)
|
|
4
4
|
* [github](https://www.github.com/carlosjhr64/neuronet)
|
|
5
5
|
* [rubygems](https://rubygems.org/neuronet)
|
|
6
6
|
|
|
@@ -68,6 +68,9 @@ When reading the library, this is order the order I would read it:
|
|
|
68
68
|
Once you understand these files, the rest should all make sense.
|
|
69
69
|
For some math on neural networks,
|
|
70
70
|
see the [Wiki](https://github.com/carlosjhr64/neuronet/wiki).
|
|
71
|
+
Finally, out of all my testing,
|
|
72
|
+
probably the best demonstration here that Neuronet works is
|
|
73
|
+
[examples/test_logic](examples/test_logic).
|
|
71
74
|
|
|
72
75
|
## LICENSE
|
|
73
76
|
|
|
@@ -6,12 +6,22 @@ module Neuronet
|
|
|
6
6
|
# Back-propagates errors, updating bias and connection weights.
|
|
7
7
|
# Clamps updates to [-max, +max].
|
|
8
8
|
# Recursively calls on connected neurons.
|
|
9
|
-
# rubocop: disable Metrics, Style
|
|
10
9
|
def backpropagate(error)
|
|
10
|
+
return if @backpropagated
|
|
11
|
+
|
|
12
|
+
@backpropagated = true
|
|
13
|
+
update_bias(error)
|
|
14
|
+
update_connections(error)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# rubocop: disable Style/NestedTernaryOperator
|
|
18
|
+
def update_bias(error)
|
|
11
19
|
bmax = Config.bias_clamp
|
|
12
20
|
b = bias + error
|
|
13
21
|
self.bias = b.abs > bmax ? (b.positive? ? bmax : -bmax) : b
|
|
22
|
+
end
|
|
14
23
|
|
|
24
|
+
def update_connections(error)
|
|
15
25
|
wmax = Config.weight_clamp
|
|
16
26
|
connections.each do |c|
|
|
17
27
|
n = c.neuron
|
|
@@ -20,6 +30,18 @@ module Neuronet
|
|
|
20
30
|
n.backpropagate(error)
|
|
21
31
|
end
|
|
22
32
|
end
|
|
23
|
-
# rubocop: enable
|
|
33
|
+
# rubocop: enable Style/NestedTernaryOperator
|
|
34
|
+
|
|
35
|
+
def reset_backpropagated!
|
|
36
|
+
return unless @backpropagated
|
|
37
|
+
|
|
38
|
+
@backpropagated = false
|
|
39
|
+
connections.each { |c| c.neuron.reset_backpropagated! }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def backpropagate!(error)
|
|
43
|
+
reset_backpropagated!
|
|
44
|
+
backpropagate(error)
|
|
45
|
+
end
|
|
24
46
|
end
|
|
25
47
|
end
|
|
@@ -15,12 +15,13 @@ module Neuronet
|
|
|
15
15
|
def downstream_params_tally
|
|
16
16
|
return 0 if (size = connections.size).zero?
|
|
17
17
|
|
|
18
|
+
# Note that this is an Integer calculation:
|
|
18
19
|
1 + size + connections.sum { it.neuron.downstream_params_tally }
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
# Sum of activations + 1. It's a component of the sensitivity measure nju.
|
|
22
23
|
# See [wiki](https://github.com/carlosjhr64/neuronet/wiki)
|
|
23
|
-
def mju = 1 + connections.sum { it.neuron.activation }
|
|
24
|
+
def mju = 1.0 + connections.sum { it.neuron.activation }
|
|
24
25
|
|
|
25
26
|
# Sensitivity measure nju:
|
|
26
27
|
# 𝒆 ~ 𝜀𝝁 + 𝑾 𝓑𝒂'𝒆'
|
|
@@ -31,7 +32,7 @@ module Neuronet
|
|
|
31
32
|
# https://github.com/carlosjhr64/neuronet/blob/master/test/tc_epsilon
|
|
32
33
|
# rubocop: disable Metrics
|
|
33
34
|
def nju
|
|
34
|
-
return 0 if connections.empty?
|
|
35
|
+
return 0.0 if connections.empty?
|
|
35
36
|
|
|
36
37
|
mju + connections.sum do |connection|
|
|
37
38
|
n = connection.neuron
|
|
@@ -3,12 +3,17 @@
|
|
|
3
3
|
module Neuronet
|
|
4
4
|
# Noisy Backpropagate
|
|
5
5
|
module NoisyBackpropagate
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
include Backpropagate
|
|
7
|
+
|
|
8
|
+
# rubocop: disable Style/NestedTernaryOperator
|
|
9
|
+
def update_bias(error)
|
|
8
10
|
bmax = Config.bias_clamp
|
|
9
11
|
b = bias + (error * (rand + rand))
|
|
10
12
|
self.bias = b.abs > bmax ? (b.positive? ? bmax : -bmax) : b
|
|
13
|
+
end
|
|
11
14
|
|
|
15
|
+
# rubocop: disable Metrics/AbcSize
|
|
16
|
+
def update_connections(error)
|
|
12
17
|
wmax = Config.weight_clamp
|
|
13
18
|
connections.each do |c|
|
|
14
19
|
n = c.neuron
|
|
@@ -17,6 +22,7 @@ module Neuronet
|
|
|
17
22
|
n.backpropagate(error)
|
|
18
23
|
end
|
|
19
24
|
end
|
|
20
|
-
# rubocop: enable Metrics
|
|
25
|
+
# rubocop: enable Metrics/AbcSize
|
|
26
|
+
# rubocop: enable Style/NestedTernaryOperator
|
|
21
27
|
end
|
|
22
28
|
end
|
data/lib/neuronet/trainable.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Neuronet
|
|
|
12
12
|
errors = targets.zip(actuals).map { |target, actual| target - actual }
|
|
13
13
|
error, index = pivot(errors)
|
|
14
14
|
neuron = output_layer[index]
|
|
15
|
-
neuron.backpropagate(error / nju)
|
|
15
|
+
neuron.backpropagate!(error / nju)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def pivot(errors)
|
|
@@ -25,5 +25,12 @@ module Neuronet
|
|
|
25
25
|
end
|
|
26
26
|
[error, index]
|
|
27
27
|
end
|
|
28
|
+
|
|
29
|
+
def sum_of_squared_errors(pairs)
|
|
30
|
+
pairs.sum do |inputs, targets|
|
|
31
|
+
actuals = self * inputs
|
|
32
|
+
targets.zip(actuals).sum { |t, a| (e = t - a) * e }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
28
35
|
end
|
|
29
36
|
end
|
data/lib/neuronet.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: neuronet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 9.0.251116
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- CarlosJHR64
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-11-
|
|
10
|
+
date: 2025-11-18 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: |
|
|
13
13
|
Library to create neural networks.
|