Following this instruction :
1. Strictly adhere to PEP-8 standards, ensuring code is clean, well-structured, and follows Python's style guide for readability.
2. Use appropriate modules like `typing` for type hints, ensuring code clarity, maintainability, and leveraging Python's standard libraries effectively.
3. Focus on time, space, robustness, scalability; write optimized, efficient code that can handle large datasets and scale seamlessly.
4. Implement comprehensive error handling, catching exceptions gracefully, providing meaningful error messages, and ensuring code robustness under unexpected conditions.
5. Ensure the developer agent writes advanced, maintainable Python code, balancing performance and readability while adhering to best practices.

TASK : objective below all api we have develop from scratch using only torch module :

user_input :
1 Model (nn.module) 
2) loss fumnction
3) optimiser
3) adversarical_sample ( batch_size, channel, height, weight)
4) label(batch_size, true_value)




### 1. **ClassLabels**
   - **Purpose**: The `ClassLabels` postprocessor converts a model’s soft output (i.e., probabilities) into hard class labels, effectively choosing the class with the highest confidence.
   - **Equation**:
     \[
     y_{\text{pred}} = \arg \max_i \, p_i
     \]
     where \( p_i \) represents the probability of class \( i \) in the output vector from the model. This approach directly assigns the predicted label based on the maximum class probability, filtering out ambiguous probabilistic information and reducing sensitivity to small perturbations in the model's output.

### 2. **GaussianNoise**
   - **Purpose**: The `GaussianNoise` postprocessor introduces Gaussian (random) noise to the model’s output, which can obscure adversarial patterns and thus make the model more resilient to adversarial attacks.
   - **Equation**:
     \[
     y_{\text{pred}} = y + \epsilon, \quad \epsilon \sim \mathcal{N}(0, \sigma^2)
     \]
     where \( y \) is the model’s output, \( \epsilon \) is the noise drawn from a Gaussian distribution with mean \( 0 \) and variance \( \sigma^2 \), and \( \sigma \) controls the noise level. This randomness can help in mitigating adversarial perturbations by making the output less predictable.

### 3. **HighConfidence**
   - **Purpose**: The `HighConfidence` postprocessor reduces low-confidence predictions by setting a threshold on class probabilities. Only probabilities that meet or exceed this threshold are retained, and the rest are suppressed.
   - **Equation**:
     \[
     y_{\text{pred}} = \begin{cases} 
      y_i, & \text{if } y_i \geq \tau \\
      0, & \text{otherwise} 
      \end{cases}
     \]
     where \( y_i \) represents the probability of class \( i \) and \( \tau \) is a predefined confidence threshold. This approach eliminates low-confidence predictions, leaving only strong predictions in the output and thus enhancing robustness.

### 4. **ReverseSigmoid**
   - **Purpose**: The `ReverseSigmoid` postprocessor transforms the model’s output through an inverse sigmoid function, reducing the sensitivity of the prediction to small input variations by compressing extreme probabilities.
   - **Equation**:
     \[
     y_{\text{pred}} = \frac{1}{1 + \exp(-\alpha \cdot (y - 0.5))}
     \]
     where \( y \) is the model’s output, and \( \alpha \) is a scaling parameter that controls the sharpness of the transformation. This transformation encourages probabilities to stay within a balanced range, rather than saturating at extreme values close to 0 or 1.

### 5. **Rounded**
   - **Purpose**: The `Rounded` postprocessor rounds the model’s output probabilities to a set decimal place, effectively reducing the model’s sensitivity to minor perturbations in the probabilities.
   - **Equation**:
     \[
     y_{\text{pred}} = \text{round}(y, d)
     \]
     where \( y \) is the model’s output, and \( d \) represents the number of decimal places to which probabilities are rounded. This approach can mitigate adversarial effects by making the model less responsive to small, adversarially introduced changes in probability.


---

### 6. **Softmax**
   - **Purpose**: The `Softmax` postprocessor converts a model’s logits (raw output scores) into a probability distribution over classes. This step can help normalize outputs, particularly after adversarial transformations.
   - **Equation**:
     \[
     y_{\text{pred}} = \frac{\exp(y_i)}{\sum_j \exp(y_j)}
     \]
     where \( y_i \) represents the logit for class \( i \). This standardization can reduce extreme values, making adversarial inputs less effective.

### 7. **Temperature Scaling**
   - **Purpose**: The `Temperature Scaling` postprocessor adjusts the confidence of predictions by scaling logits before applying the softmax. This method is commonly used to calibrate model predictions.
   - **Equation**:
     \[
     y_{\text{pred}} = \frac{\exp(y_i / T)}{\sum_j \exp(y_j / T)}
     \]
     where \( T \) (temperature) controls the smoothness of the probability distribution. Larger values of \( T \) create more uniform distributions, reducing overconfident responses to adversarial inputs.

### 8. **Label Smoothing**
   - **Purpose**: This postprocessor smooths the one-hot encoded labels during training, making the model less sensitive to small perturbations.
   - **Equation**:
     \[
     y_{\text{smoothed}} = (1 - \alpha) \cdot y + \frac{\alpha}{K}
     \]
     where \( \alpha \) is the smoothing factor and \( K \) is the number of classes. This reduces model certainty for each label, decreasing vulnerability to adversarial examples by avoiding overconfidence.

