()
| 37 | |
| 38 | # Driver code |
| 39 | def main() -> None: |
| 40 | # Training Examples ( m, n ) |
| 41 | training_samples = [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]] |
| 42 | |
| 43 | # weight initialization ( n, C ) |
| 44 | weights = [[0.2, 0.6, 0.5, 0.9], [0.8, 0.4, 0.7, 0.3]] |
| 45 | |
| 46 | # training |
| 47 | self_organizing_map = SelfOrganizingMap() |
| 48 | epochs = 3 |
| 49 | alpha = 0.5 |
| 50 | |
| 51 | for _ in range(epochs): |
| 52 | for j in range(len(training_samples)): |
| 53 | # training sample |
| 54 | sample = training_samples[j] |
| 55 | |
| 56 | # Compute the winning vector |
| 57 | winner = self_organizing_map.get_winner(weights, sample) |
| 58 | |
| 59 | # Update the winning vector |
| 60 | weights = self_organizing_map.update(weights, sample, winner, alpha) |
| 61 | |
| 62 | # classify test sample |
| 63 | sample = [0, 0, 0, 1] |
| 64 | winner = self_organizing_map.get_winner(weights, sample) |
| 65 | |
| 66 | # results |
| 67 | print(f"Clusters that the test sample belongs to : {winner}") |
| 68 | print(f"Weights that have been trained : {weights}") |
| 69 | |
| 70 | |
| 71 | # running the main() function |
no test coverage detected