pub struct FedProxOptimizer<A: Float + ScalarOperand + Debug + Send + Sync + 'static, D: Dimension + Send + Sync + Clone> { /* private fields */ }Expand description
FedProx optimizer for federated learning
FedProx adds a proximal term mu/2 * ||w - w_global||^2 to each client’s local objective, producing a gradient correction of mu * (w - w_global). This encourages local models to stay close to the global model, improving convergence under heterogeneous conditions.
Implementations§
Source§impl<A: Float + ScalarOperand + Debug + Send + Sync + 'static, D: Dimension + Send + Sync + Clone> FedProxOptimizer<A, D>
impl<A: Float + ScalarOperand + Debug + Send + Sync + 'static, D: Dimension + Send + Sync + Clone> FedProxOptimizer<A, D>
Sourcepub fn new(config: FedProxConfig<A>) -> Self
pub fn new(config: FedProxConfig<A>) -> Self
Create a new FedProxOptimizer with the given configuration
Sourcepub fn builder(num_clients: usize) -> FedProxConfigBuilder<A>
pub fn builder(num_clients: usize) -> FedProxConfigBuilder<A>
Convenience method to create a builder
Sourcepub fn set_global_parameters(&mut self, params: &[Array<A, D>]) -> Result<()>
pub fn set_global_parameters(&mut self, params: &[Array<A, D>]) -> Result<()>
Store the current global model parameters
This must be called before performing local updates, as the proximal term references the global parameters.
Sourcepub fn local_update(
&self,
params: &[Array<A, D>],
gradients: &[Array<A, D>],
lr: A,
) -> Result<Vec<Array<A, D>>>
pub fn local_update( &self, params: &[Array<A, D>], gradients: &[Array<A, D>], lr: A, ) -> Result<Vec<Array<A, D>>>
Perform a local update step with the FedProx proximal gradient
Computes: w_new = w - lr * (gradient + mu * (w - w_global))
When mu=0, this reduces to standard SGD: w_new = w - lr * gradient
Sourcepub fn compute_proximal_gradient(
&self,
params: &[Array<A, D>],
) -> Result<Vec<Array<A, D>>>
pub fn compute_proximal_gradient( &self, params: &[Array<A, D>], ) -> Result<Vec<Array<A, D>>>
Compute the proximal gradient: mu * (params - global_params)
This gradient term pulls local parameters towards the global model, preventing excessive divergence during local training.
Sourcepub fn submit_client_update(
&mut self,
client_id: usize,
params: &[Array<A, D>],
data_size: usize,
) -> Result<()>
pub fn submit_client_update( &mut self, client_id: usize, params: &[Array<A, D>], data_size: usize, ) -> Result<()>
Submit a client’s updated parameters after local training
Sourcepub fn aggregate_updates(&mut self) -> Result<Vec<Array<A, D>>>
pub fn aggregate_updates(&mut self) -> Result<Vec<Array<A, D>>>
Aggregate client updates using weighted averaging (FedAvg-style)
Each client’s contribution is weighted by its data_size relative to the total data across all participating clients. This produces a new global model for the next communication round.
Sourcepub fn get_round_count(&self) -> usize
pub fn get_round_count(&self) -> usize
Get the number of completed communication rounds
Sourcepub fn get_config(&self) -> &FedProxConfig<A>
pub fn get_config(&self) -> &FedProxConfig<A>
Get a reference to the current configuration
Sourcepub fn get_global_parameters(&self) -> Option<&Vec<Array<A, D>>>
pub fn get_global_parameters(&self) -> Option<&Vec<Array<A, D>>>
Get a reference to the current global parameters, if set
Sourcepub fn get_pending_updates_count(&self) -> usize
pub fn get_pending_updates_count(&self) -> usize
Get the number of client updates collected so far in this round
Trait Implementations§
Auto Trait Implementations§
impl<A, D> Freeze for FedProxOptimizer<A, D>where
A: Freeze,
impl<A, D> RefUnwindSafe for FedProxOptimizer<A, D>where
A: RefUnwindSafe,
D: RefUnwindSafe,
impl<A, D> Send for FedProxOptimizer<A, D>
impl<A, D> Sync for FedProxOptimizer<A, D>
impl<A, D> Unpin for FedProxOptimizer<A, D>
impl<A, D> UnsafeUnpin for FedProxOptimizer<A, D>where
A: UnsafeUnpin,
impl<A, D> UnwindSafe for FedProxOptimizer<A, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.