(numSamples: number, noise: number)
| 188 | } |
| 189 | |
| 190 | export function classifyXORData(numSamples: number, noise: number): |
| 191 | Example2D[] { |
| 192 | function getXORLabel(p: Point) { return p.x * p.y >= 0 ? 1 : -1; } |
| 193 | |
| 194 | let points: Example2D[] = []; |
| 195 | for (let i = 0; i < numSamples; i++) { |
| 196 | let x = randUniform(-5, 5); |
| 197 | let padding = 0.3; |
| 198 | x += x > 0 ? padding : -padding; // Padding. |
| 199 | let y = randUniform(-5, 5); |
| 200 | y += y > 0 ? padding : -padding; |
| 201 | let noiseX = randUniform(-5, 5) * noise; |
| 202 | let noiseY = randUniform(-5, 5) * noise; |
| 203 | let label = getXORLabel({x: x + noiseX, y: y + noiseY}); |
| 204 | points.push({x, y, label}); |
| 205 | } |
| 206 | return points; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Returns a sample from a uniform [a, b] distribution. |
nothing calls this directly
no test coverage detected
searching dependent graphs…