================================================================================
        Concrete Strength × Sorami V6  Experiments Summary & Architecture Notes
        (English)
        Main experiment group: B / Main controls: A and FixedGELU / Ablation: C
================================================================================
Subject : ConcreteStrengthSoramiV6TransformerSearch.py and its four experiment groups
Dataset : Concrete Strength (concrete compressive strength, regression)
Protocol: repro_v2 (unified data split + a shared set of random seeds; validation-only
          model selection; the test set is used exactly once)
Status  : all four groups (A / B / C / FixedGELU) finished 16 search trials + 8 seed repeats
Note    : This document states only verifiable experimental facts and makes no claim
          beyond the data.

--------------------------------------------------------------------------------
Table of Contents
--------------------------------------------------------------------------------
Ch. 1   One-sentence conclusion
Ch. 2   Background and motivation
Ch. 3   Architecture (the innovative part)
Ch. 4   Experiment groups and their roles
Ch. 5   Experimental protocol (reproducible setup)
Ch. 6   Search results (Optuna phase)
Ch. 7   Final evaluation results (val and test distributions)
Ch. 8   Paired comparisons and significance
Ch. 9   Parameter-count comparison
Ch. 10  Conclusions and honest assessment
Ch. 11  Limitations and follow-up
Ch. 12  Appendix: scripts and artifacts
================================================================================

================================================================================
Ch. 1   One-sentence conclusion
================================================================================
On Concrete Strength, the new architecture (B: a shared generator + learnable per-neuron
identity embedding) is the best-performing of the four groups: it leads on test-MSE mean,
median, best case, and average rank; its improvement over the original Sorami (A) is
statistically significant (paired t≈2.76, p≈0.03). However, B is only "tends to be better"
than the classical FixedGELU, not statistically significant (mean lower by 1.79, paired
p≈0.57). The ablation group C (explicit structural coordinates) is on par with FixedGELU,
but is the most stable in the worst case.

================================================================================
Ch. 2   Background and motivation
================================================================================
Sorami builds an adaptive activation function from a Bézier curve: the two endpoints of each
curve are fixed, while the ordinates of the 7 middle control points can be adjusted
dynamically; they are currently produced by a bias_mlp from the main network's input. V6
changes ONLY "how the control-point offsets are generated", in order to:
  (1) replace the "emit all neurons' offsets at once with dedicated weights" scheme by one in
      which all neurons share a single generator that is told apart by identity information;
  (2) provide the neuron identity in one of two ways: a learnable identity embedding (B) or
      explicit structural coordinates (C);
  (3) compare, on an equal footing, against the original implementation (A) and the classical
      FixedGELU.
Note: the Bézier math of Sorami is unchanged, and no CNN/GNN or elaborate coordinate encoding
is introduced.

================================================================================
Ch. 3   Architecture (the innovative part)
================================================================================
3.1 Main-network backbone (shared by all four groups, unchanged)
  TransformerEncoder(3 layers, d_model=64, 4 heads, d_ff=256, RoPE, Pre-Norm)
    -> mean pooling -> (N, 64) -> regression head (the main MLP) -> scalar output.

3.2 The Bézier adaptive-activation base (shared by all four groups, unchanged)
  - 9 control points (degree-8 Bernstein polynomial); the base shape is obtained by fitting a
    curve to GELU;
  - the two endpoint y-values are pinned to GELU(±5); only the 7 middle control-point
    ordinates are adjustable;
  - domain [-5, 5]; outside the domain it falls back directly to GELU;
  - parametric Bézier + differentiable Newton iteration to invert x->t (ensuring exact
    equality with the GELU curve at zero offset);
  - control-point adjustment: Y = Y_base + bias_scale * b, where bias_scale is a learnable
    temperature (initial value 0) and b is the 7-dim offset produced by the generator;
  - soft start: tiny-variance init on the generator's two layers + bias_scale = 0 -> at init
    the activation equals the GELU base exactly, matching the FixedGELU starting point.

