BuildYourOwnEmbedding

Functional module

BuildYourOwnEmbedding.functional.cosine_similarity(x1: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], x2: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) number[source]

Computes the cosine similarity between two numpy arrays.

This function calculates the cosine similarity, between two input arrays, x1 and x2, and returns the result cast to the specified dtype. If the input arrays are not 1D, they are flattened and then the cosine similarity is computed.

Args:
x1 (npt.NDArray):

The first input array.

x2 (npt.NDArray):

The second input array.

dtype (npt.DTypeLike, optional):

The desired data type of the result. Defaults to np.float64.

Returns:

np.number: The cosine similarity between x1 and x2, cast to the specified dtype.

BuildYourOwnEmbedding.functional.euclidian_distance(x1: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], x2: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) number[source]

Computes the Euclidian distance between two numpy arrays.

This function calculates the Euclidian distance (L2 norm), between two input arrays, x1 and x2, and returns the result cast to the specified dtype.

Args:
x1 (npt.NDArray):

The first input array.

x2 (npt.NDArray):

The second input array.

dtype (npt.DTypeLike, optional):

The desired data type of the result. Defaults to np.float64.

Returns:

np.number: The Euclidian distance between x1 and x2, cast to the specified dtype.

BuildYourOwnEmbedding.functional.fisher_information(curves: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Calculates the Fisher Information for a set of tuning curves.

This function supports both 1-D and arbitrary-dimensional tuning curves

Args:

curves (npt.NDArray): A numpy array of the shape (numCurves, dim1, dim2, …, dimN) representing the tuning curves, where numCurves is the number of curves and dim1, dim2, …, dimN are the dimensions of each response.

Raises:

ValueError: If the dimensionality of curves is not greater than a 2-dimensional array.

Returns:

npt.NDArray: A numpy array representing the FI values, with shape (dim1, dim2, …, dimN) for the input curves.

BuildYourOwnEmbedding.functional.inverse_correlation(x1: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], x2: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) number[source]

Computes the inverse correlation between two numpy arrays.

This function calculates the inverse of the Pearson correlation coefficient between two input arrays, x1 and x2, and returns the result cast to the specified dtype.

Args:
x1 (npt.NDArray):

The first input array

x2 (npt.NDArray):

The second input array

dtype (npt.DTypeLike, optional):

The desired data type of the result. Defaults to np.float64.

Returns:

np.number: The inverse correlation coefficient between x1 and x2, cast to the specified dtype.

BuildYourOwnEmbedding.functional.manhattan_distance(x1: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], x2: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) number[source]

Computes the Manhattan distance between two numpy arrays.

This function calculates the Manhattan distance (L1 norm), between two input arrays, x1 and x2, and returns the result cast to the specified dtype.

Args:
x1 (npt.NDArray):

The first input array.

x2 (npt.NDArray):

The second input array.

dtype (npt.DTypeLike, optional):

The desired data type of the result. Defaults to np.float64.

Returns:

np.number: The Manhattan distance between x1 and x2, cast to the specified dtype.

BuildYourOwnEmbedding.functional.mds(dissimilarityMatrix: ndarray[Any, dtype[_ScalarType_co]], nComponents: int = 3) ndarray[Any, dtype[_ScalarType_co]][source]

Perform classical Multidimensional Scaling (MDS) on a dissimilarity matrix.

This function implements classical MDS, a technique for visualising the level of similarity of dissimilarity between sets of data. Given a square dissimilarity matrix, the function computes a low-dimensional embedding of the data by finding the eigenvectors and eigenvalues of the matrix, resulting in a set of coordinates that best preserve the pairwise distances in the original matrix.

This function implements an algorithm that follows these steps:

  1. Constructs a centreing matrix J and computes the double-centred matrix G.

  2. Calculates the eigenvalues and eigenvectors of G.

  3. Sorts the eignevectors based on their corresponding eigenvalues in descending order.

  4. Selects the top nComponents eigenvectors corresponding to the largest eigenvalues.

  5. Computes the coordinates of the points in the reduced dimensionality space.

