Research Article
Research on the Intrusion Detection Model of Underwater Sensor Networks
Algorithm 2
SMOTE algorithm pseudo code.
Algorithm 2 Oversampling algorithm SMOTE(T, N, k) | Input: T——Number of minority class samples | N——Amount of SMOTE | k——Number of nearest neighbors | Output: (N/100)T | 1. numattrs——Number of attributes | 2. Sample[ ][ ]——array for original minority class samples | 3. newindex——keeps a count of number of synthetic samples generated, initialized to 0 | 4. Synthetic[ ][ ]——array for synthetic samples | 5. if N < 100 | 6. then Randomize the T minority class samples | 7. T = (N/100)T | 8. N = 100 | 9. endif | 10. N = (int)(N/100) | 11. for i = 1 to T do | 12 Compute k nearest neighbors for i, and save the indices in the nnarray | 13. Populate(N, i, nnarray) | 14. endfor | 15. nnarray——Storing nearest neighbor arrays | 16. while N != 0 do | 17. nn = random(1,k) | 18. for attr = 1 to numattrs do | 19. Compute: dif = Sample[nnarray[nn]][attr]- Sample[i][attr] | 20. Compute: gap = random(0, 1) | 21. Synthetic[newindex][attr] = Sample[i][attr] + gap dif | 22. endfor | 23. newindex + + | 24. N − − | 25. endwhile |
|