Commit Graph
197 Commits
Author SHA1 Message Date
jens 0febd4e6b6 Rbm::Train(cd_bb): added do_gibbs_sample_hidden 2026-06-07 17:48:22 +02:00
jens 2d3361d5ce rework forward_step to use char-by-char state priming with SPACE token
Replace space ' ' with explicit SPACE='_' vocab token to disambiguate
padding from real spaces, and rewrite forward_step to take a single
character plus rolling state string instead of a reconstructed vc matrix,
producing predictions one character at a time per unit.
2026-06-07 13:34:02 +02:00
jens 51274ee1ae [jayRnn]
- adjusted params
2026-06-06 12:49:09 +02:00
jens 588f58883f - no "^" in vocabular
- JayRnn: wrong but stable
2026-06-06 12:35:20 +02:00
jensandClaude Sonnet 4.6 a41ddce6a8 scale up model, expand vocab, collect predicted text in forward pass
- Increase H_SIZE to 128, lr to 0.2, disable Rao-Blackwell
- Expand VOCAB to include lowercase and hyphen/period
- Fix batch_delay to always use delay=1 per unit
- forward_step now returns (vc, text) with predicted char per unit step
- Collect and print generated text in main inference loop

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 18:17:41 +02:00
jensandClaude Sonnet 4.6 5ac4608ba8 tune hyperparams and fix forward_step shift, re-enable training
- Switch TEXT to "HALLO MAUSI! SUPER HASE!", H_SIZE to 64, lr to 0.1
- Extract v2char() helper from vc2char()
- Fix shift_left to use vocab_size() step instead of 1
- Re-enable model.train() and model.save() in main
- Clean up dead prediction loop code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 17:47:30 +02:00
jensandClaude Sonnet 4.6 f7ed8563d7 refactor RnnModel: multi-unit delay training and unified vc interface
- Add batch_delay() to shift visible input per unit index
- Unify forward_step() to work with combined vc matrix
- Fix split() to always slice on axis=1
- Add index param to Entity for readable naming
- Rename test_xor.py to xor.py, replace Mat with np.array

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 16:29:36 +02:00
jens b20ea4edb6 fixed wrong number of bits for binary encoding 2026-06-05 11:11:32 +02:00
jensandClaude Sonnet 4.6 49a99dc750 tune label fitter: epochs, momentum, encoding, decode threshold
- reduce num_epochs to 5000 and add momentum=0.9
- switch to OneHot encoding in Label constructor
- call fitter.init(0.1) before load for weight initialisation
- use train_labels as test set, lower hard-decode threshold to 0.5
- improve print output

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 10:03:55 +02:00
jensandClaude Sonnet 4.6 248ae4f199 tune hyperparams, add README, simplify training loop
- reduce WIN to 3 and H_SIZE to 32 for faster iteration
- increase NUM_EPOCHS to 1000 and collapse NUM_ITERATIONS to a single pass
- add README_JayRnn.md with algorithm description and ASCII architecture diagrams

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-05 09:34:33 +02:00
jens b5a128fb61 fixed error for other WIN sizes 2026-06-04 23:19:18 +02:00
jens 06ab8d0166 refactored forward_step 2026-06-04 19:30:58 +02:00
jens 7f6818670e - changed sample text
- changed model params
2026-06-04 16:43:41 +02:00
jens 62dd450c9c increased difficulty 2026-06-04 11:15:17 +02:00
jens 4bd516798a cleaned up 2026-06-04 10:36:50 +02:00
jens bb6680c931 getting Rnn to work 2026-06-04 10:28:19 +02:00
jens 851bad28d3 cleaned up 2026-06-03 23:01:10 +02:00
jens 3a41014d50 improved context update for JayRnn 2026-06-03 22:58:18 +02:00
jens 2701daf1c4 added JayRnn 2026-06-03 22:14:40 +02:00
jens 6a75e0b33b added more Rnn helber 2026-06-03 22:14:34 +02:00
jens 5c3734a2a4 extend model member detection by list[Entity] 2026-06-03 22:13:57 +02:00
jens 27460c503d fixed type alias 2026-06-03 22:13:26 +02:00
jensandClaude Sonnet 4.6 c62605de51 [update] README.rbm.md: add Q&A on image/video and code generation architectures
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 11:15:10 +02:00
jensandClaude Sonnet 4.6 ae81e3e340 [add] README.rbm.md: Q&A on RBMs, VAEs, Transformers, and autodiff
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 11:05:48 +02:00
jensandClaude Sonnet 4.6 df4a9b2ac2 [add] Rnn.py: unrolled character-level RNN-RBM matching docs/Rnn.drawio.png
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 10:49:46 +02:00
jensandClaude Sonnet 4.6 3edc124a5c [refactor] move tests to tests/, add pytest functions and main() entrypoints
- Moved src/tests/ → tests/
- Added test_* functions with assertions to script-style test files
- Added main() to each so IDEs offer it as a separate run target from pytest
- Fixed cupy_test.py: remove spurious x_gpu += x_cpu, fix duplicate xlabel

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 21:32:58 +02:00
jensandClaude Sonnet 4.6 829547d271 [notebook] update cifar notebook outputs and add N_HID constant
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 21:06:41 +02:00
jensandClaude Sonnet 4.6 0b4794de4e [fix] use np.asnumpy in SubImageCombine to support CuPy arrays
_np.asarray() raises TypeError on CuPy arrays; np.asnumpy() handles both.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 20:57:58 +02:00
jensandClaude Sonnet 4.6 1954064a54 [refactor] move rbm.model → model.model
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 08:55:16 +02:00
jensandClaude Sonnet 4.6 b41274c7a6 [refactor] move rbm.torch → compat.torch
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 08:36:21 +02:00
jensandClaude Sonnet 4.6 3d235b4214 [refactor] move rbm.label → label.label
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 08:30:26 +02:00
jensandClaude Sonnet 4.6 807de19fa7 [fix] restore SubImageCombine name in cifar notebook (clobbered by bulk rename)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 08:23:08 +02:00
jensandClaude Sonnet 4.6 a07698497d [refactor] SubImage → SubImageExtract, add SubImageCombine
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 08:20:38 +02:00
jensandClaude Sonnet 4.6 2da2262368 [refactor] move rbm.stack* + rbm.rnn_helper → stack/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 08:10:03 +02:00
jensandClaude Sonnet 4.6 b0d370a56b [refactor] move rbm.image → image.sub_image
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-02 08:01:51 +02:00
jensandClaude Sonnet 4.6 599ba4f6d5 [cifar_sub_image] run with STRIDE=6 (25 patches/image, ~33% overlap)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 20:07:10 +02:00
jensandClaude Sonnet 4.6 dddb937909 [cifar_sub_image] add full 32x32 reconstruction from sub-images with overlap blending
- Add PATCH/STRIDE params; STRIDE=4 for 50% overlap (49 patches per image)
- Reconstruct 32x32 by averaging overlapping patch contributions (assemble_overlapping pattern from test_faces_sub_image)
- All cells updated to use PATCH/STRIDE throughout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 19:59:30 +02:00
jensandClaude Sonnet 4.6 00993e29f1 [rnn_helper] add shift functions, ch2idx/idx2ch, and tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 16:43:33 +02:00
jensandClaude Sonnet 4.6 cce3943b27 [RNN-RBM] rename to RNN-RBM, add unrolled depth-2 mode, update README
- Rename context33.ipynb → RNN-RBM.ipynb
- Add UNROLL_DEPTH parameter (1 = shared weights, N = alternating entities)
- Training loop uses t % n_layers instead of hardcoded t % 2
- README: RNN-RBM section with signal-flow ASCII art, modes table, parameter table, papers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 23:22:00 +02:00
jensandClaude Sonnet 4.6 73ff6c2bb4 [context33] - momentum 0.9, epochs 500
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 20:47:27 +02:00
jensandClaude Sonnet 4.6 4a915f165a [context33] - increase momentum 0.5→0.7; run outputs 99% recon, 88% next-step
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 20:06:20 +02:00
jensandClaude Sonnet 4.6 586803856f [context33] - add batch tiling (N_REPEAT=500) for GPU utilisation
Tile the single sentence 500× to form a (500, T, 40) batch so matrix ops
are (500, 168) instead of (1, 168). Note: with identical rows the gradient
is mathematically equivalent to batch=1; real speedup requires diverse data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 20:03:03 +02:00
jensandClaude Sonnet 4.6 bbc03d37e1 [context33] - 200-char sentence, auto-uppercase, adaptive tick spacing
SENTENCE now accepts mixed case and strips non-vocab chars automatically.
Extended to ~200 chars using the Moby Dick opening passage.
Visualisation cells use adaptive tick spacing (max 40 labels) to handle
longer sequences without crowding.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 16:15:01 +02:00
jensandClaude Sonnet 4.6 0beb7a5c1b [context33] - replace armadillo data with 20-char sentence, moby encoding
Remove context33.training.dat loading (and read_armadillo import).
Training data is now a hardcoded 20-character sentence encoded with the
same 40-char vocabulary as moby_rnn.ipynb (space .!? A-Z 0-9).

  SENTENCE = "MOBY DICK IS A WHALE"