3.3 The three control-point generators (the only difference)

  A (original implementation, one of the main controls)
    bias_mlp: Linear(64,16) -> GELU -> Dropout -> Linear(16, M*7); emits all neurons' offsets
    at once. Neuron identity is "implicitly" encoded in the output-channel positions (each
    neuron gets its own segment of dedicated weights). Generator parameters grow linearly in M.

  B (main experimental group: shared generator + learnable per-neuron identity)
    neuron_embedding: nn.Embedding(M, 8) (trainable);
    generator: Linear(72,16) -> GELU -> Dropout -> Linear(16,7);
    input q = [x_n ‖ e_j], where x_n is the main-MLP input representation (the 64-dim mean-
    pooled vector) and e_j is the j-th neuron's embedding (8-dim).
    All neurons share the same generator; identity is distinguished via the embedding; the
    embedding is updated by backprop from the main task loss. Generator parameters are fixed
    at 1287, plus M×8 embedding parameters.

  C (ablation: shared generator + explicit structural coordinates)
    generator: Linear(68,16) -> GELU -> Dropout -> Linear(16,7);
    input q = [x_n ‖ l, L, j, n_l]; the four structural features are raw integers, not
    normalized. The identity is not learnable. Generator parameters are fixed at 1223.
    Ablation meaning: this model has only one activation-generating hidden layer, so l, L, and
    n_l are all constants and only j carries information; hence C actually tests only the
    capability of "shared generator + extremely weak identity information".

  Common to all three: the control points are generated from the input representation x
  before the activation is evaluated (z = linear1(x)), avoiding any circular dependency.

  Architecture sketch (B shown as the example):
    x (N,64) ─┬─> linear1 ─> z (N,M) ─────────────> Bézier(z; Y) ─> linear2 ─> output
              │
              └─> [x ‖ e_j] (N,M,72) ─> shared generator ─> b (N,M,7) ─┐
                                                                      ×bias_scale
              Y = Y_base + bias_scale * b  ───────────────────────────┘

--------------------------------------------------------------------------------
3.4 How the neuron embedding is produced (group B)
--------------------------------------------------------------------------------
The embedding in group B is not "computed" — it is a trainable lookup table: each neuron is
given a free vector that is learned by backprop from the main task loss. Its lifecycle
(matching the current code) is:

(1) Creation and initialization (SoramiFFN.__init__, mode 'B')
      self.neuron_embedding = nn.Embedding(d_hidden, embedding_dim)   # E: (M, 8)
      self.register_buffer('neuron_idx', torch.arange(d_hidden, dtype=torch.long))
    - Shape: E ∈ R^(M×8), M = d_hidden (number of target neurons), 8 = embedding_dim.
    - Initialization: PyTorch default N(0,1) (random small vectors).
    - It is an nn.Parameter: registered as a model parameter, stored in state_dict, handed to
      the optimizer.
    - M is given dynamically by the actual structure (best M for group B on Concrete = 16, so
      the table is (16,8) = 128 parameters).

(2) Lookup (each forward pass)
      e = self.neuron_embedding(self.neuron_idx)        # (M, 8), i.e. e_j = E[j]
    neuron_idx = [0..M-1] retrieves all M neurons' identity vectors at once; the j-th neuron
    gets the j-th row.

(3) Broadcast to the batch (a neuron reuses the same identity vector across all samples)
      e_b = e.unsqueeze(0).expand(batch, M, 8)          # (B, M, 8)
    Semantics: identity is a property of the neuron, not of the sample, so E[n,j] = E[j] for
    every sample n.

(4) Concatenate with the data condition and feed to the shared generator
      x_b = x_rep.unsqueeze(1).expand(batch, M, d_in)   # (B, M, 64)
      q   = torch.cat([x_b, e_b], dim=-1)               # (B, M, 72)
      b   = self.bias_mlp(q.reshape(B*M, 72)).reshape(B, M, 7)
    i.e. q_{n,j} = [x_n ‖ e_j]; the generator Linear(72,16) -> GELU -> Dropout -> Linear(16,7)
    outputs a 7-dim control-point offset for each (n,j).

