0.99.3#9
Merged
Merged
Conversation
use random_init
set up call_dispatch()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Module Integration
Modules previously accepted by
AINet$new()were stored on the algorithmbut never invoked by the fit loop. v0.99.3 wires every module into
AINet$fit()so it affects predictions:init(VDJLibraryor any object exposing$generate(n, X)) nowcontrols initial-repertoire construction. When supplied, it overrides
initMethod. This makes V(D)J combinatorial assembly the actualstarting state rather than dead metadata.
idiotypic(IdiotypicNetwork) is now invoked between clonal selectionand network suppression. The bell-curve
idiotypic_dynamics_cppkernelculls antibodies in over-clumped niches (suppression) and isolated
antibodies (insufficient stimulation). A safety net keeps the top-10%
population when ill-tuned thresholds would kill every antibody, so the
iteration can continue and downstream selection can penalize the config.
activation(ActivationGate) now pre-screens antibodies in over-densefeature-space neighborhoods out of each round of clonal selection.
Gated antibodies sit aside unchanged while selection runs on the sparse
subset, then rejoin the repertoire. In classification mode their class
labels are refreshed by majority-vote of their nearest data points so
pre-allocated random labels do not poison final predictions.
microenvironment(Microenvironment) is assessed each iteration afterclonal selection. Its
mutation_modifiersscale a per-antibody Gaussianjitter applied in feature units (
0.5%of feature SD on iter 1,decaying with
mutationDecay). Sparse-region antibodies exploreoutward, dense-region antibodies stabilize.
germinalCenter(GerminalCenter) now runs Tfh-mediated qualityselection after clonal-selection rejoin. Survivor indices are composed
across selection rounds and mirrored onto
antibody_classesand theadaptive-SHM moment matrices so external per-antibody state stays
aligned.
GerminalCenter$select()now returns the composed survivorvector (relative to the input repertoire) and exposes it as
$last_survivors.classSwitcher(ClassSwitcher) runs aftermicroenvironmentandbinds each antibody's isotype (IgM/IgG/IgA) to its zone. The
population-mean per-isotype alpha is then used as the next iteration's
affinity kernel width, modulating matching breadth based on the current
density landscape. Requires
microenvironmentto be present.memory(MemoryPool) is invoked at two points. Pre-iteration, inclustering mode, relevant memory cells from prior fits are recalled
(via
recall(X)) and merged into the starting repertoire so priorknowledge seeds the search. Post-iteration, after orphan pruning, the
surviving high-affinity antibodies are archived back into the pool
(
archive()) so they persist across fits. Classification archives alsoattach
class_labelto repertoire metadata so future consumers can readthem back; recall is suppressed for classification to avoid label loss.
shm(SHMEngine) is now dispatched insideclonal_selection_iteration_cpprather than ignored. All five strategies —
uniform,airs,hotspot,energy,adaptive— produce distinct mutation behavior. The adaptivestrategy's Adam-style first/second moment matrices are threaded through
the C++ kernel and re-aligned in R after every subset/reorder operation
(activation gating, germinal-center selection, idiotypic culling,
network suppression) so per-antibody moment tracking stays consistent
across iterations.
C++ Backend
clonal_selection_iteration_cppnow accepts SHM dispatch parameters(
shm_method,shm_c_rate,shm_temperature,shm_E_0,shm_base_rate,shm_beta1,shm_beta2,shm_adam_epsilon) plus adaptive momentmatrices
m1_state/m2_state. The R wrapper provides defaults(
shm_method = "uniform", empty state matrices) so legacy callers thatpass the original 15 arguments still get the previous behavior.
src/shm.hexposes the five SHM strategy helpers and amutate_by_methoddispatcher shared byshm_mutate_cppandclonal_selection_iteration_cpp. The helpers are no longerstatic.New Behavior
AINet$fit()now drops surviving antibodiesthat are not the nearest neighbor to any training point before computing
the final assignment. Eliminates ghost antibodies that pass suppression
but bind nothing, and tightens the relationship between cluster count
and effective antibody count.
antibody_classesis now pre-allocated before the iteration loop inclassification mode (uniform random over
levels(y)), so the newpre-selection gate logic has a value to index into on iteration 1
rather than referencing a not-yet-defined variable.