Args:
dissimilarityMatrix (npt.NDArray):

A square matrix of shape (n, n) representing the dissimilarities between n samples. Each element at position (i, j) represents the dissimilarity between the i-th and j-th samples.

nComponents (int, optional):

The number of dimensions for the output embedding. Defaults to 3.

Returns:
npt.NDArray:

An array of shape (n, nComponents) containing the coordinates of the points in the reduced dimensionality space, where n is the number of samples and nComponents is the number of dimensions specified.

Example:
>>> dissimilarity_matrix = np.array([[0.0, 0.5, 0.2],
                                     [0.5, 0.0, 0.8],
                                     [0.2, 0.8, 0.0]])
>>> embedding = mds(dissimilarity_matrix, nComponents=2)
>>> print(embedding)
Raises:

ValueError: If dissimilarityMatrix is not a square matrix.

BuildYourOwnEmbedding.functional.mutual_information(response: ndarray[Any, dtype[_ScalarType_co]], stimulus: ndarray[Any, dtype[_ScalarType_co]]) number[source]

Computes the mutual information between a single neural response and its stimulus.

Args:

response (npt.NDArray): Neural response with shape (dim1, dim2, …, dimN). stimulus (npt.NDArray): Corresponding stimulus with shape (dim1, dim2, …, dimN).

Raises:

ValueError: If the stimulus and response are different dimensions.

Returns:

np.number: The mutual information between the response and the stimulus.

BuildYourOwnEmbedding.functional.pca(matrix: ndarray[Any, dtype[_ScalarType_co]], nComponents) ndarray[Any, dtype[_ScalarType_co]][source]

Computes the principal components of a given 2d matrix

Args:

matrix (npt.NDArray): A 2D array of the responses nComponents (_type_): The number of principal components to consider

Returns:

npt.NDArray: A n x nComponents array, containing the values of the principal components.

BuildYourOwnEmbedding.functional.pca_variance_explained(dissimilarityMatrix: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Computes PCA Variance Explained Ratios given a dissimilarity matrix.

Args:
dissimilarityMatrix (npt.NDArray):

A square matrix of shape (n, n) representing the dissimilarities between n samples. Each element at position (i, j) represents the dissimilarity between the i-th and j-th samples.

Returns:
npt.NDArray:

An array of shape n containing the PCA variance explained ratios of the samples in the input matrix.

BuildYourOwnEmbedding.functional.plot_rdm(rdm: ndarray[Any, dtype[_ScalarType_co]], labels: List[str] | None = None, cmap: str = 'viridis', title: str | None = None, figsize: Tuple[int] = (7, 7), dissimilarityLabel: str = 'Dissimilarity') None[source]

Plots a Representational Dissimilarity Matrix (RDM).

This function visualises a given RDM given as a square matrix that represents the pairwise dissimilarities between different data points or conditions. The function provides customisation options for colormap, title, axis labels, and figure size, allowing users to tailor the appearance of the plot.

Args:
rdm (npt.NDArray):

A 2D numpy array representing the RDM, where the element at position (i,j) indicates the dissimilarity between response i and response j.

labels (Union[List[str], None], optional):

A list of string labels for the x and y axes, corresponding to each data point. If None, the axes will be labeled with indices. Defaults to None.

cmap (str, optional):

The colormap used to display the RDM. The default colormap is “viridis”, but any valid Matplotlib colormap string can be used.

title (str, optional):

The title of the plot. If None, a default title “RDM of Tuning Curves” will be used.

figsize (Tuple[int], optional):

The size of the figure in inches, specified as a tuple (width, height). Defaults to (7, 7).

dissimilarityLabel (str, optional):

The label for the colorbar, indicating the metric used for dissimilarity. Defaults to “Dissimilarity”.

Parameters Module

class BuildYourOwnEmbedding.parameters.ConstantParameter(value: number)[source]

Bases: Parameter

Parameter class that always outputs a constant value.

get_values(dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Generates an array of the specified value for the parameter

Args:

dtype (np.DTypeLike, optional): The data type of the values in the output array. Defaults to np.float64.

Returns:

npt.NDArray: An array of size numSamples where all elements are the same value.

class BuildYourOwnEmbedding.parameters.FixedParameterSet(values: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]] | ~typing.List[~numpy.number], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>)[source]

