Skip to content

feat(math): PCA warm start in clojure-legacy engine mode (PR-B)#2619

Closed
jucor wants to merge 1 commit into
spr/edge/d61d82adfrom
spr/edge/b39add7e
Closed

feat(math): PCA warm start in clojure-legacy engine mode (PR-B)#2619
jucor wants to merge 1 commit into
spr/edge/d61d82adfrom
spr/edge/b39add7e

Conversation

@jucor

@jucor jucor commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Threads the previous tick's unit components into the power-iteration PCA as
start vectors when POLISMATH_ENGINE_MODE=clojure-legacy, matching Clojure
(conversation.clj:381-387 passes :start-vectors (get-in conv [:pca :comps])
into powerit-pca, pca.clj:86-105; new columns absorbed by 1-padding,
pca.clj:46-49). Default 'improved' mode is unchanged (cold recompute).

  • pca_project_dataframe gains start_vectors (default None) and require_powerit
    (default False). With both absent the code path is BYTE-IDENTICAL to before.
    When a warm start is supplied — or required by legacy mode — and
    POLISMATH_PCA_IMPL=sklearn is set, we warn and fall back to power iteration:
    sklearn's SVD has no start-vector hook, so running it would silently drop the
    warm start (documented at the guard).
  • powerit_pca already supported start_vectors + 1-padding + all-zero->None;
    this just wires production callers to it.
  • Conversation._compute_pca: in legacy mode sets require_powerit=True and, when
    prev_pca has real comps, start_vectors = prev comps (empty/cold -> None, the
    deterministic random cold draw). prev_pca is captured in recompute() (PR-A).

Semantic judgment calls (integrator, please verify vs Clojure):

  • Warm start is POSITIONAL: prev comps align to current columns by index, and
    new (appended) comments are 1-padded — exactly Clojure's behavior. Column
    removal/reorder would misalign, but Clojure is append-only here and
    _power_iteration truncates a too-long start vector defensively (pre-existing,
    pca.py:124-127) where Clojure would error.
  • "legacy implies powerit" is enforced via require_powerit=True even on the
    cold first tick, so an operator setting PCA_IMPL=sklearn + legacy still gets
    powerit (with a warning).

TDD RED evidence (before implementing):
test_start_vectors_reach_powerit:
"TypeError: pca_project_dataframe() got an unexpected keyword argument
'start_vectors'"
test_legacy_tick2_receives_tick1_comps: "assert None is not None"
(tick 2 ran cold; no comps threaded)

Tests: 8 new (start_vectors threading, sklearn-conflict warning, improved
byte-identity, two-tick legacy warm start via spy, angle stability, cold-tick
cross-mode identity). Full suite 422 passed, 17 skipped, 47 xfailed.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

commit-id:b39add7e


Stack:


⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

Threads the previous tick's unit components into the power-iteration PCA as
start vectors when POLISMATH_ENGINE_MODE=clojure-legacy, matching Clojure
(conversation.clj:381-387 passes :start-vectors (get-in conv [:pca :comps])
into powerit-pca, pca.clj:86-105; new columns absorbed by 1-padding,
pca.clj:46-49). Default 'improved' mode is unchanged (cold recompute).

- pca_project_dataframe gains start_vectors (default None) and require_powerit
  (default False). With both absent the code path is BYTE-IDENTICAL to before.
  When a warm start is supplied — or required by legacy mode — and
  POLISMATH_PCA_IMPL=sklearn is set, we warn and fall back to power iteration:
  sklearn's SVD has no start-vector hook, so running it would silently drop the
  warm start (documented at the guard).
- powerit_pca already supported start_vectors + 1-padding + all-zero->None;
  this just wires production callers to it.
- Conversation._compute_pca: in legacy mode sets require_powerit=True and, when
  prev_pca has real comps, start_vectors = prev comps (empty/cold -> None, the
  deterministic random cold draw). prev_pca is captured in recompute() (PR-A).

Semantic judgment calls (integrator, please verify vs Clojure):
- Warm start is POSITIONAL: prev comps align to current columns by index, and
  new (appended) comments are 1-padded — exactly Clojure's behavior. Column
  removal/reorder would misalign, but Clojure is append-only here and
  _power_iteration truncates a too-long start vector defensively (pre-existing,
  pca.py:124-127) where Clojure would error.
- "legacy implies powerit" is enforced via require_powerit=True even on the
  cold first tick, so an operator setting PCA_IMPL=sklearn + legacy still gets
  powerit (with a warning).

TDD RED evidence (before implementing):
  test_start_vectors_reach_powerit:
    "TypeError: pca_project_dataframe() got an unexpected keyword argument
     'start_vectors'"
  test_legacy_tick2_receives_tick1_comps: "assert None is not None"
  (tick 2 ran cold; no comps threaded)

Tests: 8 new (start_vectors threading, sklearn-conflict warning, improved
byte-identity, two-tick legacy warm start via spy, angle stability, cold-tick
cross-mode identity). Full suite 422 passed, 17 skipped, 47 xfailed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

commit-id:b39add7e
@jucor

jucor commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator Author

Closing pull request: commit has gone away

@jucor jucor closed this Jul 18, 2026
@jucor

jucor commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #2640 (an spr commit-id mishap force-closed this PR; content and history continue there).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant