FedSamAggregationStrategy<T>
Models & Types · AiDotNet.FederatedLearning.Aggregators
Implements FedSAM (Sharpness-Aware Minimization for Federated Learning) aggregation strategy.
Inheritance: FederatedLearningComponentBase<T> → AggregationStrategyBase<Dictionary<string, T[]>, T> → ParameterDictionaryAggregationStrategyBase<T> → FedSamAggregationStrategy<T>
For Beginners
Regular optimization finds a low point (minimum) in the loss landscape, but this point might be “sharp” — a small change in parameters causes a large change in loss. FedSAM instead seeks “flat” minima that are more robust, which is especially important in FL where each client’s data creates a different loss landscape.
How It Works
Local training uses a two-step process per batch:
Variants:
Reference: Caldarola, D., et al. (2022). “Improving Generalization in Federated Learning by Seeking Flat Minima.”
Constructors
| Constructor | Summary |
|---|---|
FedSamAggregationStrategy(double perturbationRadius, FedSamVariant variant, double globalPerturbationRadius, double approximationCoeff, double controlCoeff) |
Initializes a new instance of the FedSamAggregationStrategy class. |
Properties
| Property | Summary |
|---|---|
FedSamVariant Variant { get; } |
Gets the FedSAM variant being used. |
double ApproximationCoefficient { get; } |
Gets the approximation coefficient (FedSpeed/FedLESAM). |
double ControlCoefficient { get; } |
Gets the stochastic control coefficient (FedSCAM). |
double GlobalPerturbationRadius { get; } |
Gets the global perturbation radius (FedSMOO). |
double PerturbationRadius { get; } |
Gets the SAM perturbation radius (rho). |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T[]> Aggregate(Dictionary<int, Dictionary<string, T[]>> clientModels, Dictionary<int, double> clientWeights) |
Aggregates client models using standard weighted averaging. |
Dictionary<string, T[]> ApplyPerturbation(Dictionary<string, T[]> parameters, Dictionary<string, T[]> perturbation) |
Applies a perturbation to model parameters: w_perturbed = w + epsilon. |
Dictionary<string, T[]> ComputePerturbation(Dictionary<string, T[]> gradient) |
Computes the SAM perturbation direction from the current gradient. |
Dictionary<string, T[]> ComputeSAMGradient(Dictionary<string, T[]> currentGradient, Dictionary<string, T[]> perturbedGradient) |
Computes the complete SAM-modified gradient for a training step. |
string GetStrategyName() |
|
void UpdateGradientHistory(Dictionary<string, T[]> gradient) |
Updates the gradient history (used by FedSpeed/FedLESAM for approximation). |