-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebclust-0.15.js
2285 lines (2008 loc) · 86.7 KB
/
webclust-0.15.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
/* Library version */
var VERSION = "0.15";
/** ------------------------------------------------------
Main functions for the Web Clustering demo.
--------------------------------------------------------- */
/**
Runs the visualization demo.
*/
async function demo() {
running = true;
// Wait function
const delay = ms => new Promise(res => setTimeout(res, ms));
// Disable button
disable("demo", "running");
await delay(25);
clear();
// Get clustering algorithm type and dataset name
let type = get_selected_algorithm();
let name = get_selected_dataset();
// Get render options for the dataset
let opt = get_render_options(name);
let msize = get_marker_size(type);
// Get data
let data = orig_data.clone();
// Build and train a clustering algorithm
let cl = build_cluster(type);
cl.train(data);
if (!cl.iterable()) {
let map = create_decision_boundaries(cl, opt);
draw_map(map);
draw_labels(data, opt);
draw_markers(cl.get_markers(), opt, msize);
}
else {
// Enable Stop button
enable("stop");
while (!cl.done() && running) {
// Start time
let start = new Date().getTime();
// Iterate classifier
cl.iterate();
let map = create_decision_boundaries(cl, opt);
draw_map(map);
draw_labels(data, opt);
draw_markers(cl.get_markers(), opt, msize);
document.getElementById("citer").innerHTML = "Iteration: " + cl.current_iteration();
// Time elapsed
let end = new Date().getTime();
let time = end - start;
let rest = 150 - time;
if (rest < 10) rest = 10;
// Wait
await delay(rest);
}
// Disable Stop button
disable("stop");
}
document.getElementById("clusters").innerHTML = "Clusters: " + cl.no_clusters();
// Enable button
enable("demo");
running = false;
}
/**
Stops the iteration for iterable algorithms.
*/
function stop_demo() {
running = false;
}
/**
Optimize the k-value for K-Means clustering.
*/
async function optimize_k() {
running = true;
// Wait function
const delay = ms => new Promise(res => setTimeout(res, ms));
// Disable button
disable("demo", "running");
await delay(25);
// Get dataset name
let name = get_selected_dataset();
// Get data
let data = orig_data.clone();
// Get params
let dist = get_select_list("dist", 0);
let init = get_select_list("init", 1);
let seed = get_value("seed", 42, 0, 10000);
// Run silhouette score optimization
let opt = new KOptimizer(data, dist, init, seed);
let k = opt.optimize();
document.getElementById("k").value = k;
// Enable button
enable("demo");
running = false;
}
/**
Creates a map of the dedision boundaries for the current trained clustering algorithm.
*/
function create_decision_boundaries(classifier, opt) {
let map = new Array(100 * 100).fill(0);
// 100x100 map
for (let x1 = 0; x1 < 100; x1++) {
for (let x2 = 0; x2 < 100; x2++) {
// x-values
let v1 = x1 / 100.0 * opt[0] + opt[2];
let v2 = x2 / 100.0 * opt[1] + opt[3];
v1 += 0.005;
v2 += 0.005;
// Prediction
let pred = classifier.predict([[v1, v2]]);
// Set predicted label
map[x1 + x2 * 100] = pred[0];
}
}
return map;
}
/**
Validates hyperparameter settings.
*/
function validate_setting(id, value, min_val, max_val) {
let v = value;
if (v < min_val) {
v = min_val;
}
if (v > max_val) {
v = max_val;
}
if (v != value) {
document.getElementById(id).value = v;
}
return v;
}
/**
Builds the specified clustering algorithm and trains on the specified dataset.
*/
function build_cluster(type) {
if (type == "kmeans") {
// Get options
let k = get_value("k", 3, 1, 32);
let dist = get_select_list("dist", 0);
let init = get_select_list("init", 1);
let seed = get_value("seed", 42, 0, 10000);
let cl = new KMeans(k, dist, init, seed);
return cl;
}
else if (type == "dbscan") {
// Get options
let eps = get_value("eps", 0.2, 0.01, 100, parseFloat);
let min_pts = get_value("minpts", 5, 2, 100);
let dist = get_select_list("dist", 0);
let cl = new DBScan(eps, min_pts, dist);
return cl;
}
else if (type == "meanshift") {
// Get options
let bw = get_value("bandwidth", 0.1, 0.05, 1, parseFloat);
let dist = get_select_list("dist", 0);
let w = get_select_list("weight", 0);
let cl = new MeanShift(bw, dist, w);
return cl;
}
else {
throw("Unknown clustering algorithm: " + type);
}
}
/** ------------------------------------------------------
Util functions for the VisualML demo.
--------------------------------------------------------- */
// Is set to true if a classifier is running
var running = false;
/**
Shows the element with the specified id.
*/
function show(id) {
let e = document.getElementById(id);
if (e != null) {
e.style.display = "block";
}
}
/**
Hides the element with the specified id.
*/
function hide(id) {
let e = document.getElementById(id);
if (e != null) {
e.style.display = "none";
}
}
/**
Toggles visibility of the element with the specified id.
*/
function toggle(id) {
let e = document.getElementById(id);
if (e.style.display == "none") {
e.style.display = "block";
}
else {
e.style.display = "none";
}
}
/**
Toggles visibility of the element with the specified id and updates
expand arrow.
*/
function toggle_bt(id) {
let e = document.getElementById(id);
let bt = document.getElementById(id + "_bt");
if (e.style.display == "none") {
e.style.display = "block";
bt.innerHTML = "▼";
}
else {
e.style.display = "none";
bt.innerHTML = "►";
}
}
/**
Enables an element.
*/
function enable(id) {
let e = document.getElementById(id);
e.disabled = false;
e.className = "enabled";
}
/**
Disables an element.
*/
function disable(id, classid="disabled") {
let e = document.getElementById(id);
e.disabled = true;
e.className = classid;
}
/**
Returns the value of an input field as an integer array.
*/
function get_array(id, default_arr, conv_func=parseInt) {
let e = document.getElementById(id);
if (e == null) {
return default_arr;
}
let str = e.value;
let arr = str.split(",");
for (let i in arr) {
let val = arr[i];
val = val.trim();
arr[i] = conv_func(val);
if (isNaN(arr[i])) {
e.value = default_arr;
return default_arr;
}
}
return arr;
}
/**
Returns the integer value from an input field.
*/
function get_value(id, default_val, min_val, max_val, conv_func=parseInt) {
// Check if element is available
let e = document.getElementById(id);
if (e == null) {
return default_val;
}
let str = e.value;
str = str.trim();
let val = conv_func(str);
// Check if valid int
if (isNaN(val)) {
e.value = default_val;
val = default_val;
}
// Range check
if (val < min_val) {
val = min_val;
e.value = val;
}
if (val > max_val) {
val = max_val;
e.value = val;
}
return val;
}
/**
Returns the selected value in a dropdown list.
*/
function get_select_list(id, default_val) {
// Check if element is available
let e = document.getElementById(id);
if (e == null) {
return default_val;
}
// Get selected value
let val = e.options[e.selectedIndex].value;
return val;
}
/**
Returns the selected classifier.
*/
function get_selected_algorithm() {
// Dataset radio buttons
let name = ""
let rlist = document.getElementsByName("sel-cl");
for (let i = 0, length = rlist.length; i < length; i++) {
if (rlist[i].checked) {
name = rlist[i].value;
break;
}
}
return name;
}
/**
Returns the selected dataset.
*/
function get_selected_dataset() {
// Dataset radio buttons
let name = ""
let rlist = document.getElementsByName("sel-ds");
for (let i = 0, length = rlist.length; i < length; i++) {
if (rlist[i].checked) {
name = rlist[i].value;
break;
}
}
return name;
}
/**
Shows the settings for the selected classifier.
*/
function update_settings() {
let type = get_selected_algorithm();
let name = get_selected_dataset();
let settings = get_settings(type, name);
document.getElementById("opts").innerHTML = "";
let html = "<table><tr>";
if (type == "kmeans") {
html += "<td class='param'>Clusters:</td><td><input class='value' name='k' id='k' value='" + settings[0] + "'></td>";
html += "<td class='param'>Distance function:</td><td><select id='dist' class='value'><option value='0'>Euclidean</option><option value='1'>Manhattan</option><option value='2'>Chebyshev</option></select></td>";
html += "<td class='param'>Initialization:</td><td><select id='init' class='value'><option value='1'>K-Means++</option><option value='0'>Random</option></select></td>";
html += "<td class='param'>Seed:</td><td><input class='value' name='seed' id='seed' value='" + settings[1] + "'></td>";
html += "</tr><tr>";
html += "<td colspan='2' class='param'><input type='button' style='background-color: #d4e3cf;' onclick='javascript:optimize_k()' value='Find no clusters'></button></td>";
html += "<td colspan='6'>Find optimal number of clusters using silhouette score</td>";
}
else if (type == "dbscan") {
html += "<td class='param'>Epsilon:</td><td><input class='value' name='eps' id='eps' value='" + settings[0] + "'></td>";
html += "<td class='param'>Min samples:</td><td><input class='value' name='minpts' id='minpts' value='" + settings[1] + "'></td>";
html += "<td class='param'>Distance function:</td><td><select id='dist' class='value'><option value='0'>Euclidean</option><option value='1'>Manhattan</option><option value='2'>Chebyshev</option></select></td>";
}
else if (type == "meanshift") {
html += "<td class='param'>Bandwidth:</td><td><input class='value' name='bandwidth' id='bandwidth' value='" + settings[0] + "'></td>";
html += "<td class='param'>Distance function:</td><td><select id='dist' class='value'><option value='0'>Euclidean</option><option value='1'>Manhattan</option><option value='2'>Chebyshev</option></select></td>";
html += "<td class='param'>Weight:</td><td><select id='weight' class='value'><option value='1'>Gaussian Kernel</option><option value='0'>None</option></select></td>";
}
html += "</tr></table>";
document.getElementById("opts").innerHTML = html;
}
/**
Shows the dataset labels.
*/
function show_data() {
if (running) return;
clear();
data_name = get_selected_dataset();
orig_data = get_dataset(data_name);
let opt = get_render_options(data_name);
draw_labels(orig_data, opt);
}
/**
Shows the library version in a html "version" field.
*/
function show_version() {
document.getElementById("version").innerHTML = VERSION;
}
// Randomizer seed
var global_seed = 42;
// Original data
var orig_data = null;
// Dataset name
var data_name;
/**
Custom random function.
Built-in random has no seed feature. Instead a simple pseudo-random with seed is used.
See explanation here:
https://stackoverflow.com/questions/521295/seeding-the-random-number-generator-in-javascript
*/
function rnd() {
let x = Math.sin(global_seed++) * 10000;
return x - Math.floor(x);
}
/**
Random normally distributed using the Box-Muller transform.
See explanation here:
https://stackoverflow.com/questions/25582882/javascript-math-random-normal-distribution-gaussian-bell-curve
*/
function rnd_bm() {
let u = 0, v = 0;
while(u === 0) u = rnd(); //Converting [0,1) to (0,1)
while(v === 0) v = rnd();
let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
num = num / 10.0 + 0.5; // Translate to 0 -> 1
if (num > 1 || num < 0) return rnd_bm(); // resample between 0 and 1
return num;
}
/**
Dictionary get function.
*/
function get(dict, key) {
key += "";
for (let i = 0; i < dict.length; i++) {
if (dict[i].key == key) {
return dict[i].value;
}
}
return null;
}
/** ------------------------------------------------------
Datasets used in the VisualML demo.
--------------------------------------------------------- */
/**
Spiral dataset.
*/
function get_spiral() {
let spiral_x = [
[ 0.000, 0.000], [ 0.001, 0.010], [ 0.006, 0.019], [ 0.016, 0.026], [ 0.021, 0.035], [ 0.000, 0.051], [ 0.025, 0.055], [ 0.018, 0.068],
[ 0.024, 0.077], [ 0.039, 0.082], [ 0.042, 0.092], [ 0.075, 0.082], [ 0.072, 0.097], [ 0.069, 0.112], [ 0.086, 0.112], [ 0.094, 0.118],
[ 0.131, 0.095], [ 0.103, 0.137], [ 0.129, 0.128], [ 0.108, 0.159], [ 0.059, 0.193], [ 0.176, 0.118], [ 0.194, 0.108], [ 0.164, 0.165],
[ 0.240, 0.036], [ 0.166, 0.190], [ 0.229, 0.128], [ 0.237, 0.135], [ 0.280, 0.037], [ 0.291, 0.031], [ 0.287, 0.098], [ 0.304, 0.075],
[ 0.290, 0.142], [ 0.269, 0.197], [ 0.331, 0.090], [ 0.351, 0.044], [ 0.361,-0.047], [ 0.369,-0.061], [ 0.381, 0.043], [ 0.393, 0.022],
[ 0.399, 0.066], [ 0.406, 0.082], [ 0.414, 0.091], [ 0.369,-0.230], [ 0.442,-0.047], [ 0.449,-0.072], [ 0.464,-0.017], [ 0.420,-0.221],
[ 0.484,-0.022], [ 0.462,-0.177], [ 0.487,-0.135], [ 0.434,-0.277], [ 0.478,-0.218], [ 0.506,-0.176], [ 0.449,-0.310], [ 0.411,-0.373],
[ 0.431,-0.367], [ 0.404,-0.410], [ 0.468,-0.353], [ 0.440,-0.402], [ 0.456,-0.399], [ 0.419,-0.451], [ 0.449,-0.437], [ 0.514,-0.375],
[ 0.321,-0.561], [ 0.368,-0.543], [ 0.479,-0.464], [ 0.227,-0.638], [ 0.374,-0.576], [ 0.235,-0.656], [ 0.118,-0.697], [ 0.175,-0.695],
[ 0.003,-0.727], [ 0.313,-0.667], [ 0.053,-0.746], [ 0.186,-0.734], [ 0.186,-0.745], [ 0.113,-0.769], [ 0.041,-0.787], [-0.049,-0.796],
[ 0.115,-0.800], [-0.251,-0.779], [-0.217,-0.799], [ 0.080,-0.835], [-0.443,-0.723], [-0.534,-0.672], [-0.468,-0.732], [-0.291,-0.829],
[-0.176,-0.871], [-0.555,-0.707], [-0.366,-0.832], [-0.646,-0.654], [-0.538,-0.758], [-0.681,-0.647], [-0.632,-0.709], [-0.713,-0.642],
[-0.653,-0.717], [-0.888,-0.414], [-0.739,-0.658], [-0.807,-0.591], [-0.000,-0.000], [-0.006,-0.008], [-0.013,-0.016], [-0.028,-0.012],
[-0.029,-0.029], [-0.050,-0.006], [-0.052,-0.032], [-0.059,-0.039], [-0.081,-0.000], [-0.091,-0.005], [-0.101, 0.007], [-0.111,-0.010],
[-0.112,-0.047], [-0.129, 0.025], [-0.139,-0.028], [-0.151, 0.008], [-0.160, 0.020], [-0.171,-0.010], [-0.180, 0.025], [-0.186, 0.046],
[-0.199, 0.034], [-0.211,-0.018], [-0.216, 0.052], [-0.206, 0.108], [-0.241, 0.029], [-0.244, 0.067], [-0.254, 0.065], [-0.200, 0.186],
[-0.241, 0.149], [-0.251, 0.151], [-0.285, 0.103], [-0.250, 0.189], [-0.292, 0.139], [-0.270, 0.196], [-0.296, 0.175], [-0.237, 0.263],
[-0.238, 0.275], [-0.276, 0.252], [-0.238, 0.301], [-0.315, 0.237], [-0.332, 0.230], [-0.212, 0.355], [-0.223, 0.361], [-0.177, 0.397],
[-0.013, 0.444], [-0.124, 0.437], [-0.265, 0.382], [-0.076, 0.469], [-0.277, 0.398], [-0.191, 0.457], [-0.138, 0.486], [ 0.062, 0.511],
[-0.171, 0.497], [-0.162, 0.510], [-0.066, 0.541], [-0.107, 0.545], [ 0.115, 0.554], [-0.112, 0.565], [-0.099, 0.577], [ 0.008, 0.596],
[ 0.025, 0.606], [ 0.331, 0.520], [ 0.251, 0.574], [ 0.176, 0.612], [ 0.037, 0.645], [ 0.322, 0.572], [ 0.122, 0.655], [ 0.078, 0.672],
[ 0.443, 0.525], [ 0.375, 0.587], [ 0.471, 0.527], [ 0.434, 0.571], [ 0.520, 0.508], [ 0.377, 0.634], [ 0.358, 0.656], [ 0.586, 0.481],
[ 0.450, 0.622], [ 0.495, 0.600], [ 0.553, 0.562], [ 0.631, 0.488], [ 0.622, 0.516], [ 0.536, 0.618], [ 0.649, 0.514], [ 0.491, 0.680],
[ 0.801, 0.279], [ 0.634, 0.579], [ 0.717, 0.491], [ 0.832, 0.283], [ 0.802, 0.384], [ 0.898,-0.045], [ 0.808, 0.417], [ 0.912, 0.114],
[ 0.920, 0.134], [ 0.889, 0.304], [ 0.948,-0.046], [ 0.958, 0.048], [ 0.954,-0.173], [ 0.954,-0.223], [ 0.850,-0.507], [ 0.916,-0.402],
[ 0.000,-0.000], [ 0.010,-0.001], [ 0.018,-0.009], [ 0.028,-0.012], [ 0.037,-0.017], [ 0.050,-0.001], [ 0.056,-0.023], [ 0.068,-0.020],
[ 0.070,-0.041], [ 0.080,-0.043], [ 0.075,-0.068], [ 0.088,-0.068], [ 0.085,-0.086], [ 0.110,-0.072], [ 0.123,-0.071], [ 0.119,-0.094],
[ 0.114,-0.115], [ 0.106,-0.135], [ 0.044,-0.176], [ 0.119,-0.151], [ 0.146,-0.140], [ 0.128,-0.169], [ 0.131,-0.180], [ 0.090,-0.214],
[ 0.168,-0.175], [ 0.099,-0.232], [ 0.088,-0.247], [ 0.077,-0.262], [ 0.113,-0.259], [ 0.087,-0.280], [ 0.145,-0.266], [ 0.084,-0.302],
[ 0.077,-0.314], [ 0.003,-0.333], [ 0.096,-0.330], [-0.051,-0.350], [-0.117,-0.344], [ 0.126,-0.352], [-0.075,-0.377], [-0.111,-0.378],
[-0.026,-0.403], [-0.063,-0.409], [-0.103,-0.412], [-0.109,-0.421], [-0.128,-0.426], [-0.026,-0.454], [-0.286,-0.366], [-0.302,-0.366],
[-0.167,-0.455], [-0.128,-0.478], [-0.325,-0.386], [-0.256,-0.447], [-0.340,-0.400], [-0.325,-0.425], [-0.426,-0.341], [-0.447,-0.329],
[-0.361,-0.435], [-0.326,-0.475], [-0.332,-0.483], [-0.526,-0.280], [-0.418,-0.439], [-0.497,-0.364], [-0.513,-0.359], [-0.570,-0.283],
[-0.452,-0.462], [-0.621,-0.214], [-0.650,-0.148], [-0.652,-0.181], [-0.654,-0.210], [-0.685,-0.130], [-0.704,-0.062], [-0.557,-0.452],
[-0.694, 0.218], [-0.737, 0.024], [-0.741,-0.101], [-0.757,-0.033], [-0.756, 0.133], [-0.774, 0.072], [-0.763,-0.195], [-0.654, 0.457],
[-0.790, 0.172], [-0.725, 0.379], [-0.815, 0.148], [-0.660, 0.517], [-0.762, 0.373], [-0.727, 0.456], [-0.837, 0.232], [-0.636, 0.607],
[-0.681, 0.571], [-0.586, 0.682], [-0.791, 0.448], [-0.766, 0.508], [-0.352, 0.860], [-0.801, 0.491], [-0.678, 0.665], [-0.461, 0.842],
[-0.601, 0.761], [-0.496, 0.845], [-0.628, 0.766], [-0.473, 0.881]
];
let data = new Dataset(spiral_x);
return data;
}
/**
Flame dataset.
*/
function get_flame() {
let flame_x = [
[0.123,0.273], [0.090,0.312], [0.093,0.425], [0.057,0.432], [0.033,0.455], [0.043,0.488], [0.073,0.465], [0.090,0.445],
[0.130,0.440], [0.160,0.452], [0.120,0.467], [0.167,0.472], [0.197,0.487], [0.127,0.492], [0.090,0.485], [0.090,0.503],
[0.083,0.522], [0.117,0.532], [0.133,0.513], [0.167,0.500], [0.113,0.565], [0.160,0.532], [0.203,0.518], [0.247,0.518],
[0.230,0.537], [0.197,0.550], [0.160,0.553], [0.160,0.592], [0.190,0.575], [0.217,0.565], [0.263,0.547], [0.180,0.607],
[0.230,0.598], [0.253,0.582], [0.267,0.563], [0.297,0.537], [0.310,0.562], [0.323,0.585], [0.287,0.598], [0.223,0.623],
[0.247,0.657], [0.293,0.635], [0.283,0.620], [0.320,0.612], [0.350,0.592], [0.383,0.582], [0.353,0.558], [0.403,0.548],
[0.433,0.570], [0.403,0.593], [0.373,0.607], [0.363,0.628], [0.337,0.648], [0.303,0.665], [0.330,0.685], [0.390,0.707],
[0.373,0.690], [0.377,0.667], [0.397,0.640], [0.417,0.653], [0.407,0.618], [0.440,0.612], [0.443,0.590], [0.487,0.588],
[0.523,0.590], [0.477,0.607], [0.507,0.610], [0.447,0.625], [0.487,0.625], [0.447,0.640], [0.487,0.645], [0.450,0.657],
[0.493,0.660], [0.437,0.675], [0.490,0.673], [0.453,0.702], [0.497,0.697], [0.457,0.718], [0.507,0.713], [0.570,0.712],
[0.547,0.683], [0.527,0.663], [0.537,0.650], [0.520,0.633], [0.533,0.618], [0.560,0.597], [0.577,0.608], [0.593,0.630],
[0.560,0.630], [0.577,0.645], [0.563,0.665], [0.590,0.688], [0.640,0.690], [0.610,0.667], [0.680,0.667], [0.633,0.645],
[0.717,0.647], [0.697,0.627], [0.657,0.630], [0.627,0.613], [0.677,0.610], [0.657,0.595], [0.603,0.592], [0.620,0.577],
[0.610,0.562], [0.567,0.573], [0.777,0.618], [0.740,0.612], [0.693,0.592], [0.667,0.568], [0.797,0.592], [0.750,0.587],
[0.707,0.570], [0.743,0.567], [0.793,0.572], [0.840,0.570], [0.787,0.552], [0.737,0.552], [0.687,0.553], [0.660,0.542],
[0.697,0.533], [0.870,0.537], [0.833,0.542], [0.793,0.532], [0.747,0.525], [0.723,0.505], [0.760,0.492], [0.780,0.513],
[0.820,0.518], [0.863,0.515], [0.837,0.502], [0.803,0.492], [0.783,0.463], [0.817,0.472], [0.853,0.483], [0.903,0.500],
[0.907,0.480], [0.863,0.467], [0.833,0.458], [0.813,0.438], [0.847,0.422], [0.867,0.443], [0.903,0.460], [0.937,0.458],
[0.947,0.432], [0.940,0.413], [0.900,0.440], [0.890,0.417], [0.887,0.400], [0.487,0.562], [0.530,0.555], [0.513,0.532],
[0.450,0.537], [0.350,0.522], [0.410,0.510], [0.467,0.510], [0.507,0.493], [0.570,0.513], [0.623,0.517], [0.553,0.485],
[0.527,0.480], [0.477,0.475], [0.447,0.490], [0.347,0.497], [0.413,0.468], [0.450,0.453], [0.410,0.450], [0.377,0.460],
[0.310,0.448], [0.273,0.418], [0.357,0.440], [0.493,0.447], [0.517,0.463], [0.567,0.457], [0.620,0.467], [0.647,0.435],
[0.587,0.435], [0.537,0.437], [0.507,0.428], [0.457,0.433], [0.413,0.425], [0.380,0.420], [0.340,0.415], [0.303,0.395],
[0.367,0.400], [0.407,0.398], [0.433,0.413], [0.450,0.402], [0.487,0.408], [0.553,0.420], [0.593,0.410], [0.637,0.412],
[0.690,0.397], [0.530,0.398], [0.263,0.387], [0.250,0.358], [0.260,0.335], [0.303,0.312], [0.350,0.308], [0.433,0.280],
[0.497,0.280], [0.557,0.288], [0.617,0.293], [0.663,0.317], [0.703,0.347], [0.660,0.368], [0.613,0.383], [0.570,0.393],
[0.587,0.373], [0.613,0.355], [0.637,0.332], [0.603,0.313], [0.587,0.340], [0.543,0.322], [0.537,0.340], [0.557,0.360],
[0.527,0.357], [0.537,0.377], [0.487,0.387], [0.503,0.372], [0.457,0.385], [0.417,0.378], [0.370,0.383], [0.310,0.363],
[0.333,0.348], [0.370,0.330], [0.370,0.358], [0.413,0.360], [0.453,0.365], [0.493,0.358], [0.443,0.352], [0.410,0.340],
[0.433,0.330], [0.440,0.313], [0.513,0.312], [0.500,0.327], [0.500,0.345], [0.470,0.338], [0.460,0.295], [0.410,0.303]
];
let data = new Dataset(flame_x);
return data;
}
/**
Moons dataset.
*/
function get_moons() {
let moons_x = [
[0.285,0.684], [0.500,0.694], [0.350,0.548], [0.210,0.742], [0.377,0.710], [0.817,0.385], [0.382,0.420], [0.951,0.495],
[0.054,0.599], [0.059,0.514], [0.837,0.315], [0.060,0.473], [0.371,0.696], [0.411,0.755], [0.520,0.257], [0.190,0.691],
[0.210,0.680], [0.665,0.470], [0.712,0.252], [0.395,0.475], [0.348,0.395], [0.573,0.538], [0.429,0.669], [0.067,0.486],
[0.034,0.581], [0.436,0.648], [0.857,0.478], [0.631,0.300], [0.920,0.446], [0.667,0.552], [0.480,0.700], [0.472,0.325],
[0.210,0.678], [0.482,0.338], [0.807,0.314], [0.450,0.321], [0.615,0.542], [0.046,0.620], [0.095,0.577], [0.830,0.374],
[0.749,0.262], [0.780,0.394], [0.646,0.460], [0.493,0.664], [0.843,0.307], [0.447,0.350], [0.631,0.586], [0.341,0.442],
[0.724,0.334], [0.934,0.472], [0.125,0.578], [0.148,0.642], [0.520,0.651], [0.730,0.310], [0.165,0.665], [0.506,0.684],
[0.063,0.556], [0.420,0.403], [0.389,0.453], [0.009,0.428], [0.643,0.502], [0.538,0.645], [0.067,0.545], [0.444,0.400],
[0.448,0.716], [0.960,0.437], [0.155,0.609], [0.446,0.369], [0.916,0.440], [0.883,0.532], [0.059,0.448], [0.909,0.450],
[0.544,0.282], [0.497,0.312], [0.606,0.495], [0.154,0.600], [0.740,0.339], [0.709,0.271], [0.234,0.759], [0.859,0.409],
[0.883,0.478], [0.151,0.631], [0.580,0.545], [0.515,0.354], [0.260,0.676], [0.742,0.283], [0.361,0.429], [0.360,0.511],
[0.607,0.600], [0.045,0.407], [0.527,0.585], [0.118,0.503], [0.332,0.542], [0.531,0.674], [0.370,0.532], [0.642,0.303],
[0.092,0.452], [0.853,0.351], [0.114,0.571], [0.496,0.639], [0.573,0.289], [0.092,0.650], [0.363,0.653], [0.071,0.477],
[0.432,0.760], [0.800,0.308], [0.323,0.724], [0.054,0.519], [0.339,0.484], [0.152,0.641], [0.091,0.487], [0.185,0.703],
[0.085,0.552], [0.601,0.533], [0.288,0.726], [0.448,0.288], [0.635,0.425], [0.841,0.425], [0.460,0.711], [0.165,0.633],
[0.208,0.637], [0.185,0.643], [0.075,0.526], [0.795,0.270], [0.047,0.457], [0.609,0.294], [0.086,0.513], [0.332,0.712],
[0.331,0.565], [0.260,0.715], [0.058,0.570], [0.591,0.188], [0.613,0.418], [0.321,0.387], [0.605,0.516], [0.882,0.516],
[0.933,0.556], [0.690,0.507], [0.435,0.320], [0.311,0.714], [0.620,0.553], [0.642,0.491], [0.553,0.268], [0.220,0.669],
[0.885,0.356], [0.094,0.506], [0.381,0.733], [0.047,0.539], [0.589,0.626], [0.259,0.738], [0.652,0.293], [0.094,0.624],
[0.911,0.552], [0.392,0.680], [0.059,0.453], [0.167,0.595], [0.491,0.316], [0.536,0.290], [0.650,0.497], [0.552,0.350],
[0.890,0.474], [0.642,0.297], [0.126,0.638], [0.269,0.689], [0.753,0.268], [0.675,0.266], [0.042,0.419], [0.418,0.399],
[0.463,0.702], [0.747,0.306], [0.412,0.378], [0.066,0.575], [0.564,0.652], [0.858,0.359], [0.367,0.460], [0.671,0.405],
[0.571,0.545], [0.214,0.729], [0.692,0.311], [0.688,0.470], [0.879,0.353], [0.312,0.599], [0.957,0.519], [0.383,0.367],
[0.847,0.390], [0.664,0.298], [0.012,0.472], [0.430,0.367], [0.671,0.274], [0.817,0.341], [0.077,0.452], [0.651,0.253],
[0.484,0.682], [0.908,0.619], [0.574,0.599], [0.346,0.479], [0.853,0.396], [0.648,0.293], [0.955,0.512], [0.802,0.267],
[0.057,0.386], [0.516,0.326], [0.634,0.246], [0.114,0.627], [0.290,0.684], [0.904,0.339], [0.377,0.731], [0.187,0.661],
[0.390,0.443], [0.338,0.704], [0.426,0.373], [0.932,0.536], [0.360,0.476], [0.544,0.319], [0.406,0.388], [0.591,0.241],
[0.220,0.689], [0.660,0.439], [0.850,0.354], [0.414,0.388], [0.908,0.516], [0.468,0.338], [0.583,0.246], [0.592,0.551],
[0.927,0.571], [0.012,0.444], [0.308,0.478], [0.597,0.617], [0.799,0.366], [0.926,0.373], [0.100,0.613], [0.395,0.723],
[0.631,0.549], [0.847,0.448], [0.424,0.670], [0.433,0.331], [0.543,0.637], [0.593,0.319], [0.076,0.519], [0.416,0.680],
[0.766,0.335], [0.504,0.572], [0.092,0.579], [0.350,0.532], [0.476,0.671], [0.620,0.644], [0.936,0.491], [0.334,0.532],
[0.515,0.328], [0.885,0.472], [0.307,0.734], [0.075,0.528], [0.101,0.539], [0.651,0.193], [0.583,0.588], [0.508,0.292],
[0.923,0.506], [0.404,0.318], [0.054,0.441], [0.413,0.358], [0.725,0.246], [0.615,0.504], [0.539,0.298], [0.098,0.523],
[0.383,0.548], [0.508,0.654], [0.428,0.390], [0.289,0.716], [0.888,0.429], [0.146,0.573], [0.117,0.572], [0.543,0.260],
[0.483,0.303], [0.495,0.656], [0.315,0.694], [0.804,0.301], [0.328,0.554], [0.675,0.278], [0.434,0.700], [0.665,0.313],
[0.350,0.663], [0.555,0.597], [0.644,0.288], [0.373,0.717], [0.450,0.636], [0.928,0.621], [0.182,0.625], [0.374,0.698],
[0.541,0.577], [0.249,0.733], [0.354,0.585], [0.614,0.474], [0.404,0.504], [0.679,0.462], [0.526,0.596], [0.888,0.375],
[0.684,0.321], [0.840,0.394], [0.530,0.625], [0.242,0.665], [0.768,0.271], [0.377,0.511], [0.732,0.287], [0.508,0.291],
[0.233,0.660], [0.440,0.356], [0.678,0.412], [0.165,0.674], [0.586,0.605], [0.406,0.335], [0.850,0.497], [0.810,0.398],
[0.349,0.479], [0.357,0.755], [0.653,0.547], [0.896,0.515], [0.386,0.364], [0.738,0.275], [0.495,0.320], [0.610,0.568],
[0.305,0.532], [0.968,0.579], [0.823,0.286], [0.346,0.406], [0.225,0.654], [0.105,0.632], [0.900,0.576], [0.146,0.607],
[0.816,0.364], [0.520,0.639], [0.153,0.662], [0.180,0.708], [0.711,0.310], [0.746,0.329], [0.047,0.452], [0.491,0.679],
[0.402,0.715], [0.605,0.498], [0.955,0.509], [0.950,0.474], [0.072,0.460], [0.209,0.666], [0.337,0.731], [0.388,0.421],
[0.180,0.629], [0.906,0.413], [0.851,0.370], [0.123,0.579], [0.813,0.321], [0.863,0.401], [0.901,0.431], [0.667,0.231],
[0.969,0.503], [0.310,0.534], [0.592,0.281], [0.619,0.552], [0.420,0.724], [0.556,0.572], [0.468,0.687], [0.343,0.447],
[0.659,0.263], [0.563,0.669], [0.449,0.357], [0.407,0.421], [0.456,0.327], [0.269,0.667], [0.332,0.493], [0.702,0.293],
[0.294,0.744], [0.664,0.454], [0.508,0.631], [0.778,0.233], [0.523,0.320], [0.147,0.626], [0.365,0.453], [0.618,0.288],
[0.119,0.629], [1.000,0.565], [0.662,0.424], [0.615,0.500], [0.855,0.337], [0.775,0.308], [0.493,0.707], [0.159,0.609],
[0.874,0.427], [0.962,0.553], [0.853,0.413], [0.939,0.451], [0.733,0.329], [0.928,0.562], [0.285,0.699], [0.818,0.337],
[0.635,0.425], [0.828,0.353], [0.899,0.377], [0.426,0.351], [0.862,0.457], [0.451,0.305], [0.591,0.300], [0.841,0.364],
[0.070,0.429], [0.875,0.354], [0.337,0.611], [0.245,0.693], [0.573,0.555], [0.404,0.394], [0.615,0.447], [0.358,0.435],
[0.395,0.685], [0.612,0.605], [0.243,0.707], [0.428,0.365], [0.835,0.419], [0.584,0.233], [0.385,0.706], [0.980,0.495],
[1.000,0.482], [0.508,0.635], [0.368,0.439], [0.515,0.727], [0.605,0.602], [0.132,0.637], [0.476,0.669], [0.660,0.253],
[0.580,0.273], [0.796,0.330], [0.656,0.326], [0.000,0.525], [0.633,0.576], [0.380,0.752], [0.074,0.582], [0.438,0.344],
[0.496,0.659], [0.064,0.437], [0.433,0.723], [0.617,0.273], [0.228,0.729], [0.293,0.671], [0.330,0.523], [0.578,0.434],
[0.144,0.667], [0.107,0.607], [0.370,0.331], [0.300,0.762], [0.958,0.477], [0.420,0.396], [0.111,0.500], [0.492,0.681],
[0.895,0.482], [0.447,0.736], [0.523,0.293], [0.569,0.690], [0.400,0.480], [0.539,0.240], [0.215,0.710], [0.292,0.736],
[0.162,0.649], [0.519,0.351], [0.869,0.369], [0.175,0.579], [0.312,0.707], [0.650,0.444], [0.214,0.688], [0.539,0.658],
[0.388,0.384], [0.398,0.361], [0.444,0.680], [0.283,0.728], [0.469,0.714], [0.621,0.558], [0.581,0.330], [0.759,0.317],
[0.604,0.564], [0.611,0.507], [0.635,0.547], [0.362,0.678], [0.390,0.732], [0.420,0.467], [0.082,0.535], [0.617,0.254],
[0.080,0.504], [0.425,0.445], [0.491,0.353], [0.842,0.405], [0.387,0.501], [0.137,0.607], [0.310,0.726], [0.622,0.279],
[0.699,0.552], [0.721,0.263], [0.756,0.356], [0.594,0.264], [0.590,0.599], [0.451,0.389], [0.322,0.540], [0.193,0.734],
[0.636,0.479], [0.348,0.401], [0.550,0.308], [0.400,0.470]
];
let data = new Dataset(moons_x);
return data;
}
/**
Gaussian dataset.
*/
function get_gaussian() {
let gaussian_x = [
[0.351,0.334], [0.282,0.315], [0.245,0.379], [0.373,0.209], [0.221,0.304], [0.384,0.295], [0.238,0.253], [0.246,0.111],
[0.103,0.187], [0.250,0.363], [0.234,0.119], [0.349,0.257], [0.352,0.175], [0.284,0.280], [0.282,0.305], [0.437,0.209],
[0.286,0.188], [0.216,0.258], [0.308,0.248], [0.331,0.278], [0.324,0.240], [0.111,0.214], [0.222,0.296], [0.316,0.238],
[0.321,0.398], [0.276,0.332], [0.107,0.369], [0.386,0.350], [0.295,0.313], [0.402,0.265], [0.322,0.293], [0.313,0.329],
[0.438,0.327], [0.305,0.104], [0.332,0.245], [0.252,0.211], [0.208,0.474], [0.295,0.330], [0.075,0.268], [0.088,0.389],
[0.290,0.358], [0.295,0.341], [0.296,0.371], [0.259,0.155], [0.370,0.158], [0.268,0.155], [0.220,0.097], [0.417,0.334],
[0.221,0.203], [0.233,0.124], [0.284,0.168], [0.154,0.316], [0.261,0.313], [0.309,0.270], [0.295,0.196], [0.354,0.334],
[0.215,0.344], [0.331,0.057], [0.327,0.232], [0.272,0.313], [0.161,0.239], [0.411,0.407], [0.271,0.187], [0.225,0.246],
[0.232,0.344], [0.281,0.262], [0.279,0.302], [0.248,0.167], [0.266,0.338], [0.222,0.192], [0.404,0.318], [0.410,0.274],
[0.155,0.292], [0.263,0.293], [0.334,0.295], [0.352,0.307], [0.165,0.386], [0.196,0.316], [0.238,0.147], [0.225,0.291],
[0.235,0.307], [0.255,0.339], [0.244,0.170], [0.202,0.188], [0.217,0.273], [0.306,0.383], [0.203,0.356], [0.285,0.337],
[0.305,0.324], [0.220,0.280], [0.318,0.116], [0.257,0.389], [0.178,0.337], [0.232,0.194], [0.196,0.376], [0.234,0.400],
[0.194,0.211], [0.195,0.097], [0.310,0.194], [0.129,0.170], [0.338,0.266], [0.228,0.265], [0.169,0.267], [0.289,0.289],
[0.291,0.261], [0.365,0.341], [0.324,0.241], [0.288,0.179], [0.193,0.156], [0.419,0.371], [0.361,0.261], [0.305,0.322],
[0.223,0.260], [0.355,0.387], [0.245,0.319], [0.291,0.336], [0.318,0.317], [0.336,0.383], [0.289,0.178], [0.190,0.405],
[0.318,0.234], [0.320,0.268], [0.097,0.154], [0.344,0.233], [0.296,0.329], [0.708,0.766], [0.495,0.616], [0.662,0.731],
[0.626,0.587], [0.718,0.621], [0.678,0.698], [0.529,0.707], [0.573,0.707], [0.759,0.639], [0.519,0.548], [0.667,0.550],
[0.640,0.611], [0.571,0.555], [0.661,0.621], [0.581,0.782], [0.782,0.571], [0.690,0.533], [0.656,0.657], [0.681,0.685],
[0.732,0.627], [0.717,0.621], [0.528,0.643], [0.617,0.682], [0.720,0.762], [0.682,0.614], [0.635,0.715], [0.641,0.594],
[0.779,0.754], [0.693,0.556], [0.733,0.526], [0.692,0.634], [0.713,0.598], [0.633,0.768], [0.696,0.720], [0.591,0.752],
[0.616,0.473], [0.791,0.643], [0.675,0.683], [0.596,0.779], [0.745,0.537], [0.659,0.552], [0.551,0.635], [0.587,0.738],
[0.700,0.725], [0.713,0.678], [0.659,0.747], [0.605,0.523], [0.625,0.820], [0.572,0.585], [0.554,0.709], [0.643,0.671],
[0.640,0.715], [0.724,0.727], [0.688,0.741], [0.572,0.642], [0.582,0.588], [0.669,0.701], [0.740,0.685], [0.682,0.705],
[0.636,0.808], [0.723,0.794], [0.591,0.504], [0.744,0.696], [0.682,0.751], [0.612,0.678], [0.682,0.575], [0.655,0.657],
[0.528,0.698], [0.689,0.680], [0.598,0.572], [0.492,0.747], [0.668,0.568], [0.614,0.628], [0.553,0.639], [0.755,0.777],
[0.609,0.658], [0.663,0.599], [0.742,0.684], [0.662,0.744], [0.573,0.696], [0.762,0.591], [0.676,0.683], [0.505,0.735],
[0.697,0.693], [0.594,0.689], [0.552,0.751], [0.650,0.799], [0.652,0.606], [0.615,0.738], [0.812,0.731], [0.682,0.513],
[0.725,0.608], [0.602,0.627], [0.757,0.681], [0.759,0.681], [0.650,0.726], [0.613,0.599], [0.654,0.544], [0.772,0.671],
[0.582,0.763], [0.657,0.431], [0.670,0.653], [0.617,0.523], [0.491,0.701], [0.709,0.685], [0.614,0.620], [0.709,0.659],
[0.730,0.643], [0.699,0.412], [0.592,0.813], [0.588,0.589], [0.626,0.628], [0.786,0.731], [0.540,0.611], [0.611,0.643],
[0.628,0.647], [0.584,0.429], [0.713,0.606], [0.707,0.447], [0.719,0.587], [0.675,0.606], [0.857,0.683], [0.719,0.805],
[0.656,0.623], [0.622,0.685], [0.080,0.590], [0.163,0.596], [0.202,0.620], [0.182,0.794], [0.363,0.430], [0.303,0.739],
[0.246,0.727], [0.311,0.741], [0.237,0.552], [0.407,0.621], [0.179,0.724], [0.180,0.568], [0.224,0.574], [0.063,0.689],
[0.265,0.649], [0.312,0.761], [0.284,0.881], [0.387,0.677], [0.303,0.638], [0.221,0.675], [0.216,0.623], [0.281,0.703],
[0.236,0.630], [0.380,0.620], [0.264,0.496], [0.358,0.657], [0.100,0.584], [0.282,0.654], [0.125,0.665], [0.270,0.629],
[0.243,0.770], [0.306,0.722], [0.310,0.768], [0.208,0.727], [0.343,0.448], [0.287,0.608], [0.271,0.575], [0.186,0.637],
[0.464,0.625], [0.222,0.736], [0.277,0.590], [0.424,0.788], [0.233,0.537], [0.413,0.550], [0.285,0.675], [0.231,0.625],
[0.332,0.519], [0.234,0.756], [0.445,0.698], [0.314,0.680], [0.231,0.714], [0.110,0.382], [0.374,0.548], [0.328,0.609],
[0.359,0.536], [0.113,0.648], [0.338,0.718], [0.298,0.504], [0.272,0.467], [0.172,0.740], [0.188,0.656], [0.413,0.817],
[0.169,0.640], [0.218,0.642], [0.118,0.663], [0.246,0.716], [0.318,0.518], [0.418,0.579], [0.298,0.603], [0.408,0.681],
[0.452,0.574], [0.210,0.709], [0.309,0.625], [0.276,0.741], [0.184,0.618], [0.334,0.776], [0.307,0.683], [0.416,0.647],
[0.228,0.601], [0.196,0.728], [0.234,0.586], [0.357,0.649], [0.357,0.733], [0.237,0.654], [0.139,0.806], [0.123,0.578],
[0.287,0.608], [0.205,0.525], [0.272,0.623], [0.493,0.616], [0.001,0.746], [0.151,0.816], [0.283,0.641], [0.080,0.679],
[0.333,0.566], [0.302,0.568], [0.232,0.510], [0.289,0.465], [0.068,0.392], [0.294,0.753], [0.311,0.604], [0.171,0.450],
[0.246,0.522], [0.272,0.409], [0.147,0.680], [0.240,0.709], [0.291,0.744], [0.367,0.849], [0.097,0.707], [0.407,0.626],
[0.307,0.614], [0.337,0.958], [0.411,0.439], [0.395,0.655], [0.182,0.776], [0.315,0.712], [0.035,0.654], [0.139,0.660],
[0.148,0.639], [0.355,0.472], [0.295,0.676], [0.224,0.684], [0.057,0.381], [0.150,0.567], [0.266,0.616], [0.591,0.243],
[0.714,0.310], [0.735,0.106], [0.562,0.270], [0.614,0.385], [0.574,0.236], [0.619,0.330], [0.640,0.360], [0.628,0.287],
[0.605,0.271], [0.690,0.206], [0.528,0.306], [0.583,0.163], [0.680,0.264], [0.467,0.250], [0.596,0.335], [0.609,0.190],
[0.672,0.371], [0.669,0.277], [0.779,0.256], [0.669,0.398], [0.563,0.331], [0.547,0.265], [0.564,0.213], [0.627,0.302],
[0.602,0.251], [0.512,0.190], [0.410,0.188], [0.619,0.294], [0.574,0.274], [0.614,0.305], [0.546,0.313], [0.639,0.189],
[0.730,0.320], [0.633,0.300], [0.740,0.353], [0.972,0.274], [0.712,0.398], [0.604,0.250], [0.792,0.166], [0.627,0.276],
[0.818,0.278], [0.624,0.297], [0.483,0.335], [0.537,0.253], [0.602,0.226], [0.763,0.251], [0.549,0.334], [0.790,0.237],
[0.771,0.301], [0.678,0.203], [0.628,0.171], [0.615,0.208], [0.535,0.145], [0.730,0.262], [0.442,0.180], [0.605,0.218],
[0.558,0.367], [0.800,0.220], [0.702,0.305], [0.675,0.162], [0.443,0.226], [0.659,0.311], [0.715,0.392], [0.556,0.107],
[0.580,0.177], [0.635,0.272], [0.709,0.342], [0.640,0.237], [0.522,0.366], [0.416,0.284], [0.710,0.317], [0.598,0.166],
[0.656,0.088], [0.641,0.204], [0.627,0.226], [0.627,0.139], [0.705,0.248], [0.709,0.290], [0.565,0.382], [0.485,0.410],
[0.793,0.366], [0.680,0.371], [0.544,0.205], [0.711,0.306], [0.691,0.233], [0.693,0.283], [0.726,0.295], [0.915,0.283],
[0.594,0.174], [0.641,0.179], [0.656,0.250], [0.706,0.365], [0.815,0.273], [0.648,0.311], [0.608,0.352], [0.760,0.314],
[0.799,0.322], [0.640,0.235], [0.643,0.165], [0.581,0.353], [0.790,0.234], [0.656,0.406], [0.627,0.361], [0.730,0.364],
[0.547,0.364], [0.519,0.358], [0.614,0.143], [0.493,0.135], [0.457,0.188], [0.768,0.354], [0.692,0.243], [0.677,0.164],
[0.734,0.323], [0.819,0.288], [0.792,0.251], [0.670,0.284], [0.591,0.243], [0.769,0.191], [0.597,0.186], [0.704,0.301],
[0.484,0.111], [0.618,0.156], [0.714,0.281], [0.695,0.351]
];
let data = new Dataset(gaussian_x);
return data;
}
/**
Blobs dataset.
*/
function get_blobs() {
let blobs_x = [
[0.359,0.691], [0.567,0.500], [0.917,0.286], [0.649,0.455], [0.577,0.581], [0.180,0.643], [0.885,0.413], [0.851,0.368],
[0.140,0.688], [0.598,0.434], [0.668,0.445], [0.090,0.645], [0.149,0.725], [0.512,0.709], [0.390,0.286], [0.826,0.331],
[0.411,0.283], [0.625,0.402], [0.545,0.694], [0.513,0.600], [0.047,0.739], [0.644,0.431], [0.827,0.333], [0.105,0.671],
[0.629,0.403], [0.103,0.727], [0.607,0.378], [0.864,0.425], [0.065,0.688], [0.171,0.754], [0.633,0.441], [0.471,0.641],
[0.598,0.326], [0.924,0.340], [0.121,0.697], [0.441,0.188], [0.107,0.656], [0.844,0.392], [0.517,0.688], [0.625,0.449],
[0.877,0.364], [0.587,0.376], [0.672,0.419], [0.620,0.405], [0.135,0.682], [0.880,0.378], [0.585,0.386], [0.605,0.438],
[0.136,0.762], [0.930,0.342], [0.961,0.406], [0.090,0.739], [0.884,0.379], [0.376,0.333], [0.115,0.682], [0.683,0.482],
[0.075,0.674], [0.655,0.420], [0.417,0.585], [0.121,0.719], [0.422,0.339], [0.623,0.480], [0.873,0.416], [0.467,0.232],
[0.640,0.400], [0.085,0.715], [0.546,0.441], [0.103,0.684], [0.838,0.469], [0.867,0.335], [0.154,0.649], [0.116,0.685],
[0.378,0.307], [0.456,0.283], [0.111,0.674], [0.119,0.718], [0.391,0.201], [0.469,0.639], [0.628,0.416], [0.074,0.718],
[0.808,0.404], [0.682,0.430], [0.166,0.765], [0.805,0.413], [0.644,0.343], [0.415,0.294], [0.490,0.622], [0.618,0.400],
[0.423,0.237], [0.485,0.639], [0.628,0.449], [0.077,0.655], [0.464,0.674], [0.411,0.281], [0.873,0.365], [0.604,0.420],
[0.458,0.632], [0.625,0.388], [0.449,0.260], [0.491,0.739], [0.714,0.429], [0.371,0.309], [0.615,0.451], [0.088,0.720],
[0.110,0.760], [0.440,0.236], [0.096,0.721], [0.480,0.221], [0.410,0.257], [0.638,0.354], [0.148,0.722], [0.009,0.734],
[0.392,0.171], [0.535,0.574], [0.055,0.745], [0.910,0.332], [0.427,0.310], [0.459,0.670], [0.136,0.662], [0.148,0.665],
[0.498,0.269], [0.875,0.433], [0.470,0.621], [0.875,0.393], [0.653,0.434], [0.413,0.260], [0.680,0.379], [0.586,0.605],
[0.902,0.334], [0.397,0.649], [0.503,0.605], [0.719,0.424], [0.780,0.336], [0.834,0.371], [0.530,0.557], [0.387,0.250],
[0.074,0.622], [0.912,0.397], [0.395,0.255], [0.897,0.396], [0.975,0.372], [0.809,0.429], [0.595,0.425], [0.801,0.327],
[0.616,0.428], [0.533,0.615], [0.068,0.724], [0.116,0.729], [0.458,0.288], [0.717,0.423], [0.603,0.598], [0.124,0.659],
[0.131,0.695], [0.930,0.389], [0.506,0.635], [0.096,0.708], [0.553,0.604], [0.470,0.585], [0.087,0.754], [0.429,0.596],
[0.852,0.449], [0.109,0.665], [0.617,0.355], [0.625,0.373], [0.479,0.576], [0.911,0.419], [0.582,0.432], [0.618,0.406],
[0.863,0.381], [0.882,0.423], [0.590,0.572], [0.896,0.440], [0.435,0.251], [0.379,0.279], [0.149,0.619], [0.554,0.656],
[0.319,0.230], [0.067,0.667], [0.480,0.633], [0.147,0.687], [0.868,0.427], [0.396,0.284], [0.135,0.623], [0.610,0.517],
[0.128,0.741], [0.435,0.704], [0.623,0.464], [0.464,0.251], [0.904,0.390], [0.892,0.375], [0.332,0.295], [0.640,0.436],
[0.459,0.606], [0.579,0.454], [0.623,0.471], [0.933,0.414], [0.425,0.166], [0.450,0.690], [0.396,0.277], [0.109,0.685],
[0.607,0.385], [0.627,0.354], [0.862,0.398], [0.101,0.789], [0.587,0.643], [0.688,0.375], [0.124,0.644], [0.367,0.209],
[0.647,0.380], [0.433,0.352], [0.393,0.289], [0.487,0.497], [0.403,0.242], [0.517,0.626], [0.928,0.434], [0.075,0.649],
[0.112,0.735], [0.101,0.642], [0.419,0.328], [0.503,0.219], [0.602,0.468], [0.528,0.681], [0.041,0.756], [0.477,0.661],
[0.934,0.365], [0.361,0.239], [0.089,0.663], [0.113,0.691], [0.488,0.664], [0.048,0.700], [0.123,0.695], [0.139,0.689],
[0.637,0.356], [0.884,0.416], [0.613,0.536], [0.834,0.416], [0.796,0.348], [0.687,0.464], [0.871,0.407], [0.615,0.413],
[0.663,0.409], [0.379,0.218], [0.482,0.650], [0.073,0.668], [0.539,0.642], [0.912,0.400], [0.167,0.763], [0.630,0.400],
[0.501,0.629], [0.418,0.643], [0.158,0.702], [0.394,0.287], [0.930,0.447], [0.129,0.649], [0.418,0.300], [0.855,0.421],
[0.616,0.411], [0.819,0.372], [0.648,0.519], [0.087,0.727], [0.913,0.472], [0.402,0.210], [1.004,0.435], [0.437,0.673],
[0.389,0.310], [0.369,0.245], [0.946,0.337], [0.915,0.414], [0.610,0.454], [0.503,0.621], [0.568,0.457], [0.415,0.606],
[0.106,0.641], [0.142,0.767], [0.504,0.598], [0.316,0.231], [0.645,0.454], [0.090,0.693], [0.365,0.337], [0.442,0.230],
[0.921,0.410], [0.403,0.278], [0.636,0.446], [0.105,0.635], [0.439,0.697], [0.467,0.670], [0.438,0.598], [0.525,0.599],
[0.431,0.298], [0.403,0.199], [0.433,0.680], [0.665,0.454], [0.876,0.383], [0.618,0.422], [0.928,0.361], [0.623,0.383],
[0.604,0.384], [0.911,0.423], [0.117,0.766], [0.409,0.397], [0.542,0.614], [0.702,0.473], [0.809,0.333], [0.497,0.559],
[0.451,0.199], [0.309,0.276], [0.578,0.491], [0.515,0.746], [0.135,0.754], [0.391,0.260], [0.504,0.645], [0.678,0.448],
[0.708,0.425], [0.698,0.425], [0.449,0.596], [0.845,0.397], [0.862,0.403], [0.854,0.348], [0.474,0.607], [0.435,0.513],
[0.641,0.377], [0.366,0.298], [0.134,0.689], [0.642,0.453], [0.368,0.292], [0.097,0.741], [0.398,0.697], [0.499,0.616],
[0.407,0.195], [0.116,0.746], [0.450,0.655], [0.112,0.717], [0.410,0.307], [0.392,0.575], [0.443,0.603], [0.053,0.723],
[0.429,0.227], [0.476,0.656], [0.431,0.545], [0.390,0.265], [0.566,0.727], [0.447,0.240], [0.065,0.700], [0.114,0.747],
[0.431,0.690], [0.201,0.687], [0.966,0.302], [0.111,0.721], [0.396,0.298], [0.176,0.636], [0.509,0.462], [0.499,0.624],
[0.439,0.286], [0.477,0.651], [0.520,0.566], [0.848,0.378], [0.484,0.150], [0.375,0.348], [0.160,0.720], [0.433,0.291],
[0.399,0.269], [0.121,0.656], [0.381,0.223], [0.063,0.672], [0.618,0.409], [0.115,0.626], [0.588,0.489], [0.898,0.378],
[0.634,0.416], [0.905,0.316], [0.157,0.706], [0.431,0.225], [0.928,0.410], [0.069,0.794], [0.571,0.616], [0.544,0.369],
[0.794,0.368], [0.855,0.385], [0.893,0.396], [0.765,0.431], [0.440,0.702], [0.592,0.394], [0.456,0.568], [0.490,0.624],
[0.912,0.429], [0.854,0.430], [0.391,0.288], [0.431,0.325], [0.506,0.612], [0.859,0.422], [0.812,0.377], [0.419,0.273],
[0.939,0.487], [0.530,0.653], [0.152,0.717], [0.648,0.478], [0.528,0.578], [0.150,0.724], [0.930,0.421], [0.862,0.336],
[0.898,0.405], [0.397,0.336], [0.863,0.367], [0.391,0.268], [0.692,0.417], [0.842,0.319], [0.422,0.261], [0.861,0.371],
[0.673,0.476], [0.021,0.747], [0.587,0.422], [0.937,0.375], [0.485,0.582], [0.903,0.416], [0.640,0.414], [0.627,0.434],
[0.153,0.712], [0.106,0.761], [0.951,0.413], [0.846,0.456], [0.107,0.719], [0.345,0.307], [0.869,0.307], [0.583,0.400],
[0.486,0.418], [0.916,0.369], [0.441,0.330], [0.083,0.719], [0.611,0.501], [0.955,0.356], [0.411,0.288], [0.931,0.404],
[0.662,0.428], [0.473,0.677], [0.383,0.195], [0.585,0.659], [0.067,0.689], [0.880,0.359], [0.323,0.244], [0.074,0.706],
[0.348,0.355], [0.859,0.414], [0.680,0.457], [0.641,0.430], [0.890,0.292], [0.118,0.746], [0.718,0.414], [0.604,0.438],
[0.924,0.452], [0.501,0.626], [0.632,0.365], [0.649,0.468], [0.484,0.642], [0.659,0.340], [0.855,0.453], [0.133,0.646],
[0.515,0.626], [0.221,0.673], [0.116,0.677], [0.077,0.736], [0.611,0.443], [0.102,0.748], [0.920,0.347], [0.899,0.403],
[0.636,0.401], [0.913,0.396], [0.894,0.300], [0.597,0.438], [0.155,0.725], [0.665,0.424], [0.894,0.346], [0.427,0.281],
[0.082,0.766], [0.402,0.281], [0.897,0.339], [0.492,0.587], [0.614,0.422], [0.407,0.355], [0.960,0.412], [0.516,0.686],
[0.626,0.383], [0.511,0.675], [0.903,0.364], [0.458,0.622], [0.593,0.463], [0.569,0.680], [0.524,0.638], [0.458,0.573],
[0.631,0.420], [0.599,0.418], [0.492,0.682], [0.603,0.463], [0.166,0.649], [0.478,0.213], [0.654,0.448], [0.393,0.270],
[0.105,0.718], [0.486,0.196], [0.881,0.368], [0.926,0.286], [0.404,0.251], [0.497,0.258], [0.376,0.256], [0.333,0.242],
[0.077,0.637], [0.452,0.330], [0.968,0.331], [0.816,0.326], [0.865,0.390], [0.891,0.325], [0.389,0.259], [0.153,0.698],
[0.875,0.372], [0.438,0.224], [0.984,0.341], [0.478,0.715], [0.479,0.638], [0.471,0.626], [0.431,0.258], [0.163,0.682],
[0.621,0.379], [0.405,0.571], [0.104,0.705], [0.445,0.204], [0.670,0.450], [0.495,0.631], [0.222,0.747], [0.527,0.580],
[0.876,0.364], [0.598,0.468], [0.500,0.621], [0.166,0.784], [0.452,0.701], [0.493,0.628], [0.455,0.314], [0.501,0.625],
[0.827,0.338], [0.115,0.758], [0.409,0.311], [0.948,0.330], [0.832,0.376], [0.887,0.375], [0.478,0.657], [0.399,0.254],
[0.081,0.648], [0.482,0.613], [0.411,0.644], [0.674,0.397], [0.497,0.629], [0.475,0.604], [0.415,0.268], [0.437,0.260],
[0.601,0.401], [0.388,0.291], [0.159,0.741], [0.123,0.678], [0.500,0.641], [0.429,0.275], [0.898,0.360], [0.123,0.550],
[0.413,0.230], [0.059,0.673], [0.346,0.301], [0.142,0.779], [0.051,0.692], [0.167,0.730], [0.540,0.671], [0.648,0.484],
[0.415,0.235], [0.488,0.603], [0.588,0.367], [0.431,0.179], [0.401,0.291], [0.396,0.257], [0.498,0.664], [0.110,0.702],
[0.883,0.354], [0.551,0.394], [0.486,0.640], [0.144,0.663], [0.930,0.347], [0.095,0.676], [0.400,0.233], [0.125,0.734],
[0.449,0.679], [0.543,0.414], [0.595,0.515], [0.651,0.388], [0.437,0.572], [0.895,0.444], [0.940,0.340], [0.633,0.360],
[0.147,0.706], [0.481,0.537], [0.678,0.378], [0.375,0.181], [0.450,0.644], [0.323,0.291], [0.111,0.749], [0.186,0.635],
[0.867,0.405], [0.491,0.663], [0.454,0.270], [0.873,0.395], [0.898,0.367], [0.522,0.751], [0.470,0.600], [0.884,0.370],
[0.439,0.719], [0.422,0.669], [0.604,0.419], [0.523,0.693], [0.411,0.281], [0.630,0.408], [0.110,0.701], [0.127,0.697],
[0.440,0.618], [0.870,0.370], [0.430,0.225], [0.430,0.226], [0.391,0.240], [0.458,0.616], [0.406,0.250], [0.161,0.672],
[0.590,0.667], [0.662,0.423], [0.442,0.659], [0.505,0.606], [0.650,0.417], [0.915,0.339], [0.162,0.695], [0.440,0.325],
[0.572,0.599], [0.499,0.580], [0.135,0.613], [0.910,0.403], [0.070,0.705], [0.406,0.713], [0.874,0.401], [0.514,0.633],
[0.418,0.335], [0.077,0.709], [0.623,0.397], [0.509,0.659], [0.675,0.424], [0.440,0.284], [0.384,0.231], [0.396,0.223],
[0.408,0.275], [0.583,0.363], [0.966,0.313], [0.900,0.356], [0.601,0.467], [0.370,0.233], [0.898,0.368], [0.901,0.364],
[0.178,0.762], [0.226,0.722], [0.347,0.255], [0.463,0.639], [0.221,0.734], [0.405,0.291], [0.149,0.717], [0.373,0.281],
[0.900,0.331], [0.431,0.274], [0.640,0.384], [0.465,0.569], [0.517,0.594], [0.361,0.306], [0.398,0.325], [0.846,0.281],
[0.591,0.369], [0.430,0.308], [0.084,0.706], [0.101,0.612], [0.397,0.286], [0.548,0.580], [0.640,0.477], [0.467,0.569],
[0.093,0.723], [0.589,0.376], [0.501,0.254], [0.503,0.611], [0.876,0.360], [0.949,0.368], [0.388,0.311], [0.689,0.421],
[0.556,0.431], [0.435,0.205], [0.095,0.684], [0.603,0.486], [0.135,0.756], [0.837,0.352], [0.381,0.287], [0.744,0.352],
[0.398,0.210], [0.895,0.401], [0.550,0.618], [0.133,0.693], [0.629,0.402], [0.636,0.463], [0.840,0.428], [0.532,0.642],
[0.573,0.386], [0.948,0.381], [0.488,0.678], [0.386,0.240], [0.638,0.452], [0.559,0.645], [0.521,0.674], [0.639,0.418],
[0.870,0.398], [0.361,0.288], [0.453,0.216], [0.133,0.752], [0.130,0.695], [0.150,0.632], [0.132,0.722], [0.517,0.687],
[0.601,0.642], [0.445,0.676], [0.405,0.307], [0.904,0.370], [0.918,0.416], [0.846,0.330], [0.636,0.463], [0.863,0.360],
[0.399,0.280], [0.454,0.572], [0.646,0.454], [0.704,0.390], [0.930,0.316], [0.322,0.312], [0.587,0.351], [0.068,0.703],
[0.922,0.414], [0.864,0.366], [0.517,0.709], [0.614,0.448], [0.370,0.233], [0.395,0.239], [0.463,0.601], [0.372,0.359],
[0.625,0.497], [0.164,0.716], [0.877,0.327], [0.450,0.302], [0.465,0.715], [0.460,0.268], [0.418,0.238], [0.112,0.687],
[0.594,0.450], [0.096,0.682], [0.482,0.689], [0.514,0.560], [0.924,0.371], [0.555,0.526], [1.009,0.406], [0.658,0.427],
[0.393,0.195], [0.090,0.792], [0.081,0.668], [0.864,0.356], [0.779,0.357], [0.567,0.535], [0.502,0.636], [0.631,0.368],
[0.520,0.596], [0.522,0.552], [0.448,0.211], [0.430,0.275], [0.870,0.357], [0.934,0.348], [0.697,0.474], [0.151,0.652],
[0.186,0.735], [0.592,0.438], [0.134,0.614], [0.501,0.598], [0.499,0.648], [0.876,0.310], [0.866,0.321], [0.905,0.398],
[0.383,0.351], [0.330,0.208], [0.090,0.732], [0.456,0.333], [0.419,0.264], [0.109,0.658], [0.696,0.401], [0.674,0.436],
[0.406,0.273], [0.429,0.165], [0.670,0.506], [0.106,0.701], [0.650,0.406], [0.659,0.349], [0.835,0.374], [0.601,0.604]
];
let data = new Dataset(blobs_x);
return data;
}
/**
Returns the dataset with the specified name.
*/
function get_dataset(name) {
if (name == "spiral") {
return get_spiral();
}
else if (name == "flame") {
return get_flame();
}
else if (name == "moons") {
return get_moons();
}
else if (name == "gaussian") {
return get_gaussian();
}
else if (name == "blobs") {
return get_blobs();
}
else if (name == "circle") {
return get_circle();
}
else {
throw("Unknown dataset: " + name);
}
}
/**
Returns the render options for the specified dataset.
*/
function get_render_options(name) {
if (name == "spiral") {
return [2.2, 2.2, -1.1, -1.1];
}
else if (name == "flame") {
return [1.1, 1.1, -0.05, -0.05];
}
else if (name == "moons") {
return [1.1, 1.1, -0.05, -0.05];
}
else if (name == "circle") {
return [1.1, 1.1, -0.05, -0.05];
}
else if (name == "gaussian") {
return [1.1, 1.1, -0.05, -0.05];
}
else if (name == "blobs") {
return [1.1, 1.1, -0.05, -0.05];
}
else {
throw("Unknown dataset: " + name);
}
}
/**
Returns the size of rendered markers.
*/
function get_marker_size(type) {
if (type == "kmeans") {
return 9;
}
else if (type == "dbscan") {
return 5;
}
else if (type == "meanshift") {
return 5;
}
return 5;
}
/**
Returns the default hyperparameter settings for classifier and datasets combinations.
*/
function get_settings(type, name) {
if (type == "kmeans") {
if (name == "spiral") {
return [3, 42];
}
else if (name == "flame") {
return [2, 42];
}
else if (name == "moons") {
return [2, 42];
}
else if (name == "circle") {
return [2, 42];
}
else if (name == "gaussian") {
return [4, 42];
}
else if (name == "blobs") {
return [5, 3];
}
else {
return [3, 42];
}
}
else if (type == "dbscan") {
if (name == "spiral") {
return [0.12, 6];
}
else if (name == "flame") {
return [0.06, 10];
}
else if (name == "moons") {
return [0.05, 6];
}
else if (name == "gaussian") {
return [0.06, 7];
}
else if (name == "blobs") {
return [0.04, 6];
}
return [0.05, 6];
}
else if (type == "meanshift") {
if (name == "spiral") {
return [0.4];
}
else if (name == "gaussian") {
return [0.2];
}
return [0.1];
}
}
/** ------------------------------------------------------
Utility functions and classes for classifiers.
--------------------------------------------------------- */
/**
Holds a loaded and converted dataset.
*/
class Dataset {
// Constructor
constructor(x) {
this.x = x;
}
// Returns a copy of this dataset
clone() {
let nx = [];
// Copy all instances
for (let i = 0; i < this.no_examples(); i++) {
// Copy attributes of current instance
let e = this.x[i];
let new_e = [];
for (let a = 0; a < e.length; a++) {
new_e.push(e[a]);
}