### 9. **Top-k Filtering**
   - **Purpose**: This postprocessor only retains the top \( k \) class probabilities and sets the rest to zero, focusing on the most confident predictions and reducing noise from lower-probability classes.
   - **Equation**:
     \[
     y_{\text{pred}} = \begin{cases} 
      y_i, & \text{if } y_i \in \text{Top-}k \\
      0, & \text{otherwise} 
      \end{cases}
     \]
     By focusing on dominant classes, this defense removes lower-confidence noise, mitigating adversarial effects.

### 10. **Normalization**
   - **Purpose**: This postprocessor rescales outputs to a specified range (e.g., 0 to 1), ensuring consistency in output magnitude.
   - **Equation**:
     \[
     y_{\text{pred}} = \frac{y - y_{\min}}{y_{\max} - y_{\min}}
     \]
     where \( y_{\min} \) and \( y_{\max} \) are the minimum and maximum values in the output vector. Rescaling can prevent adversarial perturbations from generating exaggerated outputs.

### 11. **Thresholding**
   - **Purpose**: The `Thresholding` postprocessor enforces a strict minimum and maximum on output values, restricting the output range and avoiding exaggerated responses to adversarial inputs.
   - **Equation**:
     \[
     y_{\text{pred}} = \max(\min(y, \text{upper\_limit}), \text{lower\_limit})
     \]
     Limiting output extremes can prevent adversarial samples from pushing predictions into excessively high or low values.

### 12. **Log Transformation**
   - **Purpose**: This transformation applies the natural logarithm to outputs, reducing the impact of very large values.
   - **Equation**:
     \[
     y_{\text{pred}} = \log(y + 1)
     \]
     where \( y \) is the model’s output. This approach compresses large probabilities, reducing adversarial influence by normalizing extreme values.

### 13. **Quantile Binning**
   - **Purpose**: This method bins output probabilities based on quantiles, reducing sensitivity to minor variations in output values.
   - **Equation**:
     \[
     y_{\text{pred}} = \text{bin}(y, q)
     \]
     where `bin` maps \( y \) to its nearest quantile \( q \). By grouping similar values, quantile binning mitigates the influence of slight adversarial shifts.

### 14. **Median Filtering**
   - **Purpose**: This approach smooths output values by replacing each class probability with the median of its neighbors in a multi-class setting, reducing erratic responses.
   - **Equation**:
     \[
     y_{\text{pred}} = \text{median}(y_{\text{neighbors}})
     \]
     This can stabilize outputs against localized adversarial noise.

### 15. **Entropy Regularization**
   - **Purpose**: This regularization technique penalizes low-entropy predictions, encouraging output distributions that are more uniform and less susceptible to adversarial changes.
   - **Equation**:
     \[
     H(y) = -\sum_i y_i \log(y_i)
     \]
     Higher entropy in predictions increases model uncertainty, reducing overconfident responses that can be exploited by adversarial attacks.



---

### 16. **Adaptive Noise Injection**
   - **Purpose**: The `Adaptive Noise Injection` postprocessor adjusts the noise level dynamically based on input characteristics, adding tailored Gaussian noise to outputs.
   - **Equation**:
     \[
     y_{\text{pred}} = y + \epsilon, \quad \epsilon \sim \mathcal{N}(0, f(y)^2)
     \]
     where \( f(y) \) is a function that adapts noise intensity according to specific features in the output. Adaptive noise can reduce vulnerability by introducing controlled randomness that adapts to the input’s nature, making adversarial manipulation harder to exploit.

### 17. **Temperature Softmax Decay**
   - **Purpose**: Similar to temperature scaling, `Temperature Softmax Decay` gradually reduces temperature over time or during inference steps, adjusting model confidence adaptively.
   - **Equation**:
     \[
     y_{\text{pred}} = \frac{\exp(y_i / T(t))}{\sum_j \exp(y_j / T(t))}
     \]
     where \( T(t) \) decays as a function of time \( t \) or inference steps. As \( T(t) \) decreases, the model’s output becomes more confident, balancing exploration and stability for enhanced robustness against attacks.

### 18. **Outlier Suppression**
   - **Purpose**: This postprocessor reduces the effect of outliers by truncating extreme values, ensuring that excessively high or low values in the output do not dominate predictions.
   - **Equation**:
     \[
     y_{\text{pred}} = \text{clip}(y, \text{lower\_bound}, \text{upper\_bound})
     \]
     where clipping thresholds define allowable output ranges. This process eliminates unusually high values, minimizing the influence of adversarial outliers.

### 19. **Exponential Smoothing**
   - **Purpose**: `Exponential Smoothing` applies a weighted average over the model’s output across multiple inference steps, making predictions less prone to sudden shifts due to adversarial perturbations.
   - **Equation**:
     \[
     y_{\text{smooth}} = \alpha \cdot y + (1 - \alpha) \cdot y_{\text{prev}}
     \]
     where \( \alpha \) is the smoothing factor and \( y_{\text{prev}} \) represents the previous output. Smoothing stabilizes outputs over time, mitigating sharp adversarial-induced changes.

### 20. **Bayesian Calibration**
   - **Purpose**: This method adjusts model confidence based on Bayesian probability, calibrating the model output by incorporating prior distributional information to improve resilience to adversarial shifts.
   - **Equation**:
     \[
     y_{\text{calibrated}} = \frac{\exp(y_i + \log \pi_i)}{\sum_j \exp(y_j + \log \pi_j)}
     \]
     where \( \pi_i \) is the prior probability for class \( i \). By incorporating prior beliefs about classes, Bayesian calibration adjusts outputs to be more realistic and less vulnerable to minor input perturbations.

These post-processors add further layers of stability, reducing output variability, recalibrating confidence, and ensuring consistency against adversarial noise, helping models stay robust in challenging scenarios.