Skip to main content

ARDRegression

#include <Skigen/LinearModel>

template <typename Scalar = double>
class Skigen::ARDRegression(max_iter=300, tol=1e-3, alpha_1=1e-6, alpha_2=1e-6, lambda_1=1e-6, lambda_2=1e-6, compute_score=false, threshold_lambda=1e4, fit_intercept=true, copy_X=true, verbose=false)

Bayesian Automatic Relevance Determination (ARD) regression.

Maintains a per-feature precision λj\lambda_j and prunes features whose precision exceeds threshold_lambda during the evidence-maximisation iteration. Mirrors sklearn.linear_model.ARDRegression.

The posterior covariance over the surviving features is

Σ=(diag(λkeep)+αXkeepXkeep)1\Sigma = \bigl(\operatorname{diag}(\lambda_{\text{keep}}) + \alpha\, X_{\text{keep}}^\top X_{\text{keep}}\bigr)^{-1}

and the posterior mean is wkeep=αΣXkeepyw_{\text{keep}} = \alpha\, \Sigma\, X_{\text{keep}}^\top y.



Attributes:

  • max_iter : int

  • tol : Scalar

  • alpha_1 : Scalar

  • alpha_2 : Scalar

  • lambda_1 : Scalar

  • lambda_2 : Scalar

  • compute_score : bool

  • threshold_lambda : Scalar

  • fit_intercept : bool

  • verbose : bool

  • coef : RowVectorType

  • intercept : Scalar

  • alpha : Scalar

  • lambda_ : RowVectorType Per-feature weight precisions, shape (n_features,).

  • sigma : MatrixType

  • scores : VectorType

  • n_iter : int

  • X_offset : RowVectorType

  • X_scale : RowVectorType

  • y_offset : Scalar


Methods

SKIGEN_PARAMS()

Fit the ARD model via evidence maximisation with feature pruning.


fit(X, y)

Fit from a sparse design matrix (densifies internally).


predict(X)

Predictive mean.


score(X, y)

R2R^2 score.


predict(X)

Predictive mean and standard deviation (tag-dispatch overload).


predict(X)


Example

Skigen::ARDRegression<double> ard(
/*max_iter=*/300, /*tol=*/1e-3,
/*alpha_1=*/1e-6, /*alpha_2=*/1e-6,
/*lambda_1=*/1e-6, /*lambda_2=*/1e-6,
/*compute_score=*/false,
/*threshold_lambda=*/1e4);
ard.fit(X, y);

std::cout << "=== ARDRegression ===\n";
std::cout << " alpha = " << ard.alpha() << "\n";
std::cout << " lambda_ = " << ard.lambda_() << "\n";
std::cout << " coef = " << ard.coef() << "\n";
std::cout << " n_iter = " << ard.n_iter() << "\n";
std::cout << " R^2 (train) = " << ard.score(X, y) << "\n";

// Predictions with confidence intervals on first 5 samples.
Eigen::MatrixXd X_test = X.topRows(5);
auto [y_mean, y_std] = ard.predict(X_test, Skigen::with_std);
std::cout << "\nPredictions with 95% CI (first 5 rows):\n";
for (Eigen::Index i = 0; i < y_mean.size(); ++i) {
std::cout << " y_pred = " << std::setw(7) << y_mean(i)
<< " +/- " << std::setw(6) << 1.96 * y_std(i)
<< " (true=" << y(i) << ")\n";
}