Skip to content

Commit 74def15

Browse files
author
Alexander Ororbia
committed
minor revisions/polish
1 parent 6281f1a commit 74def15

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

docs/museum/harmonium.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where $Z$ is the normalizing constant (or, in statistical mechanics, the <i>part
6060
When one works through the derivation of the gradient of the log probability $\log p(\mathbf{x})$ with respect to the synapses such as $\mathbf{W}$, they get a (contrastive) Hebbian-like update rule as follows:
6161

6262
$$
63-
\Delta \mathbf{W} = <\mathbf{z}^0_i \mathbf{z}^1_j>_{data} - <\mathbf{z}^0_i \mathbf{z}^1_j>_{model}
63+
\Delta \mathbf{W}_{ij} = <\mathbf{z}^0_i \mathbf{z}^1_j>_{data} - <\mathbf{z}^0_i \mathbf{z}^1_j>_{model}
6464
$$
6565

6666
where the angle brackets $< >$ tell us that we need to take the expectation of the values within the brackets under a certain distribution (such as the data distribution denoted by the subscript $data$). The above rule can also be considered to be a stochastic form of a general recipe known as contrastive Hebbian learning (CHL) [4].
@@ -170,31 +170,31 @@ which will fit/adapt your harmonium to MNIST. This should produce per-training i
170170
W1: min -0.0494 ; max 0.0445 mu -0.0000 ; norm 4.4734
171171
b1: min -4.0000 ; max -4.0000 mu -4.0000 ; norm 64.0000
172172
c0: min -11.6114 ; max 0.0635 mu -3.8398 ; norm 135.2238
173-
-1| Test: E(X) = 99.8526 err(X) = 54.3889
174-
0| Test: E(X) = 116.6596 err(X) = 46.8236; Train: E(X) = 112.0452 err(X) = 52.7418
175-
1| Test: E(X) = 89.5413 err(X) = 36.8690; Train: E(X) = 102.4642 err(X) = 41.3630
176-
2| Test: E(X) = 75.7558 err(X) = 31.8582; Train: E(X) = 82.9692 err(X) = 34.5511
177-
3| Test: E(X) = 66.6632 err(X) = 28.6253; Train: E(X) = 72.1229 err(X) = 30.4615
178-
4| Test: E(X) = 60.8256 err(X) = 26.2317; Train: E(X) = 64.3613 err(X) = 27.6882
179-
5| Test: E(X) = 55.5070 err(X) = 24.3207; Train: E(X) = 58.9254 err(X) = 25.5485
180-
6| Test: E(X) = 51.7455 err(X) = 22.8012; Train: E(X) = 54.4092 err(X) = 23.8361
181-
7| Test: E(X) = 49.4866 err(X) = 21.6163; Train: E(X) = 51.1574 err(X) = 22.4523
182-
8| Test: E(X) = 46.2826 err(X) = 20.5934; Train: E(X) = 48.2617 err(X) = 21.3355
183-
9| Test: E(X) = 43.8611 err(X) = 19.7679; Train: E(X) = 46.0239 err(X) = 20.4297
184-
10| Test: E(X) = 42.2886 err(X) = 19.0672; Train: E(X) = 44.3544 err(X) = 19.6835
185-
11| Test: E(X) = 41.7468 err(X) = 18.4881; Train: E(X) = 42.9321 err(X) = 19.0372
173+
-1| Test: err(X) = 54.3889
174+
0| Test: |d.E(X)| = 16.8070 err(X) = 46.8236; Train: err(X) = 52.7418
175+
1| Test: |d.E(X)| = 27.1183 err(X) = 36.8690; Train: err(X) = 41.3630
176+
2| Test: |d.E(X)| = 13.7855 err(X) = 31.8582; Train: err(X) = 34.5511
177+
3| Test: |d.E(X)| = 9.0927 err(X) = 28.6253; Train: err(X) = 30.4615
178+
4| Test: |d.E(X)| = 5.8375 err(X) = 26.2317; Train: err(X) = 27.6882
179+
5| Test: |d.E(X)| = 5.3187 err(X) = 24.3207; Train: err(X) = 25.5485
180+
6| Test: |d.E(X)| = 3.7614 err(X) = 22.8012; Train: err(X) = 23.8361
181+
7| Test: |d.E(X)| = 2.2589 err(X) = 21.6163; Train: err(X) = 22.4523
182+
8| Test: |d.E(X)| = 3.2040 err(X) = 20.5934; Train: err(X) = 21.3355
183+
9| Test: |d.E(X)| = 2.4215 err(X) = 19.7679; Train: err(X) = 20.4297
184+
10| Test: |d.E(X)| = 1.5725 err(X) = 19.0672; Train: err(X) = 19.6835
185+
11| Test: |d.E(X)| = 0.5418 err(X) = 18.4881; Train: err(X) = 19.0372
186186
...
187187
<shortened for brevity>
188188
...
189-
91| Test: E(X) = 65.5179 err(X) = 11.0443; Train: E(X) = 65.0850 err(X) = 10.9832
190-
92| Test: E(X) = 65.4790 err(X) = 11.0118; Train: E(X) = 64.8345 err(X) = 10.9820
191-
93| Test: E(X) = 65.9917 err(X) = 11.0013; Train: E(X) = 64.4392 err(X) = 10.9586
192-
94| Test: E(X) = 64.0737 err(X) = 10.9874; Train: E(X) = 64.2096 err(X) = 10.9312
193-
95| Test: E(X) = 64.0479 err(X) = 10.9906; Train: E(X) = 63.8461 err(X) = 10.9274
194-
96| Test: E(X) = 63.5719 err(X) = 10.9712; Train: E(X) = 63.3354 err(X) = 10.8940
195-
97| Test: E(X) = 64.1757 err(X) = 10.9589; Train: E(X) = 62.8447 err(X) = 10.8960
196-
98| Test: E(X) = 63.8886 err(X) = 10.9563; Train: E(X) = 62.6391 err(X) = 10.8727
197-
99| Test: E(X) = 62.2265 err(X) = 10.9347; Train: E(X) = 62.3147 err(X) = 10.8671
189+
91| Test: |d.E(X)| = 0.4870 err(X) = 11.0443; Train: err(X) = 10.9832
190+
92| Test: |d.E(X)| = 0.0390 err(X) = 11.0118; Train: err(X) = 10.9820
191+
93| Test: |d.E(X)| = 0.5127 err(X) = 11.0013; Train: err(X) = 10.9586
192+
94| Test: |d.E(X)| = 1.9180 err(X) = 10.9874; Train: err(X) = 10.9312
193+
95| Test: |d.E(X)| = 0.0258 err(X) = 10.9906; Train: err(X) = 10.9274
194+
96| Test: |d.E(X)| = 0.4760 err(X) = 10.9712; Train: err(X) = 10.8940
195+
97| Test: |d.E(X)| = 0.6038 err(X) = 10.9589; Train: err(X) = 10.8960
196+
98| Test: |d.E(X)| = 0.2870 err(X) = 10.9563; Train: err(X) = 10.8727
197+
99| Test: |d.E(X)| = 1.6622 err(X) = 10.9347; Train: err(X) = 10.8671
198198
--- Final RBM Synaptic Stats ---
199199
W1: min -1.8648 ; max 1.3757 mu -0.0012 ; norm 70.6230
200200
b1: min -7.5815 ; max 0.2337 mu -2.3395 ; norm 53.3993

ngclearn/components/synapses/denseSynapse.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def __init__(
4444
super().__init__(name, **kwargs)
4545

4646
self.batch_size = batch_size
47-
self.weight_init = weight_init
48-
self.bias_init = bias_init
4947

5048
## Synapse meta-parameters
5149
self.shape = shape
@@ -54,13 +52,11 @@ def __init__(
5452
## Set up synaptic weight values
5553
tmp_key, *subkeys = random.split(self.key.get(), 4)
5654

57-
if self.weight_init is None:
55+
if weight_init is None:
5856
info(self.name, "is using default weight initializer!")
5957
# self.weight_init = {"dist": "uniform", "amin": 0.025, "amax": 0.8}
60-
# weights = initialize_params(subkeys[0], self.weight_init, shape)
61-
self.weight_init = DistributionGenerator.uniform(0.025, 0.8)
62-
#weights = initialize_params(subkeys[0], self.weight_init, shape)
63-
weights = self.weight_init(shape, subkeys[0])
58+
weight_init = DistributionGenerator.uniform(0.025, 0.8)
59+
weights = weight_init(shape, subkeys[0])
6460

6561
if 0. < p_conn < 1.: ## Modifier/constraint: only non-zero and <1 probs allowed
6662
p_mask = random.bernoulli(subkeys[1], p=p_conn, shape=shape)
@@ -74,12 +70,12 @@ def __init__(
7470
self.outputs = Compartment(postVals)
7571
self.weights = Compartment(weights)
7672
## Set up (optional) bias values
77-
if self.bias_init is None:
73+
if bias_init is None:
7874
info(self.name, "is using default bias value of zero (no bias kernel provided)!")
79-
self.biases = Compartment(self.bias_init((1, shape[1]), subkeys[2]) if bias_init else 0.0)
80-
# self.biases = Compartment(initialize_params(subkeys[2], bias_init,
81-
# (1, shape[1]))
82-
# if bias_init else 0.0)
75+
self.biases = Compartment(bias_init((1, shape[1]), subkeys[2]) if bias_init else 0.0)
76+
## pin weight/bias initializers to component
77+
self.weight_init = weight_init
78+
self.bias_init = bias_init
8379

8480
@compilable
8581
def advance_state(self):

0 commit comments

Comments
 (0)