1+ """
2+ generate_twospirals(; n_samples::Int = 2000,
3+ start_degrees::Int = 90,
4+ total_degrees::Int = 570,
5+ noise::Float64 = 0.2
6+ Generate two spirals dataset. Return a Nx3 matrix, where each line contains the X,Y coordinates and the class of an instance.
7+ # Arguments
8+ - `n_samples::Int = 2000`: The total number of points generated.
9+ - `start_degrees::Int = 90`: Determines how far from the origin the spirals start.
10+ - `total_degrees::Int = 570`: Controls the lenght of the spirals.
11+ - `noise::Float64 = 0.2`: Determines the noise in the dataset.
12+ Reference: [link](https://la.mathworks.com/matlabcentral/fileexchange/41459-6-functions-for-generating-artificial-datasets)
13+ """
14+ function generate_twospirals (; n_samples:: Int = 2000 ,
15+ start_degrees:: Int = 90 ,
16+ total_degrees:: Int = 570 ,
17+ noise:: Float64 = 0.2 )
18+ start_degrees = deg2rad (start_degrees);
19+
20+ N1 = floor (Int, n_samples / 2 );
21+ N2 = n_samples - N1;
22+
23+ n = start_degrees .+ sqrt .(rand (N1,1 )) .* deg2rad (total_degrees);
24+ d1 = [- cos .(n).* n + rand (N1,1 ).* noise sin .(n).* n+ rand (N1,1 ).* noise];
25+
26+ n = start_degrees .+ sqrt .(rand (N2,1 )) .* deg2rad (total_degrees);
27+ d2 = [cos .(n).* n+ rand (N2,1 )* noise - sin .(n).* n+ rand (N2,1 )* noise];
28+
29+ features = [d1; d2]
30+ labels = [zeros (Int, N1); ones (Int, N1)]
31+
32+ return convert (features, labels);
33+ end
0 commit comments