# Federated Learning: A Comparative Study of Defenses Against Poisoning Attacks
## 5 Defense Methods
### Krlu
The algorithm for the federated learning system using COMED as the aggregation model works as follows (Algorithm 5):

```
Input: numberOfAgents, T (number of iterations) Output: globalWeights // Step 1: Initialization and Configuration  Initialize agents with indices [1, 2,..., numberOfAgents]  Initialize globalWeights  Set t = 0 // Step 2: Main Training Loop while t < T do // Step 2: Calculate probabilities for agent selection  probabilities = CalculateSelectionProbabilities(agents) // Step 2: Start parallel training and wait for completion  selectedAgents = SelectAgents(probabilities)  updates = ParallelTraining(selectedAgents) // Step 2: Calculate Median (COMED Aggregation)  medianUpdates = InitializeMedianUpdates() for each coordinate in globalWeights do  values = [] for each agent in selectedAgents do  values_append(agent.update[coordinate]) end for  medianUpdates[coordinate] = CalculateMedian(values) end for // Step 2: Global Update  globalWeights = medianUpdates // Step 3: Evaluation and Updating  EvaluateModel(globalWeights)
```

**Algorithm 5**Identifying malicious model updates using COMED

```
//Step 4: Close Loop  StoreEvaluationResults(globalWeights)  t = t + 1 endwhile returnglobalWeights
```

**Algorithm 5**_Cont._

### RPCA + PCA + K-Means

This is an algorithm we propose that combines Robust Principal Components Analysis (RPCA) with the PCA + K-Means algorithm. RPCA is a technique designed to decompose a matrix into two distinct components: a low-rank matrix (L) representing dominant and essential patterns, and a sparse matrix (S) capturing sparse and potentially disruptive elements. This approach is particularly useful for identifying significant patterns and handling sparse elements, such as outliers or malicious updates, in contexts like federated learning [24]. The decomposition of low-rank matrix (L) and sparse matrix (S) is achieved by solving a complex optimization problem. Essentially, the objective is to find the best combination of L and S that, when added together, reconstructs the original matrix (M). The optimization involves balancing the trade-off between maintaining the essential patterns (low-rank) and identifying sparse disruptive elements. The process aims to discern regularities in the data (L) while singling out irregular or sparse occurrences (S) [25]. This defense mechanism is a combination of RPCA with PCA and clustering. This combination in federated learning introduces a multi-step approach to processing and analyzing updates from participating agents. Initially, RPCA is applied to decompose the update matrix into a low-rank matrix (L) and a sparse matrix (S), allowing for the identification of dominant patterns and potential sparse or disruptive elements, which may include outliers or malicious updates. Subsequently, the low-rank matrix (L) undergoes dimensionality reduction using PCA, aiming to represent the identified patterns in a more compact form. The reduced matrix is then subjected to a clustering algorithm, such as K-Means, to group similar update patterns. This step helps identify clusters of agents contributing similar updates, helping to identify potential malicious activity or anomalous behavior. It enhances the system's ability to robustly aggregate updates in federated learning, while addressing outliers and identifying patterns indicative of irregularities.