bHIVE is an R package implementing an Artificial Immune Network (AI-Net) algorithm. Inspired by principles of immunology, the bHIVE algorithm evolves a population of "antibodies" to model and analyze datasets. It supports three tasks:
- Clustering: Groups data points based on similarity.
- Classification: Assigns labels to data points based on learned patterns.
- Regression: Predicts continuous outcomes based on input features.
The AI-Net algorithm uses clonal selection and mutation, network suppression, and affinity/distance metrics to iteratively refine the antibody population.
The algorithm operates in the following steps:
-
Affinity Calculation: For a data point
x
and an antibodya
, the affinity is defined as:Affinity(x, a) = f(x, a; params)
where
f
is a similarity kernel such as Gaussian (RBF), Laplace, or cosine similarity. -
Clonal Expansion and Mutation: Top-matching antibodies are cloned and mutated:
a' = a + ε
where
ε
is sampled from a distribution scaled by affinity and iteration parameters. -
Network Suppression: Antibodies that are too similar (within a threshold
ε
) are suppressed to maintain diversity:Distance(a_i, a_j) < ε ⇒ Suppress a_j
-
Assignment: Data points are assigned to antibodies using affinity (for classification/regression) or distance (for clustering).
To install the bHIVE from GitHub, use:
# Install bHIVE from GitHub
devtools::install_github("ncborcherding/bHIVE")
# Load the Iris dataset
data(iris)
X <- as.matrix(iris[, 1:4]) # Use numeric features only
# Run bHIVE for clustering
res <- bHIVE(X = X,
task = "clustering",
nAntibodies = 30,
beta = 5,
epsilon = 0.01,
maxIter = 20,
k = 3)
# View clustering results
table(res$assignments)
# Load the Iris dataset
data(iris)
X <- as.matrix(iris[, 1:4]) # Use numeric features
y <- iris$Species # Classification labels
# Run bHIVE for classification
res <- bHIVE(X = X,
y = y,
task = "classification",
nAntibodies = 30, beta = 5,
epsilon = 0.01,
maxIter = 20,
k = 3)
# Compare predicted labels with actual labels
table(Predicted = res$assignments, Actual = y)
# Load the Iris dataset
data(iris)
X <- as.matrix(iris[, 2:4]) # Use other features as predictors
y <- iris$Sepal.Length # Regression target
# Run bHIVE for regression
res <- bHIVE(X = X,
y = y,
task = "regression",
nAntibodies = 30,
beta = 5,
epsilon = 0.01,
maxIter = 20,
k = 3)
# Compare predicted values with actual values
cor(res$assignments, y)
If you run into any issues or bugs please submit a GitHub issue with details of the issue.
If possible please include a reproducible example.
Any requests for new features or enhancements can also be submitted as GitHub issues.
We welcome contributions to the bHIVE project! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -m "Add new feature"
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.