R6 implementation of the Artificial Immune Network algorithm. This is the core bHIVE algorithm using C++ backends for performance-critical operations. Supports composable modules for somatic hypermutation, idiotypic network regulation, germinal center selection, and more.
Super class
bHIVE::ImmuneAlgorithm -> AINet
Methods
Method new()
Create a new AINet algorithm instance.
Usage
AINet$new(
nAntibodies = 20,
beta = 5,
epsilon = 0.01,
maxIter = 50,
k = 3,
affinityFunc = "gaussian",
distFunc = "euclidean",
affinityParams = list(alpha = 1, c = 1, p = 2, Sigma = NULL),
mutationDecay = 1,
mutationMin = 0.01,
maxClones = Inf,
stopTolerance = 0,
noImprovementLimit = Inf,
initMethod = "sample",
consolidate = TRUE,
consolidationSteps = 10L,
scale = c("none", "zscore", "robust", "arcsinh"),
scaleCofactor = 5,
targetK = NULL,
epsilonQuantile = NULL,
coverageBoost = FALSE,
coverageQuantile = 0.05,
shm = NULL,
init = NULL,
activation = NULL,
idiotypic = NULL,
germinalCenter = NULL,
microenvironment = NULL,
memory = NULL,
classSwitcher = NULL,
verbose = TRUE
)Arguments
nAntibodiesInteger. Initial antibody population size.
betaNumeric. Clone multiplier.
epsilonNumeric. Suppression distance threshold.
maxIterInteger. Maximum iterations.
kInteger. Top-k antibodies to clone per data point.
affinityFuncCharacter. Affinity function name.
distFuncCharacter. Distance function name.
affinityParamsList. Parameters for affinity/distance functions.
mutationDecayNumeric. Per-iteration mutation rate decay.
mutationMinNumeric. Minimum mutation rate.
maxClonesNumeric. Maximum clones per antibody.
stopToleranceNumeric. Early stopping tolerance.
noImprovementLimitInteger. Early stopping patience.
initMethodCharacter. Initialization method.
consolidateLogical. For clustering, run Lloyd-style consolidation (an M-step) after affinity maturation so antibodies are pulled onto the data manifold and become true data-space prototypes. Has no effect on classification. Default TRUE.
consolidationStepsInteger. Maximum consolidation iterations.
scaleCharacter. Per-feature input scaling applied at
fit()and re-applied to new data atpredict(). One of"none"(default, no transform),"zscore"(center/SD),"robust"(median / IQR, outlier-tolerant), or"arcsinh"(inverse hyperbolic sine with cofactorscaleCofactor, the standard mass-cytometry transform). Becauseepsilon, mutation scale, and all distances live in feature units, scaling makes the same defaults behave consistently across datasets of different magnitude.scaleCofactorNumeric. Cofactor for
scale = "arcsinh"(asinh(x / cofactor)). Default 5 (CyTOF convention; use ~150 for fluorescence flow).targetKInteger or NULL. If set, force the clustering solution to exactly
targetKclusters. Affinity maturation still discovers where prototypes belong, but the final consolidation seeds a K-means (Lloyd) refinement at exactlytargetKcentroids: surviving antibodies are agglomerated (if more than K) or split with k-means++ (if fewer than K) before refinement. This decouples the reported cluster count from the emergent suppression dynamics. NULL (default) keeps the emergent, self-selected K. Ignored for classification.epsilonQuantileNumeric in (0, 1) or NULL. If set, the suppression threshold is recomputed each iteration as this quantile of the pairwise distances among the current antibodies, making suppression scale-free and adaptive instead of using the fixed
epsilon. NULL (default) uses the fixedepsilon.coverageBoostLogical. Clustering only. After maturation, find data points that no surviving antibody covers well (max affinity in the bottom
coverageQuantiletail) and seed fresh antibodies there with k-means++. Counters the clonal-selection bias toward dense regions, which otherwise leaves rare populations unrepresented. Pairs naturally withtargetK: the extra seeds give the forced-K refinement candidate prototypes for sparse populations. Default FALSE.coverageQuantileNumeric in (0, 1). Affinity-coverage tail that defines "poorly covered" points for
coverageBoost. Default 0.05.shmAn SHMEngine instance or NULL for default uniform mutation.
initA VDJLibrary instance or NULL for default initialization.
activationAn ActivationGate instance or NULL.
idiotypicAn IdiotypicNetwork instance or NULL.
germinalCenterA GerminalCenter instance or NULL.
microenvironmentA Microenvironment instance or NULL.
memoryA MemoryPool instance or NULL.
classSwitcherA ClassSwitcher instance or NULL.
verboseLogical. Print progress.
Method fit()
Fit the AINet algorithm to data.
Examples
# Clustering with Iris data
data(iris)
X <- as.matrix(iris[, 1:4])
model <- AINet$new(nAntibodies = 15, maxIter = 10, verbose = FALSE)
model$fit(X, task = "clustering")
table(model$result$assignments)
#>
#> 1 2 3 4 5 6 7 8 9 10 11 12 13 14
#> 10 10 23 7 14 10 10 8 12 9 18 10 3 6
# Classification
model2 <- AINet$new(nAntibodies = 20, maxIter = 10, verbose = FALSE)
model2$fit(X, iris$Species, task = "classification")
mean(model2$result$assignments == as.character(iris$Species))
#> [1] 0.8933333
# Predict on new data
preds <- model2$predict(X[1:10, ])