Results: 95% reconstruction, 95% next-step prediction (one miss each
on the first character where context is zero).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 15:35:59 +02:00
jensandClaude Sonnet 4.6 5506fef0fa [context33] - fix row order; sequence now reads 1 5 6 9 … R U X
The training.dat file stores samples LIFO (last added in the C++ GUI = row 0).
Reversing the rows restores chronological order, matching the C++ sequence.

Next-step prediction remains 100%: model predicts x_{t+1} from h_t correctly
in the C++ insertion order 1 5 6 9 B F I L Q R U X.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 15:22:43 +02:00
jensandClaude Sonnet 4.6 2a6b00db88 [context33] - pyRBM port of context33.prj; predict next char from current context
Notebook reconstructs the C++ context33.prj configuration exactly:
  - shared-weights StackRnn (1 entity, reused every time step)
  - visible = [context(128) | x_t(40)] = 168 units, hidden = 128
  - all hyperparams from .prj: lr=0.05, momentum=0.5, epochs=1000,
    mini_batch=100, gibbs=3, rao_blackwell=True, weight_decay=0

Training data loaded directly from context33.training.dat (Armadillo format,
12 × 168): sensory one-hot chars decoded as 'XURQLIFB9651'.

Key design: training pairs are (h_t, x_{t+1}) not (h_{t-1}, x_t) —
context is first advanced by seeing x_t, then the model is trained to
predict the next character x_{t+1} from that context. Evaluation using
clamped Gibbs on h_t achieves 100% next-step prediction accuracy.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 15:12:14 +02:00
jensandClaude Sonnet 4.6 952045b9f1 [StackRnn] - temporal-shift padding, joint training, vocab reduction, TEMPORAL_DEPTH=64
stack_rnn.py:
  - _train_unrolled: C++-style temporal-shift padding — flatten (num_seq, T, s)
    → (N, s), append T-1 zero rows, layer t trains on batch[t:N+t]; joint
    training replaces greedy sequential (all layers update each epoch)
  - Reverted sequential/greedy training path (poor next-step prediction)

