qbiocode.data_generation.make_spheres module#

Generate synthetic concentric n-dimensional spheres datasets for binary classification.

This module creates multiple configurations of high-dimensional concentric spheres datasets with varying sample sizes, dimensionality, and radii, useful for testing machine learning algorithms on high-dimensional non-linearly separable data.

Summary#

Functions:

generate_points_in_nd_sphere

Generate random points within an n-dimensional spherical shell.

generate_spheres_datasets

Generate multiple concentric n-dimensional spheres datasets with varying parameters.

Reference#

generate_points_in_nd_sphere(n_s, dim=3, radius=1, thresh=0.9)[source]#

Generate random points within an n-dimensional spherical shell.

Parameters:
  • n_s (int) – Number of points to generate.

  • dim (int, default=3) – Dimensionality of the sphere.

  • radius (float, default=1) – Outer radius of the spherical shell.

  • thresh (float, default=0.9) – Inner radius threshold as fraction of outer radius (creates shell).

Returns:

points – Generated points within the spherical shell.

Return type:

ndarray of shape (n_s, dim)

generate_spheres_datasets(n_s=[100, 125, 150, 175, 200, 225, 250, 275], dim=[5, 10], radius=[5, 10, 15], save_path=None, random_state=42)[source]#

Generate multiple concentric n-dimensional spheres datasets with varying parameters.

Creates a series of high-dimensional datasets where samples form two concentric spherical shells, providing a challenging non-linearly separable binary classification problem in high dimensions. Each configuration varies the number of samples, dimensionality, and sphere radii.

Parameters:
  • n_s (list of int, default=range(100, 300, 25)) – List of sample sizes per class to generate for each configuration.

  • dim (list of int, default=range(5, 15, 5)) – List of dimensionalities for the spheres.

  • radius (list of float, default=range(5, 20, 5)) – List of outer sphere radii (inner sphere is 0.5 * outer radius).

  • save_path (str, optional) – Directory path where datasets and configuration files will be saved.

  • random_state (int, default=42) – Random seed for reproducibility.

Returns:

Saves CSV files for each dataset configuration and a JSON file with all configuration parameters.

Return type:

None

Notes

  • Each dataset is saved as ‘spheres_data-{i}.csv’ where i is the configuration number

  • Configuration parameters are saved in ‘dataset_config.json’

  • The last column ‘class’ contains binary labels (0 for outer, 1 for inner sphere)

  • Samples are generated in spherical shells (not solid spheres) for better separation

Examples

>>> from qbiocode.data_generation import generate_spheres_datasets
>>> generate_spheres_datasets(n_s=[100], dim=[5], radius=[10], save_path='data')
Generating spheres dataset...