Skip to main content
. 2025 Jun 13;12(6):651. doi: 10.3390/bioengineering12060651
Algorithm 1 BreastSwimFedNeXt: Federated Swin Transformer Ensemble for Breast Cancer Classification.
  • Require: 

    Distributed datasets X={(xi,yi)}i=1N from multiple clients, Swin Transformer variants (Tiny, Small, Base, Large), FL parameters θ

  •    1:

    Initialize FL parameters θ and set Swin Transformer variants and RF meta-learner

  •    2:

    for each client i do

  •    3:

        Perform local data preprocessing: apply augmentation (rotation, flipping, brightness, Gaussian noise, blur)

  •    4:
        Train local Swin Transformer model to extract features:
    fswin=SwinTransformer(X)
  •    5:
        Apply MHSA:
    Attention(Q,K,V)=softmaxQKTdkV
  •    6:
        Optimize with local cross-entropy loss:
    Llocal=ylog(y^local)
  •    7:

    end for

  •    8:
    Server aggregates model weights using FedAvg:
    Wglobal=1NWlocali
  •    9:
    Server constructs stacking ensemble: base predictions from all Swin variants → RF meta-learner
    y^=RF(fSwinTiny,fSwinSmall,fSwinBase,fSwinLarge)
  •    10:

    return Final prediction y^