(5) Training (how it is updated)
    - The embedding is trainable; gradients flow from the main task loss through
      [generator -> b -> bias_scale·b -> Bézier -> linear2] and are updated by AdamW (same
      group as the generator: lr / weight_decay taken from the regress_mlp group).
    - Soft-start gating: Y = Y_base + bias_scale·b, and bias_scale starts at 0 => initially
      ∂loss/∂E ≡ 0 (the embedding does not move); it only begins to be trained effectively
      once bias_scale leaves 0.

  Flow sketch:
      neuron_idx=[0..M-1] ─► E (lookup) ─► e_j (M,8) ─► expand ─┐
      x_n (B,64) ───────────────────────────────────────────────┼─► [x ‖ e_j] (B,M,72)
                                                                ┘         │
                                                                          ▼
                                                                shared generator ─► b (B,M,7)

(6) Comparison with A / C ("how the identity information is produced")
    - A: implicit — identity lives in the different channels of the bias_mlp output (dedicated
      weight columns); there is no separate vector.
    - B: explicit and learnable — each neuron has a free vector e_j (table E), learned.
    - C: explicit and non-learnable — each neuron is computed from fixed integers
      (l,L,j,n_l); there is no embedding.
    In one sentence: B's embedding is "assign each neuron a trainable vector, look it up by
    index, share it across all samples, and learn it from the main task loss" — it is NOT a
    feature extracted from the input data.

================================================================================
Ch. 4   Experiment groups and their roles
================================================================================
  Group      | Role            | Generation mechanism
  -----------+-----------------+--------------------------------------------------------
  B          | main experiment | shared generator + learnable per-neuron embedding
  A          | main control    | original Sorami bias_mlp (dedicated output channels)
  FixedGELU  | main control    | fixed GELU activation (no adaptation)
  C          | ablation        | shared generator + explicit structural coordinates
             |                 | (tests whether structural conditioning helps)

  Division of labor at the conclusion level: B argues for the effectiveness of "sharing +
  learnable identity"; A answers "is it better than the original implementation?"; FixedGELU
  answers "is it better than the classical fixed activation?"; C is the ablation testing the
  value of "explicit structural conditioning" (and its boundary on a single-layer model).

================================================================================
Ch. 5   Experimental protocol (reproducible setup)
================================================================================
- Data: Concrete_Data.xls, 8 features; ~1030 rows after dedup/dropna; train:val:test = 8:1:1.
- Fixed split seed SPLIT_SEED = 19120101; StandardScaler fit on the training set only.
- Search: Optuna + TPE, 16 trials per group; fixed search-training seed [19120101]; selection
  by validation MSE.
- Final evaluation: after freezing the best hyperparameters, retrain once with each of 8
  predeclared random seeds (the first 8 of RandomSeeds.txt, identical for all four groups);
  the test set is evaluated only here, exactly once.
- All four groups share the same data split, the same search space, the same training
  schedule, and the same seed set; the only difference is the control-point generator.
- Reproducibility: data fingerprint / split manifest / scaler / protocol / checkpoint sha256
  are all written and verified; deterministic algorithms enabled.

================================================================================
Ch. 6   Search results (Optuna phase)
================================================================================
Metric = validation MSE under the single search seed (19120101), lower is better; 16 trials
per group.

  Group      | best   | mean    | median  | worst    | std     | #<60
  -----------+--------+---------+---------+----------+---------+------
  A          | 43.371 | 268.930 | 120.073 | 1465.802 | 378.157 |  3
  B          | 35.480 | 236.684 | 115.096 | 1456.304 | 342.397 |  2
  C          | 34.905 | 224.073 | 118.160 | 1457.939 | 340.545 |  3
  FixedGELU  | 40.388 | 350.154 | 142.774 | 1437.193 | 476.600 |  2

