Skip to content

Commit 31e1d47

Browse files
committed
Added simple is better dataset and made minor dataset changes
1 parent f98b4de commit 31e1d47

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ <h4>
170170
<div class="dataset" title="Linear">
171171
<canvas class="data-thumbnail" data-dataset="linear"></canvas>
172172
</div>
173-
<div class="dataset" title="Placeholder">
174-
<canvas class="data-thumbnail" data-dataset="placeholder"></canvas>
173+
<div class="dataset" title="Moon">
174+
<canvas class="data-thumbnail" data-dataset="moon"></canvas>
175175
</div>
176176
<div class="dataset" title="Plane">
177177
<canvas class="data-thumbnail" data-regDataset="reg-plane"></canvas>

src/dataset.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,8 @@ export function classifyLinearTrainData(numSamples: number, noise: number):
228228

229229
function genGauss(cx: number, cy: number, label: number) {
230230
for (let i = 0; i < numSamples / 2; i++) {
231-
let x = Math.min(Math.max(normalRandom(cx, variance*5), -5), 5);
232-
let y = Math.min(Math.max(normalRandom(cy, variance*5), -5), 5);
233-
while (x + y > 0) {
234-
if (x >= -5) {
235-
x -= 1;
236-
} else {
237-
y -= 1;
238-
}
239-
}
231+
let x = Math.min(Math.max(normalRandom(cx, variance*4), -5), 5);
232+
let y = Math.min(Math.max(normalRandom(cy, variance*4), -5), 5);
240233
points.push({x, y, label});
241234
}
242235
}
@@ -264,6 +257,41 @@ export function classifyLinearTestData(numSamples: number, noise: number):
264257
return points;
265258
}
266259

260+
export function classifyMoonData(numSamples: number, noise: number):
261+
Example2D[] {
262+
let points: Example2D[] = [];
263+
// let radius = 5;
264+
// function getCircleLabel(p: Point, center: Point) {
265+
// return (dist(p, center) < (radius * 0.5)) ? 1 : -1;
266+
// }
267+
268+
// Generate positive points inside the circle.
269+
for (let i = 0; i < numSamples / 2; i++) {
270+
let ind = randUniform(0, Math.PI);
271+
let xnoise = randUniform(-0.5, 0.5)*(1 + noise*5);
272+
let ynoise = randUniform(-0.5, 0.5)*(1 + noise*5);
273+
let x = Math.cos(ind)*3 - 1.5 + xnoise;
274+
let y = Math.sin(ind)*3 + 0.5 + ynoise;
275+
let label = 1;
276+
// let noiseX = randUniform(-Math.PI, 0) * noise;
277+
// let noiseY = Math.cos(randUniform(-Math.PI, 0)) * noise;
278+
// let label = getCircleLabel({x: x + noiseX, y: y + noiseY}, {x: 0, y: 0});
279+
points.push({x, y, label});
280+
}
281+
282+
// Generate negative points outside the circle.
283+
for (let i = 0; i < numSamples / 2; i++) {
284+
let ind = randUniform(0, Math.PI);
285+
let xnoise = randUniform(-0.5, 0.5)*(1 + noise*5);
286+
let ynoise = randUniform(-0.5, 0.5)*(1 + noise*5);
287+
let x = (1 - Math.cos(ind))*3 - 1.5 + xnoise;
288+
let y = (1 - Math.sin(ind))*3 - 3.5 + ynoise;
289+
let label = -1;
290+
points.push({x, y, label});
291+
}
292+
return points;
293+
}
294+
267295
/**
268296
* Returns a sample from a uniform [a, b] distribution.
269297
* Uses the seedrandom library as the random generator.

src/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export let datasets: {[key: string]: dataset.DataGenerator} = {
4545
"gauss": dataset.classifyTwoGaussData,
4646
"spiral": dataset.classifySpiralData,
4747
"linear": dataset.classifyLinearTrainData,
48+
"moon": dataset.classifyMoonData,
4849
};
4950

5051
/** A map between dataset names and functions that generate regression data. */

0 commit comments

Comments
 (0)