Bases: Parameter

Parameter class for generating a fixed set of values.

get_values() ndarray[Any, dtype[_ScalarType_co]][source]

Generates an array of specified values for the parameter

Returns:

npt.NDArray: An array of specified parameter values

class BuildYourOwnEmbedding.parameters.LogRangeParameter(minValue: number, maxValue: number, numSamples: int)[source]

Bases: Parameter

Parameter class for generating a logarithmically scaling set of values within a range.

get_values(dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Generates a logarithmically spaced array of values for the parameter

Args:

dtype (np.DTypeLike, optional): The data type of the values in the output array. Defaults to np.float64.

Returns:

npt.NDArray: A logarithmically spaced numpy array of values

class BuildYourOwnEmbedding.parameters.Parameter(numSamples: int)[source]

Bases: ABC

Abstract base class for defining a parameter with a specific strategy to vary its value

abstract get_values() ndarray[Any, dtype[_ScalarType_co]][source]

Generates a list of values for this parameter. This method should be overriden in derived class to generate the output values.

Returns:

npt.NDArray: A list of parameter values

class BuildYourOwnEmbedding.parameters.RandomRangeParameter(minValue: number, maxValue: number, numSamples: int)[source]

Bases: Parameter

Parameter class for generating a random set of values within a range.

get_values(dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Generates a random array of values for the parameter

Args:

dtype (np.DTypeLike, optional): The data type of the values in the output array. Defaults to np.float64.

Returns:

npt.NDArray: A numpy array of random values

class BuildYourOwnEmbedding.parameters.UniformRangeParameter(minValue: number, maxValue: number, numSamples: int)[source]

Bases: Parameter

Parameter class for generating a uniform set of values within a range.

get_values(dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Generates a linearly spaced array of values for the parameter

Args:

dtype (np.DTypeLike, optional): The data type of the values in the output array. Defaults to np.float64.

Returns:

npt.NDArray: A linearly spaced numpy array of values

Responses module

class BuildYourOwnEmbedding.responses.CompositeResponse(response1: ResponseFunction, response2: ResponseFunction, operation: Callable[[ndarray[Any, dtype[_ScalarType_co]], ndarray[Any, dtype[_ScalarType_co]]], ndarray[Any, dtype[_ScalarType_co]]])[source]

Bases: ResponseFunction

Composite response class that combines two responses using a specified operation.

evaluate(x: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Evaluates the CompositeResponse for a given input stimuli.

Args:

x (npt.NDArray): The input stimuli for which to generate a response.

Returns:

npt.NDArray: The response of the CompositeResponse function to the stimuli x.

class BuildYourOwnEmbedding.responses.GaussianResponse(mean: npt.number, std: npt.number)[source]

Bases: ResponseFunction

GaussianResponse class. Is the response function for a 1-dimensional gaussian response model.

evaluate(x: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Evaluates the GaussianResponse response function for a given stimuli.

Args:

x (npt.NDArray): The stimuli for which to generate a response to. dtype (npt.DTypeLike, optional): The desired data type of the output. Defaults to np.float64.

Returns:

npt.NDArray: A numpy array containing the values of the Response to the stimulus x.

class BuildYourOwnEmbedding.responses.GaussianResponse2D(xMean: npt.number, yMean: npt.number, xStd: npt.number, yStd: npt.number)[source]

Bases: ResponseFunction

evaluate(x: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Evaluates the GaussianResponse2D response function for a given stimuli.

Args:

x (npt.NDArray): The stimuli for which to generate a response to. This stimuli should be a 2-dimensional numpy array. dtype (npt.DTypeLike, optional): The desired data type of the output. Defaults to np.float64.

Returns:

npt.NDArray: A numpy array containing the values of the Response to the stimulus x.

class BuildYourOwnEmbedding.responses.ResponseData(params: Dict[str, npt.number], response: npt.NDArray, responseFunction: str, x: npt.NDArray)[source]

Bases: object

Data class for storing a single response output and the parameters that created it.

Attributes:

params (Dict[str, np.number]): The parameters used for generating the response. response (np.ndarray): The response values. responseFunction (str): The name of the Response Function that generated this Response

params: Dict[str, npt.number]
response: npt.NDArray
responseFunction: str
x: npt.NDArray
class BuildYourOwnEmbedding.responses.ResponseFunction(**kwargs: Any)[source]

Bases: ABC

Base class for defining neural responses.

The ResponseFunction class serves as an abstract base class for creating neural response functions that can be evaluated based on input data. This class provides a standardised interface for defining neural response curves, allowing users to implement custom responses by extending this class and implementing the evaluate method. It also supports mathematical operations to combine responses, creating composite response functions.

Attributes:
params (Dict): A dictionary containing response-specific parameters used

to define the behavior of the response function.

Methods:
evaluate(x: npt.NDArray) -> npt.NDArray:

Abstract method to evaluate the neural response for a given input.

__call__(x: npt.NDArray) -> npt.NDArray:

Calls the evaluate method to compute the response for the given input.

__add__(other: ResponseFunction) -> CompositeResponse:

Combines this response with another response using addition.

__sub__(other: ResponseFunction) -> CompositeResponse:

Combines this response with another response using subtraction.

__mul__(other: ResponseFunction) -> CompositeResponse:

Combines this response with another response using multiplication.

__str__() -> str:

Returns a string representation of the response function.

abstract evaluate(x: ndarray[Any, dtype[_ScalarType_co]]) ndarray[Any, dtype[_ScalarType_co]][source]

Evaluate the response of the neuron for a given input.

This abstract method must be implemented by subclasses to define how the response function computes output values based on input data.

Args:
x (npt.NDArray):

The input data for which the response is evaluated. This should be a Numpy array representing the stimulus or feature input to the neuron.

Returns:
npt.NDArray:

A Numpy array representing the evaluated response values corresponding to the input data.

Raises:
NotImplementedError:

This method must be overridden by subclasses, otherwise, calling it will raise this error.

class BuildYourOwnEmbedding.responses.ResponseManager(responseClasses: Type[ResponseFunction] | Tuple[Type[ResponseFunction], ...], **parameters: Parameter)[source]

Bases: object

generate_responses(x: npt.NDArray, noiseLevel: npt.number = 0, numSamples: int = 1) ResponseSet[source]

Generates responses for each combination of parameter values

Args:

x (npt.NDArray): The input data for which the response is generated noiseLevel (npt.number, optional):

The standard deviation of Gaussian noise to be added to the response. Defaults to 0 (no noise).

numSamples (int, optional):

The number of times to sample each combination of parameters. Defaults to 1.

Returns:

ResponseSet: A ResponseSet object containing each response and the corresponding parameters.

class BuildYourOwnEmbedding.responses.ResponseSet(responses: None | List[ResponseData] = None)[source]

Bases: object

A class for storing and analysing a set of neural responses.

The ResponseSet class provides methods to compute representational dissimilarity matrices (RDM) and representational geodesic topological matrices (RGTM), as well as functions for visualising and analysing responses. It supports both 1D and 2D response visualisations and also allows interactive plots.

Attributes:
responses (List[ResponseData]): A list of ResponseData objects that store

the neural responses and their associated parameters.

compute_rdm(dissimilarityMetric: Callable[[npt.ArrayLike, npt.ArrayLike], npt.number] = <function inverse_correlation>) npt.ArrayLike[source]

Computes the Representational Dissimilarity Matrix (RDM) for the stored responses

Args:

dissimilarityMetric (Callable[ [npt.ArrayLike, npt.ArrayLike], npt.number ], optional): A function to compute dissimilarity between two responses. Defaults to inverse_correlation.

Returns:

npt.ArrayLike: A square RDM where each entry (i, j) represents the dissimilarity between the i-th and j-th responses.

compute_rgtm(lowerBound: npt.number, upperBound: npt.number, dissimilarityMetric: Callable[[npt.ArrayLike, npt.ArrayLike], npt.number] = <function inverse_correlation>) npt.ArrayLike[source]

Computes the Representational Geodesic Topological Matrix (RGTM).

The RGTM is computed by applying a piecewise linear transformation on the dissimilarity matrix based on the provided lower and upper bounds.

Args:

lowerBound (npt.number): The lower bound for the transformation. upperBound (npt.number): The upper bound for the transformation. dissimilarityMetric (Callable[ [npt.ArrayLike, npt.ArrayLike], npt.number ], optional): A function to compute dissimilarity between two responses. Defaults to inverse_correlation.

Returns:

npt.ArrayLike: The computed RGTM matrix.

fisher_information() ndarray[Any, dtype[_ScalarType_co]][source]

Computes the fisher information of the set of responses

Returns:

npt.NDArray: A numpy array containing the fisher information of the stored responses.

plot_2D_PCA(xlabel: str = 'PC 1', ylabel: str = 'PC 2', title: str = '2D PCA of Embedding', figsize: Tuple[int] = (7, 7)) None[source]
plot_2D_mds(dissimilarityMetric: Callable[[npt.ArrayLike, npt.ArrayLike], npt.number] = <function inverse_correlation>, xlabel: str = 'MDS Dimension 1', ylabel: str = 'MDS Dimension 2', cmap: str = 'viridis', cbarLabel: Union[str, None] = None, title: str = None, figsize: Tuple[int] = (7, 7), responseToColour: Union[Callable[[ResponseData], npt.number], str, None] = None) None[source]

Plots a 2D Multidimensional Scaling (MDS) scatter plot for the stored responses.

This method computes a 2D MDS embedding from the dissimilarity matrix of the responses and visualises the responses in a 2D scatter plot. The color of each point in the scatter plot can be customized based on response parameters or a user-defined function.

Args:
dissimilarityMetric (Callable[ [npt.ArrayLike, npt.ArrayLike], npt.number ], optional):

A function to compute the dissimilarity between two responses. Defaults to inverse_correlation.

xlabel (str, optional): Label for the x-axis of the MDS plot. Defaults to “MDS Dimension 1”. ylabel (str, optional): Label for the y-axis of the MDS plot. Defaults to “MDS Dimension 2”. cmap (str, optional): The colourmap used for coloring the scatter points. Defaults to “viridis”. cbarLabel (Union[str, None], optional): Label for the colour bar. Defaults to None. title (str, optional): Title of the plot. Defaults to None. figsize (Tuple[int], optional): The size of the figure. Defaults to (7, 7). responseToColour (Union[Callable[[ResponseData], npt.number], str, None], optional):

A function or string to define the color mapping for the scatter points. If a string is passed, it should be the name of a parameter in the responses. If a callable is passed, it should be a function that maps a ResponseData object to a numeric value for coloring the points. Defaults to None.

plot_3D_mds(dissimilarityMetric: Callable[[npt.ArrayLike, npt.ArrayLike], npt.number] = <function inverse_correlation>, xlabel: str = 'MDS Dimension 1', ylabel: str = 'MDS Dimension 2', zlabel: str = 'MDS Dimension 3', cmap: str = 'viridis', cbarLabel: Union[str, None] = None, title: str = None, figsize: Tuple[int] = (7, 7), responseToColour: Union[Callable[[ResponseData], npt.number], str, None] = None) None[source]

Plots a 3D Multidimensional Scaling (MDS) scatter plot for the stored responses.

This method computes a 3D MDS embedding from the dissimilarity matrix of the responses and visualises the responses in a 3D scatter plot. The color of each point in the scatter plot can be customized based on response parameters or a user-defined function.

Args:
dissimilarityMetric (Callable[ [npt.ArrayLike, npt.ArrayLike], npt.number ], optional):

A function to compute the dissimilarity between two responses. Defaults to inverse_correlation.

xlabel (str, optional): Label for the x-axis of the MDS plot. Defaults to “MDS Dimension 1”. ylabel (str, optional): Label for the y-axis of the MDS plot. Defaults to “MDS Dimension 2”. zlabel (str, optional): Label for the z-axis of the MDS plot. Defaults to “MDS Dimension 3”. cmap (str, optional): The colourmap used for coloring the scatter points. Defaults to “viridis”. cbarLabel (Union[str, None], optional): Label for the colour bar. Defaults to None. title (str, optional): Title of the plot. Defaults to None. figsize (Tuple[int], optional): The size of the figure. Defaults to (7, 7). responseToColour (Union[Callable[[ResponseData], npt.number], str, None], optional):

A function or string to define the color mapping for the scatter points. If a string is passed, it should be the name of a parameter in the responses. If a callable is passed, it should be a function that maps a ResponseData object to a numeric value for coloring the points. Defaults to None.

plot_PCA_variance_explained(dissimilarityMetric: Callable[[npt.ArrayLike, npt.ArrayLike], npt.number] = <function inverse_correlation>, xlabel: str = 'Number of Principal Components', ylabel: str = 'Variance Explained', title: str = 'Variance Explained vs. Number of Principal Components', figsize: Tuple[int] = (7, 7), grid: bool = False) None[source]

Plots the variance explained by each principal component from PCA on the dissimilarity matrix.

This method computes the Principal Component Analysis (PCA) of the dissimilarity matrix and visualises the variance explained by each principal component in a line plot. This provides insight into how much variance each component captures, helping to determine how many components are needed for sufficient variance representation.

Args:
dissimilarityMetric (Callable[ [npt.ArrayLike, npt.ArrayLike], npt.number ], optional):

A function to compute the dissimilarity between two responses. Defaults to inverse_correlation.

xlabel (str, optional): Label for the x-axis. Defaults to ‘Number of Principal Components’. ylabel (str, optional): Label for the y-axis. Defaults to ‘Variance Explained’. title (str, optional): Title of the plot. Defaults to ‘Variance Explained vs. Number of Principal Components’. figsize (Tuple[int], optional): Size of the figure. Defaults to (7, 7). grid (bool, optional): Whether to show grid lines on the plot. Defaults to False.

plot_rdm(dissimilarityMetric: Callable[[npt.ArrayLike, npt.ArrayLike], npt.number] = <function inverse_correlation>, labels: Union[List[str], None] = None, cmap: str = 'viridis', title: str = None, figsize: Tuple[int] = (7, 7), dissimilarityLabel: str = 'Dissimilarity') None[source]

Plots the Representational Dissimilarity Matrix (RDM) for the stored responses.

Args:

dissimilarityMetric (Callable[ [npt.ArrayLike, npt.ArrayLike], npt.number ], optional): Function to compute dissimilarity between two responses. Defaults to inverse_correlation. labels (Union[List[str], None], optional): Labels for the plot’s x and y axes. Defaults to None. cmap (str, optional): Colourmap for the plot. Defaults to “viridis”. title (str, optional): Title of the plot. Defaults to None. figsize (Tuple[int], optional): Size of the figure. Defaults to (7, 7). dissimilarityLabel (str, optional): Label for the colour bar. Defaults to “Dissimilarity”.

plot_responses(figsize: Tuple[int] = (7, 7), xlabel: str = 'Stimuli', ylabel: str = 'Response', title: str = 'Responses', grid: bool = False, hoverEffects: bool = True, *args, **kwargs) None[source]

Plots the responses in 1D or 2D format.

Higher dimensional plots are not currently supported.

Args:

figsize (Tuple[int], optional): Size of the figure. Defaults to (7, 7). xlabel (str, optional): Label for the x-axis. Defaults to “Stimuli”. ylabel (str, optional): Label for the y-axis. Defaults to “Response”. title (str, optional): Title of the plot. Defaults to “Responses”. grid (bool, optional): Whether to display a grid on the plot. Defaults to False. hoverEffects (bool, optional): If True, adds hover effects to the plot. Defaults to True.

Raises:

NotImplementedError: If the ResponseData represents 3-dimensional or higher curves.

plot_rgtm(lowerBound: npt.number = 0, upperBound: npt.number = 1, dissimilarityMetric: Callable[[npt.ArrayLike, npt.ArrayLike], npt.number] = <function inverse_correlation>, interactive: bool = True, labels: Union[List[str], None] = None, cmap: str = 'viridis', title: str = 'Representational Geo-Topological Matrix', figsize: Tuple[int] = (7, 7), dissimilarityLabel: str = 'Dissimilarity') None[source]

Plots the Representational Geo-Topological Matrix (RGTM) with optional interactivity.

Args:

lowerBound (npt.number, optional): The lower bound for the RGTM transformation. Defaults to 0. upperBound (npt.number, optional): The upper bound for the RGTM transformation. Defaults to 1. dissimilarityMetric (Callable[ [npt.ArrayLike, npt.ArrayLike], npt.number ], optional): Function to compute dissimilarity between two responses. Defaults to inverse_correlation. interactive (bool, optional): Whether to include sliders for adjusting the bounds interactively. Defaults to True. labels (Union[List[str], None], optional): List of labels for the axes. Defaults to None. cmap (str, optional): Colourmap used for plotting. Defaults to “viridis”. title (str, optional): Title of the plot. Defaults to “Representational Geo-Topological Matrix”. figsize (Tuple[int], optional): Size of the figure. Defaults to (7, 7). dissimilarityLabel (str, optional): Label for the colour bar. Defaults to “Dissimilarity”.

class BuildYourOwnEmbedding.responses.SigmoidResponse(alpha: npt.number, beta: npt.number)[source]

Bases: ResponseFunction

SigmoidResponse class. Is the response function for a 1-dimensional sigmoid response model.

evaluate(x: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Evaluates the SigmoidResponse response function for a given stimuli.

Args:

x (npt.NDArray): The stimuli for which to generate a response to. dtype (npt.DTypeLike, optional): The desired data type of the output. Defaults to np.float64.

Returns:

npt.NDArray: A numpy array containing the values of the Response to the stimulus x.

class BuildYourOwnEmbedding.responses.VonMisesResponse(kappa: npt.number, theta: npt.number)[source]

Bases: ResponseFunction

VonMisesResponse class. Is the response function for a 1-dimensional Von-mises response model.

evaluate(x: ~numpy.ndarray[~typing.Any, ~numpy.dtype[~numpy._typing._array_like._ScalarType_co]], dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float64'>) ndarray[Any, dtype[_ScalarType_co]][source]

Evaluates a Von-mises response for a given stimuli

Args:

x (npt.NDArray): The stimuli for which to generate a response to. dtype (npt.DTypeLike, optional): The desired data type of the output. Defaults to np.float64.

Returns:

npt.NDArray: A numpy array containing the values of the Response to the stimulus x.