cblearn.datasets.LinearSubspace#

class cblearn.datasets.LinearSubspace(subspace_dimension, space_dimension, random_state=None)[source]#

Linear Subspace

Linear Subspace is a class for creating a hyperplane of a given subspace dimension embedded in a higher dimensional space. It gives a method of generating synthetic points with intrinsic structure and dimensionality. The generated points are then meant to be used for generating ordinal data.

A reason for needing synthetically generated points is that it is often difficult to comprehensively evaluate the performance of ordinal methods on real data. Being able to modify the underlying geometry and structure of the data allows for better experimentation and control in evaluating ordinal methods.

This class inherits from the BaseManifold class. This class creates hyperplanes reproducibly using the scipy.stats.ortho_group function for a given random state. This class can sample points from the hyperplane using a given sampling function and add noise to the points using a given noise function.

Note

Subspace dimension must be less than or equal to space

dimension and space dimension must be greater than 1.

subspace_dimension#

Dimension of the subspace

space_dimension#

Dimension of the space

random_state#

Random state for reproducibility of the manifold

created#

Flag to check if the hyperplane has been created

basis#

Basis of the hyperplane

Examples

>>> from cblearn.datasets import LinearSubspace, make_random_triplet_indices, triplet_response
>>> # Creates a 1-dimensional hyperplane in 3-dimensional space
>>> manifold = LinearSubspace(subspace_dimension=1, space_dimension=3)
>>> # Samples 10 points from the created hyperplane
>>> points, distances = manifold.sample_points(num_points=10)
>>> print(points.shape)
(10, 3)
>>> print(distances.shape)
(10, 10)
>>> # Sampling 10 points with noise
>>> noisy_points, noisy_distances = manifold.sample_points(10, noise='normal', noise_options={'scale': 0.1})
>>> # Responding to triplets based on distance matrix
>>> triplets = make_random_triplet_indices(n_objects=10, size=100)
>>> response = triplet_response(triplets, distances, distance='precomputed')
__init__(subspace_dimension, space_dimension, random_state=None)[source]#

Initialize the manifold

Parameters:
  • subspace_dimension (int) – Dimension of the hyperplane

  • space_dimension (int) – Dimension of the space in which the hyperplane is embedded

  • random_state (None | int | RandomState) – The seed of the pseudo random number generator to use when sampling. If None, the random number generator is the RandomState instance used by np.random.

Methods

__init__(subspace_dimension, space_dimension)

Initialize the manifold

clone()

Clone the manifold

get_canonical_distance_matrix(points)

Get the distance matrix of the points sampled

get_params()

Get the parameters of the manifold

sample_points(num_points[, ...])

Sample points from the hyperplane and add noise if requested

set_params(params)

Set the parameters of the manifold

clone()#

Clone the manifold

Returns:

A clone of the manifold

get_canonical_distance_matrix(points)[source]#

Get the distance matrix of the points sampled

Parameters:

points (ndarray) – The points sampled from the hyperplane

Returns:

The distance matrix of the points sampled (num_points, num_points)

get_params()#

Get the parameters of the manifold

Returns:

The parameters of the manifold

sample_points(num_points, sampling_function='normal', sampling_options={'scale': 1}, noise=None, noise_options={}, random_state=None, return_distances=True)[source]#

Sample points from the hyperplane and add noise if requested

Parameters:
  • num_points (int) – Number of points to sample

  • sampling_function (str | Callable) – The sampling function to use. If a string, it should be a method of the random state object. If a callable, it should be a function that takes a size argument and returns a numpy array of samples.

  • sampling_options (Dict) – The options to pass to the sampling function.

  • noise (None | str | Callable) – The noise function to use. If a string, it should be a method of the random state object. If a callable, it should be a function that takes a size argument and returns a numpy array of samples.

  • noise_options (Dict) – The options to pass to the noise function.

  • random_state (None | int | RandomState) – The seed of the pseudo random number generator to use when sampling. If None, the random number generator is the RandomState instance used by np.random.

  • return_distances (bool) – Flag to return the distance matrix of the sampled points. Defaults to True.

Returns:

The sampled points. If return_distances is True, the distance matrix of the sampled points (num_points, num_points) is also returned.

set_params(params)#

Set the parameters of the manifold

Parameters:

set (The parameters to)