How to read:
- Top end (best): C 34.9 < B 35.5 < FixedGELU 40.4 < A 43.4. During search, B and C are
  already clearly better than A and FixedGELU.
- Distribution (mean/median): B/C are better (224–237 / 115–118); A 269/120; FixedGELU 350/143
  (the worst).
- The vast majority of trials are poor (mean 220–350, worst ~1440); 16 trials is only a
  screening budget, with only 2–3 usable configurations.
- Important: the search "best" is a single training run — noisy and optimistic. C had the best
  search value, yet B overtook it in the final evaluation; that is the evidence.

================================================================================
Ch. 7   Final evaluation results (val and test distributions)
================================================================================
Same set of 8 seeds; val MSE and test MSE (lower is better):

  VAL MSE
    Group      |  mean  |  std  | best(min) | median | worst(max)
    -----------+--------+-------+-----------+--------+-----------
    A          | 48.888 | 6.894 |   39.539  | 50.474 |   57.064
    B          | 40.164 | 4.099 |   33.597  | 41.644 |   45.969
    C          | 42.814 | 4.595 |   35.797  | 43.626 |   48.933
    FixedGELU  | 42.633 | 7.549 |   33.775  | 40.773 |   58.532

  TEST MSE
    Group      |  mean  |  std  | best(min) | median | worst(max)
    -----------+--------+-------+-----------+--------+-----------
    A          | 39.287 | 7.085 |   30.658  | 38.469 |   54.020
    B          | 32.129 | 5.990 |   23.625  | 32.222 |   42.301
    C          | 33.639 | 3.824 |   29.022  | 33.109 |   40.162
    FixedGELU  | 33.919 | 5.414 |   27.529  | 32.732 |   45.386

  Times each group is the best on a seed (test): B 5/8, FixedGELU 2/8, C 1/8, A 0/8.
  Average rank (1 = best): B 1.88 < FixedGELU 2.25 < C 2.38 < A 3.50.

Key points:
- B (main experiment) leads on test mean / median / best / average rank, and is not carried by
  a single extreme seed.
- C (ablation) is best on test std and worst (most stable) — i.e. "no collapse".
- A (original implementation) is the worst on every statistic, on both val and test.

================================================================================
Ch. 8   Paired comparisons and significance
================================================================================
Paired by seed (n=8); difference in test MSE:

  Comparison               | mean diff | wins   | paired t | significant?
  -------------------------+-----------+--------+----------+---------------
  B − FixedGELU            |  −1.79    |  5/8   |  −0.60   | no (p≈0.57)
  B − C                    |  −1.51    | (5/8)  |  −0.70   | no
  C − FixedGELU            |  −0.28    |  3/8   |  −0.70   | no (on par)
  A − FixedGELU            |  +5.37    |  2/8   |  +2.04   | marginal (p≈0.08)
  B − A                    |  −7.16    | (7/8)  |  +2.76   | yes (p≈0.03)

Conclusions:
- B is significantly better than the original Sorami (A) → the new architecture is genuinely
  effective relative to the old implementation.
- B tends to be better than FixedGELU but not significantly → one cannot claim "significantly
  better than the classical activation".
- C (ablation) is on par with FixedGELU.

================================================================================
Ch. 9   Parameter-count comparison
================================================================================
Note: each group selected a different hidden width M (chosen by its own HPO), so total
parameter counts are not directly comparable across groups.

  Group      | M   | total   | generator | embedding | non-generator (backbone+head)
  -----------+-----+---------+-----------+-----------+------------------------------
  A          | 21  | 155007  | 3539      | 0         | 151468
  B          | 16  | 152553  | 1287      | 128       | 151138
  C          | 64  | 155529  | 1223      | 0         | 154306
  FixedGELU  | 20  | 151401  | 0         | 0         | 151401

  The "generator" part normalized to the same width M=64:
    A: 8656   (1040 + 119·M, grows linearly in M)
    B: 1287   (+ 512 = M×8 embedding)
    C: 1223   (constant)