moby_rnn.ipynb:
  - Vocabulary reduced 85 → 40 chars (A-Z, 0-9, space, .!?)
  - T renamed to TEMPORAL_DEPTH throughout
  - TEMPORAL_DEPTH increased 5 → 64; CONTEXT_SIZE 128
  - SEED "Call me Ishmael." now falls within training data coverage

state.py:
  - Remove per-file load/save print messages (too noisy with 64-layer checkpoints)

README_moby_rnn.md:
  - Update vocab, constants, parameter count, checkpoint listing
  - Add temporal-shift padding and joint training sections
  - Clarify reconstruction accuracy vs next-step prediction as honest metric

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 14:37:08 +02:00
jensandClaude Sonnet 4.6 3698c85ed4 [StackRnn] - add unrolled (own-weights) mode; each position gets its own RBM
Previously a single shared-weight Entity processed every time step.  Now:
- Shared mode  (1 layer via make_layer):  original behaviour unchanged
- Unrolled mode (N layers via make_unrolled): layers[t] owns W_t, b_v_t, b_h_t

New API:
  make_unrolled(T, sensory_size, h_size, ...)  → list[Layer]
  next_entity()   → Entity for the upcoming step() call
  current_entity() → Entity from the most recent step() call
  is_shared        → bool

moby_rnn.ipynb: switch Build model cell to make_unrolled(T=100); update
  predict_next() to use rnn.next_entity() for position-correct Gibbs sampling
README_moby_rnn.md: redraw temporal-unrolling ASCII art showing per-position
  weights W_t; update parameter count and checkpoint file listing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 11:52:01 +02:00
jensandClaude Sonnet 4.6 0b302a9c12 [moby_rnn] - add README with architecture ASCII art; consolidate constants
- README_moby_rnn.md: single-step and temporally-unrolled ASCII diagrams,
  configuration table, notebook cell guide, generation API docs, references
- moby_rnn.ipynb: move all constants (T, NUM_SEQ, EVAL_CHARS, PRED_CHARS,
  N_GIBBS, SEED, SEQ_IDX) into the Build model cell under a Configuration
  header; rename H_SIZE → CONTEXT_SIZE throughout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 11:42:55 +02:00
jensandClaude Sonnet 4.6 eb1f96f4ec [StackRnn] - add recurrent RBM stack with character-level LM notebook
Implements StackRnn: a cascaded/recurrent RBM where the visible layer at
each time step is the concatenation of the previous hidden state (context)
and the current sensory input — V[t] = [context | x_t].  Weights are
shared across time steps (RTRBM-style concatenation variant).

- stack_rnn.py: StackRnn with step(), reconstruct(), reset(), train(),
  make_layer() factory; supports greedy layer-wise training over sequences
  of shape (num_seq, T, sensory_size)
- test_rnn.py: single-layer, two-layer, and save/load tests
- moby_rnn.ipynb: character-level language model on Moby Dick; one-hot
  encoding, clamped-Gibbs next-char prediction, free text generation,
  hidden-state trace and character-distribution visualisations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 11:27:07 +02:00