Welcome to MAQ’s documentation!
src package
Submodules
src.qml module
- src.qml.kmeans2Qubo(X, k, alpha=None, beta=None)[source]
Converts a given k-means clustering problem into a QUBO problem
- Parameters:
X (numpy array) – Data matrix with N rows and d columns
k (numpy array) – Number of clusters desired
- Returns:
QUBO matrix p (numpy array): QUBO vector
- Return type:
Q (numpy array)
- Raises:
TypeError –
If X is not numpy array 2. If k is not an integer
ValueError – If shape of X is not [N, d]
- src.qml.kmeansClusters(solutions, N, k)[source]
Returns the clustering assignment for a given k-means problem
- Parameters:
solutions (list) – List of k-means solutions returned by the adiabatic quantum computer
N (int) – Number of data points in the original problem
k (int) – Number of clusters in the original problem
- Returns:
A list of assignments corresponding to each solution returned by the adiabatic quantum computer
- Return type:
assignmentsList
- src.qml.regression2Qubo(X, Y, P)[source]
Converts a given regression problem into QUBO problem
- Parameters:
X (numpy array) – Augmented training data having N datapoints and (d+1) features, i.e. d features augmented by unity
Y (numpy array) – Training labels for regression, N dimensional vector
P (numpy array) – Precision vector, must be sorted, can contain positive and negative powers of 2
- Returns:
QUBO matrix p (numpy array): QUBO vector
- Return type:
Q (numpy array)
- Raises:
TypeError – If X, Y or P are not numpy arrays
ValueError –
If shape of X is not [N,d] 2. If shape of Y is not [N] 3. If first dimensions of X and Y are not equal
- src.qml.regressionWeights(solutions, P)[source]
Finds regression weights from binarized regression weights
- Parameters:
solutions – List of binarized regression weight vector
P – Precision vector
- Returns:
List of real valued regression weights
- Return type:
w
- src.qml.svm2Qubo(X, Y, P)[source]
Converts a given SVM problem into QUBO problem
- Parameters:
X (numpy array) – Training data having N datapoints and d features
Y (numpy array) – Training labels for binary classification
P (numpy array) – Precision vector, must be sorted, can contain positive and negative powers of 2
- Returns:
QUBO matrix p (numpy array): QUBO vector
- Return type:
Q (numpy array)
- Raises:
TypeError – If X, Y or P are not numpy arrays
ValueError –
If shape of X is not [N,d] 2. If shape of Y is not [N] 3. If first dimensions of X and Y are not equal
- src.qml.svmWeights(solutions, P, N, d)[source]
Finds SVM weights from binarized SVM weights
- Parameters:
solutions – List of binarized SVM solutions (weights, biases and Lagrangian multipliers)
P – Precision vector
N – Size of training dataset
d – Number of features in training dataset
- Returns:
List of real valued SVM weights biasList: List of real valued SVM bias lambdas: List of real valued SVM Lagrangian multipliers
- Return type:
weightsList
src.utils module
- src.utils.array2Dict(x)[source]
Converts numpy 1-dimensional array into dictionary.
- Parameters:
x (numpy array) – Input array
- Returns:
Dictionary with array indices as keys and array values as values.
- Return type:
d (dict)
- src.utils.embedChimeraIsing(Q, p, M=16, N=16, L=4, Lambda=None, normalize=True)[source]
Generates embedding for an Ising problem characterized by Q and p for D-Wave Chimera hardware.
- Parameters:
Q (numpy array) –
p (numpy array) –
M (int) –
N (int) –
L (int) –
- Returns:
h (dict):
- Return type:
J (dict)
- Raises:
TypeError – If M, N or L are not integers
ValueError – If Lambda is given and not positive
- src.utils.embedChimeraQubo(Q, p, M=16, N=16, L=4, Lambda=None, normalize=True)[source]
Generates embedding for an Ising problem characterized by Q and p for D-Wave Chimera hardware.
- Parameters:
Q (numpy array) –
p (numpy array) –
M (int) –
N (int) –
L (int) –
- Returns:
h (dict):
- Return type:
J (dict)
- Raises:
TypeError – If M, N or L are not integers
ValueError – If Lambda is given and not positive