(numSamples: number, noise: number)
| 154 | } |
| 155 | |
| 156 | export function classifyCircleData(numSamples: number, noise: number): |
| 157 | Example2D[] { |
| 158 | let points: Example2D[] = []; |
| 159 | let radius = 5; |
| 160 | function getCircleLabel(p: Point, center: Point) { |
| 161 | return (dist(p, center) < (radius * 0.5)) ? 1 : -1; |
| 162 | } |
| 163 | |
| 164 | // Generate positive points inside the circle. |
| 165 | for (let i = 0; i < numSamples / 2; i++) { |
| 166 | let r = randUniform(0, radius * 0.5); |
| 167 | let angle = randUniform(0, 2 * Math.PI); |
| 168 | let x = r * Math.sin(angle); |
| 169 | let y = r * Math.cos(angle); |
| 170 | let noiseX = randUniform(-radius, radius) * noise; |
| 171 | let noiseY = randUniform(-radius, radius) * noise; |
| 172 | let label = getCircleLabel({x: x + noiseX, y: y + noiseY}, {x: 0, y: 0}); |
| 173 | points.push({x, y, label}); |
| 174 | } |
| 175 | |
| 176 | // Generate negative points outside the circle. |
| 177 | for (let i = 0; i < numSamples / 2; i++) { |
| 178 | let r = randUniform(radius * 0.7, radius); |
| 179 | let angle = randUniform(0, 2 * Math.PI); |
| 180 | let x = r * Math.sin(angle); |
| 181 | let y = r * Math.cos(angle); |
| 182 | let noiseX = randUniform(-radius, radius) * noise; |
| 183 | let noiseY = randUniform(-radius, radius) * noise; |
| 184 | let label = getCircleLabel({x: x + noiseX, y: y + noiseY}, {x: 0, y: 0}); |
| 185 | points.push({x, y, label}); |
| 186 | } |
| 187 | return points; |
| 188 | } |
| 189 | |
| 190 | export function classifyXORData(numSamples: number, noise: number): |
| 191 | Example2D[] { |
nothing calls this directly
no test coverage detected
searching dependent graphs…