Gaussian discriminant analysis (GDA) models each class with a Gaussian, , and a class prior . How the covariances are constrained decides how many parameters you estimate and whether the decision boundaries are quadratic or linear.
Implement two functions. Classes are labelled and every class appears in y.
gda_fit(X, y, cov_type="full", lam=0.0) returns a dict with
"pi": shape (C,), "mu": shape (C, D), the class means"Sigma": shape (C, D, D), one covariance per class (repeat the shared matrix for tied types)The covariance options, all maximum-likelihood estimates with divisor or (not ):
"full": "tied": one pooled matrix "diag": the diagonal of each "full" matrix (off-diagonals set to 0)"tied_diag": the diagonal of the "tied" matrixAfter building the matrices, apply regularized discriminant analysis (RDA) to every covariance:
with = lam (so lam=0 leaves them unchanged).
gda_predict_proba(params, X) returns the (N, C) matrix of posteriors , computed from the discriminant function
and normalized over classes with a numerically stable log-sum-exp. Each row must sum to 1.