in src/dataset.ts [156:188]
export function classifyCircleData(numSamples: number, noise: number):
Example2D[] {
let points: Example2D[] = [];
let radius = 5;
function getCircleLabel(p: Point, center: Point) {
return (dist(p, center) < (radius * 0.5)) ? 1 : -1;
}
// Generate positive points inside the circle.
for (let i = 0; i < numSamples / 2; i++) {
let r = randUniform(0, radius * 0.5);
let angle = randUniform(0, 2 * Math.PI);
let x = r * Math.sin(angle);
let y = r * Math.cos(angle);
let noiseX = randUniform(-radius, radius) * noise;
let noiseY = randUniform(-radius, radius) * noise;
let label = getCircleLabel({x: x + noiseX, y: y + noiseY}, {x: 0, y: 0});
points.push({x, y, label});
}
// Generate negative points outside the circle.
for (let i = 0; i < numSamples / 2; i++) {
let r = randUniform(radius * 0.7, radius);
let angle = randUniform(0, 2 * Math.PI);
let x = r * Math.sin(angle);
let y = r * Math.cos(angle);
let noiseX = randUniform(-radius, radius) * noise;
let noiseY = randUniform(-radius, radius) * noise;
let label = getCircleLabel({x: x + noiseX, y: y + noiseY}, {x: 0, y: 0});
points.push({x, y, label});
}
return points;
}