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 : we have develop below from scratch using torch module :





| **Metric**                       | **Equation**                                                                                         | **Description**                                                                                               |
|----------------------------------|------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| **Accuracy**                     | \( \text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN} \)                                           | Measures the proportion of correctly classified images.                                                       |
| **Precision**                    | \( \text{Precision} = \frac{TP}{TP + FP} \)                                                         | Percentage of positive predictions that are correct.                                                          |
| **Recall**                       | \( \text{Recall} = \frac{TP}{TP + FN} \)                                                            | Ability to detect all positive instances.                                                                     |
| **F1 Score**                     | \( \text{F1} = 2 \cdot \frac{\text{Precision} \cdot \text{Recall}}{\text{Precision} + \text{Recall}} \) | Harmonic mean of Precision and Recall.                                                                        |
| **True Positive Rate (TPR)**     | \( \text{TPR} = \frac{TP}{TP + FN} \)                                                               | Also called Recall; measures correctly identified positives.                                                  |
| **False Positive Rate (FPR)**    | \( \text{FPR} = \frac{FP}{FP + TN} \)                                                               | Proportion of negatives incorrectly classified as positives.                                                  |
| **True Negative Rate (TNR)**     | \( \text{TNR} = \frac{TN}{TN + FP} \)                                                               | Also called Specificity; proportion of negatives correctly identified.                                        |
| **False Negative Rate (FNR)**    | \( \text{FNR} = \frac{FN}{FN + TP} \)                                                               | Proportion of positives incorrectly classified as negatives.                                                  |
| **Matthews Correlation Coefficient (MCC)** | \( \text{MCC} = \frac{(TP \cdot TN) - (FP \cdot FN)}{\sqrt{(TP + FP)(TP + FN)(TN + FP)(TN + FN)}} \) | Measures correlation between true labels and predictions.                                                     |
| **Cohen's Kappa**                | \( \kappa = \frac{\text{Accuracy} - \text{Random Accuracy}}{1 - \text{Random Accuracy}} \)          | Adjusts for agreement by chance.                                                                             |
| **AUC-ROC**                      | Area under the ROC curve                                                                            | Evaluates classifier’s ability to distinguish between classes.                                                |
| **Log Loss**                     | \( \text{Log Loss} = -\frac{1}{N} \sum_{i=1}^{N} \sum_{j=1}^{M} y_{ij} \log(p_{ij}) \)             | Penalizes predictions based on the distance from the correct labels.                                          |
| **Cross-Entropy Loss**           | Similar to Log Loss, used in multi-class classification                                             | Measures divergence from actual distribution.                                                                 |
| **Hamming Loss**                 | \( \text{Hamming Loss} = \frac{1}{N} \sum_{i=1}^{N} \frac{1}{L} \sum_{j=1}^{L} \mathbb{1}(y_{ij} \neq \hat{y}_{ij}) \) | Fraction of misclassified labels in multi-label classification.                                               |
| **Jaccard Index**                | \( J = \frac{TP}{TP + FP + FN} \)                                                                   | Measures similarity between actual and predicted classes (IoU).                                               |
| **Dice Coefficient**             | \( \text{Dice} = \frac{2 \cdot TP}{2 \cdot TP + FP + FN} \)                                        | Similar to Jaccard but weighted for overlap.                                                                  |
| **Balanced Accuracy**            | \( \text{Balanced Accuracy} = \frac{\text{TPR} + \text{TNR}}{2} \)                                  | Average of True Positive Rate and True Negative Rate.                                                         |
| **Top-k Accuracy**               | \( \text{Top-k Accuracy} = \frac{\text{Top-k correct predictions}}{\text{Total Predictions}} \)     | Measures whether the correct label is within the top k predicted labels.                                      |
| **Mean Squared Error (MSE)**     | \( \text{MSE} = \frac{1}{N} \sum_{i=1}^{N} (y_i - \hat{y}_i)^2 \)                                  | Used in regression for image quality assessments, measures prediction errors.                                 |
| **Mean Absolute Error (MAE)**    | \( \text{MAE} = \frac{1}{N} \sum_{i=1}^{N} |y_i - \hat{y}_i| \)                                    | Measures the average magnitude of prediction errors.                                                          |
| **Average Precision (AP)**       | AP is the area under the precision-recall curve                                                     | Evaluates precision across all recall levels.                                                                 |
| **G-Mean**                       | \( \text{G-Mean} = \sqrt{\text{TPR} \times \text{TNR}} \)                                          | Geometric mean of TPR and TNR, useful for imbalanced classes.                                                 |
| **F2 Score**                     | \( \text{F2} = (1 + 2^2) \cdot \frac{\text{Precision} \cdot \text{Recall}}{(2^2) \cdot \text{Precision} + \text{Recall}} \) | F1 variant that gives more weight to recall.                                                                  |
| **Weighted Accuracy**            | \( \text{Weighted Accuracy} = \frac{\sum_{c} w_c \cdot \text{Accuracy}_c}{\sum_{c} w_c} \)         | Weighted accuracy, useful when different classes have different importance.


we have test using module module 
for image/video/text/audio classification