Commit Graph
100 Commits
Author SHA1 Message Date
jensandClaude Sonnet 4.6 68b376657c [faces_sub_image] - add --mini_batch_size CLI arg
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 21:13:25 +02:00
jensandClaude Sonnet 4.6 9911caae06 [README] - document cd_jens removal, dbv simplification, Gibbs sampling fix
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 20:55:00 +02:00
jensandClaude Sonnet 4.6 b5104ebc97 [bugfix] - remove dead cd_jens; fix cd_gaussian_binary dbv; fix cd_binary_gaussian Gibbs sampling
- Remove cd_jens: dead code never called, contained multiple bugs.
- cd_gaussian_binary: dbv formula simplified — b_v terms cancelled between
  positive and negative phases, making the subtraction redundant.
- cd_binary_gaussian: Gibbs loop (CD-k > 1) now properly samples both visible
  (sample(prob(...))) and hidden (+ sample_gaussian) states when
  do_rao_blackwell=False. Previously used means throughout, giving biased
  gradient estimates for k > 1.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 20:54:09 +02:00
jensandClaude Sonnet 4.6 a6bfdf8eaf [README] - document train() shuffling and elif fixes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 20:44:13 +02:00
jensandClaude Sonnet 4.6 003152518a [bugfix] - shuffle data each epoch; replace if chains with elif/else in train()
Shuffling eliminates systematic gradient bias from fixed mini-batch ordering.
elif/else raises ValueError for unrecognised entity types instead of silently
calling None and crashing with a cryptic TypeError.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 20:43:42 +02:00
jensandClaude Sonnet 4.6 96f271f160 [faces_sub_image] - add --num_epochs CLI arg
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 20:38:33 +02:00
jensandClaude Sonnet 4.6 edeeb1773b [README] - update faces_sub_image entry; bump N_HID to 256
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 20:18:46 +02:00
jensandClaude Sonnet 4.6 1d18983192 [README] - document L1/L2 batch-size scaling fix
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 19:59:34 +02:00
jensandClaude Sonnet 4.6 d4d3d33931 [bugfix] - fix L1/L2 scaling: move regularisation out of grad_compute into state_adjust
Regularisation terms (L1, L2, weight_decay) were being divided by mini_batch_size
in state_adjust along with the CD gradient. The CD gradient is a batch sum so
1/N normalisation is correct; regularisation penalties are per-weight and
batch-size independent. Separating them makes l1_lambda/l2_lambda directly
interpretable regardless of batch size.

Also adds --l1_lambda CLI arg to test_faces_sub_image.py and sets num_epochs=1000.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 19:58:44 +02:00
jensandClaude Sonnet 4.6 95b114003e [README] - document entity.py L1/L2 and image.py normalize fixes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 18:28:45 +02:00
jensandClaude Sonnet 4.6 abee870ada [bugfix] - fix L1 and L2 regularisation gradients in grad_compute
Previous code computed scalar norms and multiplied by W, giving gradients
that scaled with total weight magnitude rather than the correct per-element
derivatives:
  L1: gradient is λ·sign(W), not λ·‖W‖₁·W
  L2: gradient is 2λ·W, not λ·‖W‖₂²·W
