Generate a small deterministic toy data set. Four independent sources are modulated by the target class and mixed into signal space.
(classes=("class_a", "class_b"))
| 57 | |
| 58 | |
| 59 | def deterministic_toy_data(classes=("class_a", "class_b")): |
| 60 | """Generate a small deterministic toy data set. |
| 61 | |
| 62 | Four independent sources are modulated by the target class and mixed |
| 63 | into signal space. |
| 64 | """ |
| 65 | sources_a = ( |
| 66 | np.array( |
| 67 | [ |
| 68 | [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], |
| 69 | [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], |
| 70 | [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1], |
| 71 | [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], |
| 72 | ], |
| 73 | dtype=float, |
| 74 | ) |
| 75 | * 2 |
| 76 | - 1 |
| 77 | ) |
| 78 | |
| 79 | sources_b = ( |
| 80 | np.array( |
| 81 | [ |
| 82 | [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], |
| 83 | [0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1], |
| 84 | [0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1], |
| 85 | [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1], |
| 86 | ], |
| 87 | dtype=float, |
| 88 | ) |
| 89 | * 2 |
| 90 | - 1 |
| 91 | ) |
| 92 | |
| 93 | sources_a[0, :] *= 1 |
| 94 | sources_a[1, :] *= 2 |
| 95 | |
| 96 | sources_b[2, :] *= 3 |
| 97 | sources_b[3, :] *= 4 |
| 98 | |
| 99 | mixing = np.array( |
| 100 | [ |
| 101 | [1.0, 0.8, 0.6, 0.4], |
| 102 | [0.8, 1.0, 0.8, 0.6], |
| 103 | [0.6, 0.8, 1.0, 0.8], |
| 104 | [0.4, 0.6, 0.8, 1.0], |
| 105 | ] |
| 106 | ) |
| 107 | |
| 108 | x_class_a = mixing @ sources_a |
| 109 | x_class_b = mixing @ sources_b |
| 110 | |
| 111 | x = np.stack([x_class_a, x_class_b]) |
| 112 | y = np.array(classes) |
| 113 | |
| 114 | return x, y |
| 115 | |
| 116 |
no outgoing calls
no test coverage detected