@@ -228,15 +228,8 @@ export function classifyLinearTrainData(numSamples: number, noise: number):
228
228
229
229
function genGauss ( cx : number , cy : number , label : number ) {
230
230
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 ) ;
240
233
points . push ( { x, y, label} ) ;
241
234
}
242
235
}
@@ -264,6 +257,41 @@ export function classifyLinearTestData(numSamples: number, noise: number):
264
257
return points ;
265
258
}
266
259
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
+
267
295
/**
268
296
* Returns a sample from a uniform [a, b] distribution.
269
297
* Uses the seedrandom library as the random generator.
0 commit comments