Also removed the combined (l1+l2)*W term which incorrectly mixed the two.
weight_decay (correct L2 form λW) is kept as a separate term.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 18:26:06 +02:00
jensandClaude Sonnet 4.6 e0dcac5c82 [normalize] - simplify and harden normalize(); remove duplicate in load_image_patches
image.py: replace repeat/reshape with keepdims=True; guard std < 1e-8 to
prevent NaN on constant patches (previously relied on call-site pre-filtering).
test_faces_sub_image.py: load_image_patches now calls normalize() directly
instead of duplicating the per-sample normalization logic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 18:22:19 +02:00
jensandClaude Sonnet 4.6 07fc7dc607 [faces_sub_image] - add --grayscale CLI flag for single-channel mode
GRAYSCALE flag drives N_CH (1 or 3) and N_VIS (1024 or 3072) at runtime.
_img_to_chw() handles BGR→gray or BGR→RGB conversion.
All visualisation functions use cmap='gray' when GRAYSCALE is set.
Separate model name (faces_sub_image_gray) keeps weights isolated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 16:07:08 +02:00
jensandClaude Sonnet 4.6 fc10fab627 [faces_sub_image] - add overlap patch extraction and boundary blending reconstruction
Replace non-overlapping stride=32 with stride=16 (50% overlap) throughout.
Add assemble_overlapping() which accumulates reconstructed patches into a
float buffer and averages contributions per pixel, eliminating blocking artefacts.
Update load_image_patches to return nx_steps/ny_steps for correct reassembly.
Add start parameter to load_patches for held-out test image selection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 15:33:49 +02:00
jensandClaude Sonnet 4.6 feaf96417a [faces_sub_image] - add --load_model and --do_train CLI args
Reconstruction always runs. Default: load saved weights, skip training.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 15:25:22 +02:00
jensandClaude Sonnet 4.6 56f881d155 [README] - add faces_sub_image test entry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 15:21:46 +02:00
jensandClaude Sonnet 4.6 441354088f [faces_sub_image] - add GB-RBM autoencoder test on Caltech WebFaces using SubImage ROIs
Extracts non-overlapping 32x32 RGB patches from face images using SubImage,
trains a GB-RBM (3072 visible, 128 hidden), and visualises learned filters,
patch reconstructions, and full image reconstruction.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 15:20:21 +02:00
jensandClaude Sonnet 4.6 7bbacc729b [README] - document all bug fixes in implementation notes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 14:47:23 +02:00
jensandClaude Sonnet 4.6 7d48f835a6 [bugfix] - fix momentum reset, cd_gaussian_gaussian noise, rms_error, label CuPy compat
- train.py: grad_zero() was called inside the epoch loop, resetting momentum
  to zero before every update — momentum had no effect in the default full-batch
  case. Moved outside the loop so momentum accumulates across epochs.
- train.py: cd_gaussian_gaussian: use mean h for weight updates and sampled h
  to drive the negative visible reconstruction (same pattern as cd_gaussian_binary fix).
  Remove spurious Gaussian noise added to data_neg before computing h_probs_neg.
- matrix.py: rms_error divided by d_err_squared[1] (row 1) instead of
  d_err_squared.shape[1] (column count).
- label.py: _dec_binary used reversed() on a CuPy array — replaced with np.flip().
  label2vec_onehot now returns np.stack() array instead of a Python list.
  vec2label_onehot implemented via np.argmax (was returning None).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 14:46:45 +02:00