Key points:
- The generator is a tiny fraction of the whole model (A 2.3%, B incl. embedding 0.93%,
  C 0.79%); the total-parameter differences come mainly from the backbone.
- Per-neuron "dedicated" parameters: A ≈ 119 (output weights), B = 8 (embedding), C = 0
  (shared, no identity parameters).
- How the generator scales with M: A grows linearly and is the most expensive; B is constant
  plus 8 per neuron; C is constant and the cheapest.
- One should not claim the new architecture is "more parameter-efficient" based on total
  parameters; efficiency differences belong only within the "generator" scope.

================================================================================
Ch. 10  Conclusions and honest assessment
================================================================================
1. The main group B works: significantly better than the original implementation A (p≈0.03),
   and the most consistently best of the four on test.
2. Relative to the classical FixedGELU: B has only a trending advantage (mean lower by 1.79,
   5/8 wins), not statistically significant; the honest statement is "median comparable or
   slightly better, upper bound improved, no collapse", not "comprehensively beating the fixed
   activation".
3. Ablation C: explicit structural conditioning has limited value on a single-layer model
   (degenerate identity), on par with FixedGELU; but it is the most stable in the tail, which
   can serve as supporting evidence for "stability".
4. The original implementation A ranks last on this dataset — a real and slightly awkward
   result, suggesting that the "dedicated output channels" scheme is inferior to "shared
   generator + identity information" on this task.
5. Overall: the new architecture's gains are real but modest, and bounded by the sample size
   (8 seeds) and each group's independent HPO; it is best positioned as an "honest comparison"
   rather than a claim of dominance.

================================================================================
Ch. 11  Limitations and follow-up
================================================================================
Limitations:
- Only 8 final seeds and a single dataset; the B vs FixedGELU difference is not significant.
- Each group ran its own 16-trial HPO and selected a different width (21/16/64), so
  inter-group differences contain width / hyperparameter luck.
- C's structural coordinates are only meaningful in a model with multiple activation layers;
  the ablation here can only give a boundary-level conclusion.
- The search phase uses a single seed, so the top value is optimistic (C's search was best but
  B overtook it in the final evaluation).

Follow-up suggestions:
- Fix one common set of hyperparameters (same width) and run an A/B/C/FixedGELU "same-
  hyperparameter" comparison to remove the HPO confound.
- Increase the number of final seeds (16–32) to check whether B's −1.8 vs FixedGELU is stable.
- To claim B across datasets, repeat the same B scheme on Wine / Bangumi / California, etc.

================================================================================
Ch. 12  Appendix: scripts and artifacts
================================================================================
Directory: /home/miyabitama/SHUZHE/FixedTransformerSearch/ConcreteStrengthSoramiV6TransformerSearch/
  ConcreteStrengthSoramiV6TransformerSearch.py     Sorami V6 main script (edit GENERATOR_MODE =
                                                   'A'/'B'/'C')
  ConcreteStrengthFixedGELUV2TransformerSearch.py  FixedGELU control script (separate file)
  Concrete_Data.xls, RandomSeeds.txt               required training files
  ConcreteStrengthSoramiV6_unit_tests.py           unit tests (40/40 pass)
  ConcreteStrengthSoramiV6TransformerSearch_A/     group A artifacts (db / results / protocol)
  ConcreteStrengthSoramiV6TransformerSearch_B/     group B artifacts (main experiment)
  ConcreteStrengthSoramiV6TransformerSearch_C/     group C artifacts (ablation)
  ConcreteStrengthFixedGELUV2TransformerSearch/    FixedGELU artifacts
  ConcreteStrengthSoramiV6_{A,B,C}_repro_v2.db     Optuna databases
  ConcreteStrengthFixedGELUV2_repro_v2.db          FixedGELU Optuna database

Key recorded fields (final_seed_results.csv): seed, val_mse, test_mse, n_params_total,
n_params_generator, n_params_embedding, train_time_sec, inference_time_sec, checkpoint_sha256.

(End of document)
================================================================================
