Embeddings#
- class tn4ml.embeddings.Embedding[source][source]
Data embedding (feature map) class.
- dtype
Data Type
- Type:
numpy.dtype
- __new__(**kwargs)
Trigonometric#
- class tn4ml.embeddings.trigonometric[source][source]
Trigonometric feature map.
\(\phi(x_\textit{j}) = \left[ cos(\frac{\pi}{2}x_\textit{j}), sin(\frac{\pi}{2}x_\textit{j}) \right]\)
- k
Custom parameter =
dim/2.- Type:
int
- property dim: int
Mapping dimension
- property input_dim: int
Dimensionality of input feature. 1 = number, 2 = vector
Fourier#
- class tn4ml.embeddings.fourier[source][source]
Fourier feature map. \(\phi(x_\textit{j}) = \frac{1}{\sqrt{k}}\left[ cos(\frac{\pi x_\textit{j}}{2}), sin(\frac{\pi x_\textit{j}}{2}), ..., cos(\frac{\pi x_\textit{j}}{2^k}), sin(\frac{\pi x_\textit{j}}{2^k})\right]\)
- p
Mapping dimension.
- Type:
int
- property dim: int
Mapping dimension
- property input_dim: int
Dimensionality of input feature. 1 = number, 2 = vector
Linear Complement#
Gaussian RBF#
- class tn4ml.embeddings.gaussian_rbf[source][source]#
Gaussian Radial Basis Function.
- centers#
Gaussian centers.
- Type:
numpy.ndarray
- gamma#
Scaling factor \(\gamma=\frac{1}{2\sigma^2}\)
- Type:
float
- __init__(centers=None, gamma=None, **kwargs)[source][source]#
- Parameters:
centers (ndarray)
gamma (float)
- property dim: int#
Mapping dimension
- property input_dim: int#
Dimensionality of input feature. 1 = number
Polynomial#
- class tn4ml.embeddings.polynomial[source][source]#
Polynomial feature map
- degree#
Degree of polynomial.
- Type:
int
- n#
Number of features.
- Type:
int
- include_bias#
Include bias term.
- Type:
bool
- __init__(degree, n, include_bias=False, **kwargs)[source][source]#
- Parameters:
degree (int)
n (int)
include_bias (bool)
- property dim: int#
Mapping dimension
- property input_dim: int#
Dimensionality of input feature
Jax Arrays#
Patch Embedding#
- class tn4ml.embeddings.PatchEmbedding[source][source]#
- __init__(k=2, **kwargs)[source][source]#
Initialize the PatchedEmbedding class.
- Parameters:
k (int) – The kernel size of the patch window kxk.
- Return type:
None
- property dims: list#
Dimensions of mps arrays
- pad_or_truncate_statevector(statevector, target_size)[source][source]#
Pad or truncate the statevector to a target size.
- Parameters:
statevector (
jax.numpy.ndarray) – The input statevector.target_size (int) – The desired size of the statevector.
- Returns:
A statevector of the target size.
- Return type:
jax.numpy.ndarray
- create_statevector(x)[source][source]#
Create a statevector representation of an input array (vector like).
- Parameters:
x (
jax.numpy.ndarray) – An array of patch pixel intensities flattened from original patch k x k.- Returns:
A statevector representation of the input array.
- Return type:
jax.numpy.ndarray
- flatten_snake(image)[source][source]#
Flatten an image in a snake-like fashion.
- Parameters:
image (
jax.numpy.ndarray) – A 2D array of pixel intensities.- Returns:
A 1D array of pixel intensities in snake-like order.
- Return type:
jax.numpy.ndarray
- combine_mps_patches(mps_patches, n_qubits)[source][source]#
Combine arrays of each MPS patch into a single MPS.
- Parameters:
mps_patches (
numpy.ndarray) – List of MPS patches (nested lists of arrays).n_qubits (int) – Number of qubits.
- Returns:
A list of arrays for combined MPS.
- Return type:
jax.numpy.ndarray
Embed Function#
- tn4ml.embeddings.embed(x, phi, **mps_opts)[source][source]#
Creates a product state from a vector of features x. Works only if features are separated and not correlated (this check you need to do yourself).
- Parameters:
x (
numpy.ndarray) – Vector or Matrix of features.phi (
tn4ml.embeddings.Embeddingortn4ml.embeddings.ComplexEmbeddingortn4ml.embeddings.StateVectorToMPSEmbedding) – Feature map for each feature.mps_opts (Optional parameters.) – Additional arguments passed to MatrixProductState class.