jensandClaude Sonnet 4.6 f0e98eb714 [README] - document cd_gaussian_binary bug fixes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 14:37:27 +02:00
jensandClaude Sonnet 4.6 07e430f109 [cd_gaussian_binary] - fix negative phase: remove spurious noise, sample hidden states
In cd_gaussian_binary, two CD formulation bugs:
1. Gaussian noise was incorrectly added to data_neg before computing h_probs_neg
2. Negative visible reconstruction used h_probs_pos (soft probabilities) instead
   of sampled binary hidden states, biasing the fantasy particle toward the mean

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 14:36:18 +02:00
jensandClaude Sonnet 4.6 3c85705d85 [README] - add gaussian_autoencoder test entry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 14:29:25 +02:00
jensandClaude Sonnet 4.6 b032db3099 [gaussian_autoencoder] - add GB-RBM autoencoder test with Gaussian blob data
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 14:28:57 +02:00
jensandClaude Sonnet 4.6 86d39813cd [binary_autoencoder] - add BB-RBM autoencoder test and tests README
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 14:24:49 +02:00
jensandClaude Sonnet 4.6 95be9dd632 [conv2d] - add 2D convolution function and test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 10:11:11 +02:00
jens 759f4b5348 updated notebooks 2026-01-11 11:23:35 +01:00
jens 92afc16137 [SubImage]
- handle different image shapes
2026-01-11 11:21:42 +01:00
jens 3f4cdc277f updated notebooks 2026-01-10 22:19:52 +01:00
jens 51a06605dd [cifar_test_sub_image]
- use L1-regulation
2026-01-10 22:18:45 +01:00
jens 7220d41e02 [cifar-test]
- found good L1-regulation parameter for sparse weights
2026-01-10 21:44:03 +01:00
jens 432a596092 [mnist-test]
- found good L1-regulation parameter for sparse weights
2026-01-10 19:58:39 +01:00
jens be64b0f8ce refactored 2026-01-10 16:46:27 +01:00
jens 1722a68b2a [entity]
- refactored training parameters for grad_compute()
- added l1-norm
- improved tests
2026-01-10 15:21:40 +01:00
jens 00fe5fd178 updated notebooks 2026-01-10 14:13:18 +01:00
jens f7e3693f45 - added image module with sub image and normalize
- improved tests
2026-01-10 14:12:29 +01:00
jens b6a511e33c improved tests 2026-01-10 10:24:50 +01:00
jens f1aae9b0f1 [train]
- reset grad at start of epoch
[state]
- init(): set default parameter mu=0
2026-01-10 10:19:30 +01:00
jens 381ec8d0e3 improved tests 2026-01-09 15:28:53 +01:00
jens 4c939cab8b cd_gaussian_binary: no sampling of training data 2026-01-09 15:28:06 +01:00
jens 074ded1581 improved tests 2026-01-06 21:51:28 +01:00
jens 9025f54434 simplified EntityParams.from_dict 2026-01-06 21:49:35 +01:00
jens e7b287e632 - simplified TrainingParams.from_dict
- fixed test_rbm
2026-01-06 21:48:09 +01:00
jens 226453c7ae fixed status indention 2026-01-06 21:06:11 +01:00
jens c879ff583b updated notebooks 2026-01-06 20:21:01 +01:00
jens 186fd423b9 updated notebooks 2026-01-06 20:20:43 +01:00
jens 7d3ab02e26 fixed dividing l2-norm by length of vector 2026-01-06 18:17:45 +01:00
jens 542b8ae9b0 added L2-Regulation 2026-01-06 18:00:26 +01:00
jens ff6254a15d - Status has entity paarmeter
- train provides entity parameter to Status
2026-01-06 11:29:47 +01:00
jens 42520e5761 improved tests 2026-01-06 09:44:45 +01:00
jens ec5d259ff7 Entity: added property enable training 2026-01-06 09:44:29 +01:00
jens b1fe7229fa updated cifar_test 2026-01-05 21:46:33 +01:00
jens b6a3779bf9 updated cifar_test and mnist_test 2026-01-05 21:39:22 +01:00
jens 74138b5514 train: swapped epochs and mini-batch loop 2026-01-05 20:53:31 +01:00
jens 562e9e9bda added mnist_test 2026-01-05 19:42:01 +01:00
jens ae6ab9b9b5 updated cifar_test 2026-01-05 19:41:43 +01:00
jens d238d2954e grad_compute(): pre-multiply weight decay with learning rate 2026-01-05 19:40:05 +01:00
jens 10999ec731 updated notebook 2026-01-05 18:08:22 +01:00
jens 2fd55ee69c updated notebook 2026-01-05 14:49:03 +01:00
jens fdf4186d6b significantly improved GB-RBM training 2026-01-05 14:16:34 +01:00
jens 9f72c1f253 - added cifar_test as jupiter lab
- started torch version of RBM
- enable CUDA in matrix
2026-01-04 18:30:01 +01:00
jens 73d4486fb7 test_norbs: added mode hidden gaussian - hidden binary 2026-01-04 16:06:41 +01:00
jens 6546c37657 train: fixed gaussian sampling 2026-01-03 19:30:47 +01:00
jens e6c959d890 - fixed test_xor
- added test_linear
2026-01-03 13:07:08 +01:00
jens e56f99535a improved tests 2026-01-03 12:51:43 +01:00
jens 529252166a train: sample gaussian visible units 2026-01-03 12:40:08 +01:00
jens 63bfd3ed80 updated 2026-01-03 12:11:04 +01:00
jens f828c26f36 refactored 2026-01-03 12:10:53 +01:00
jens 94595ddd8a train: added cd_binary_gaussian 2026-01-03 12:10:17 +01:00
jens fa9f595be6 use gray color map 2026-01-02 22:50:03 +01:00
jens 082bb3c566 Label: added OneHote encoding 2026-01-02 22:49:00 +01:00
jens 2e714685d1 model: forward() is not abstract method 2026-01-02 19:42:22 +01:00
jens c87b8f8ed0 fixed 2026-01-02 19:41:26 +01:00
jens 48f3642e44 fixed TrainingParams 2026-01-02 18:36:17 +01:00
jens c7f820ec63 - adapted test to TrainingParameter as parat of Entity
- learn_norbs_labes start working
2026-01-02 14:53:45 +01:00
jens 10691894d1 - training params are (again) attrubute of Entity
- ditched layout concept
2026-01-02 14:51:19 +01:00
jens 8b97350564 cd_binary_binary: added gibbs sampling 2026-01-01 20:02:22 +01:00
jens e67207504b fixed cd_binary_binary 2026-01-01 15:55:35 +01:00
jens dc998d30a2 - initroduced types: BB-RBM GB-RBM, GG-RBM as property of entity
- training simplification and for clarity: added specialized cd_funcs for each entity type
2026-01-01 12:05:39 +01:00
jens 38b834c640 - added training params as list for model.train()
- added gaussian sample
- introduced layout concept
- updated README
2025-12-31 16:13:59 +01:00
jens 9b41dd6c02 added LabelLearner 2025-12-22 11:14:44 +01:00
jens 35e045a701 added label 2025-12-22 10:02:36 +01:00
jens 781870b971 add label encoder/decoder (not finished) 2025-12-21 20:20:24 +01:00
jens 362970574f refactored 2025-12-21 19:34:23 +01:00
jens ff05c729e8 - refactored read_armadillo into matrix
- added test_norbs
2025-12-21 18:16:48 +01:00
jens e11f775aff Test model: removed unecessary import 2025-12-21 17:46:04 +01:00
jens b29937c149 Test model: improved output log 2025-12-21 17:45:10 +01:00
jens 4bd5cffd6b - state load/save revised
- num gibbs samples is also part of entity
- working 3-layer deep test model
2025-12-21 17:34:11 +01:00
jens 22d189cf2f added model 2025-12-21 16:39:53 +01:00
jens 7668c73ea4 refactored 2025-12-21 10:33:04 +01:00
jens 8ed6488b45 refactored train 2025-12-21 10:16:08 +01:00
jens 7f4505c1f8 Raise exception if doSampleBatch == True 2025-12-20 20:21:42 +01:00
jens 61c762150c - removed Optimizer
- refactored training
- use static seed for random (for better comparison)
- simplified StackDeep.train
2025-12-20 20:12:19 +01:00
jens 5f5c7c6d77 Optimizer.train() shall ignore param.do_batch_sample 2025-12-19 17:29:32 +01:00
jens d3c9fe4681 - numGibbs no longer part of EntityParameter
- refactored forward and reconstruct
- conditionally use optimizer for training
2025-12-19 17:15:10 +01:00
jens a47922cb1c refactored 2025-12-19 15:20:04 +01:00
jens a293fc31a0 added layertest notebook 2025-12-19 12:25:17 +01:00
jens a9e67da43a refactored 2025-12-19 11:55:29 +01:00
jens 13a7cff094 layer: refactored xor() into test_xor.py 2025-12-19 11:39:55 +01:00
jens ed8274cc8b updated gitignore 2025-12-19 11:11:00 +01:00
jens cadbb34d1a fixed imports 2025-12-19 11:10:16 +01:00