amplify.BinaryIntMatrix
- class BinaryIntMatrix
Upper triangular matrix representation of QUBO model with integer coefficients.
The QUBO model will be the form of \(y = \min_q q^{T} Q q\), where \(q\) is a vector of variables and \(Q\) is a square matrix.
This class denotes the upper triangular matrix representation of \(Q\).
注釈
In the descriptions of class methods, \(Q\) and \(q\) are the matrix and the vector this class represents, respectively.
注釈
- The following operators are defined for the class.
Indexing:
a[slices]
(__getitem__()
,__setitem__()
)Equality:
a == b
(__eq__()
)Inequality:
a != b
(__ne__()
)Addition:
a + b
(__add__()
,__radd__()
,__iadd__()
)Subtraction:
a - b
(__sub__()
,__rsub__()
,__isub__()
)Multiplication:
a * b
(__mul__()
,__rmul__()
,__imul__()
)Division:
a / b
(__truediv__()
,__rtruediv__()
,__itruediv__()
)Floor Division:
a // b
(__floordiv__()
,__rfloordiv__()
,__ifloordiv__()
)
- __init__(size)
Returns a zero-matirx with specified size.
- パラメータ:
size (
int
) -- Size of the matrix.
Example
>>> from amplify import BinaryIntMatrix >>> m = BinaryIntMatrix(3) >>> m[0, 1] = 1 >>> m[0, 2] = 2 >>> m[1, 2] = 3 >>> m [[0, 1, 2], [0, 0, 3], [0, 0, 0]]
Methods
__init__
(size)Returns a zero-matirx with specified size.
evaluate
(self, object)Evaluates the matrix with array q.
resize
(self, size)Resizes the matrix.
size
(self)Returns the matrix size.
to_BinaryMatrix
(self[, ascending])Converts the matrix to
BinaryIntMatrix
.to_IsingMatrix
(self[, ascending])Converts the matrix to
IsingIntMatrix
.to_Poly
(self)Converts the matrix to
BinaryIntPoly
.to_numpy
(self)no docstring
- evaluate(self, object)
Evaluates the matrix with array q.
- パラメータ:
object -- array-like. The size of arary object should be equal to the matrix size.
- 戻り値:
\(q^{T} Q q\)
Example
>>> from amplify import BinaryIntMatrix >>> m = BinaryIntMatrix(3) >>> m[0, 1] = 1 >>> m[0, 2] = 2 >>> m[1, 2] = 3 >>> m [[0, 1, 2], [0, 0, 3], [0, 0, 0]] >>> m.evaluate([0, 1, 1]) 3
- resize(self: amplify.BinaryIntMatrix, size: int) None
Resizes the matrix.
Example
>>> from amplify import BinaryIntMatrix >>> m = BinaryIntMatrix(2) >>> m[0, 1] = 1 >>> m [[0, 1], [0, 0]] >>> m.resize(3) >>> m [[0, 1, 0], [0, 0, 0], [0, 0, 0]]
- size(self: amplify.BinaryIntMatrix) int
Returns the matrix size.
- 戻り値:
size of the matrix
- 戻り値の型:
Example
>>> from amplify import BinaryIntMatrix >>> m = BinaryIntMatrix(3) >>> m.size() 3
- to_BinaryMatrix(self: amplify.BinaryIntMatrix, ascending: bool = True) Tuple[amplify.BinaryIntMatrix, int]
Converts the matrix to
BinaryIntMatrix
.This function returns the pair of the converted
BinaryIntMatrix
\(Q\) and the constant term \(c\) in the converted QUBO formulation.- 戻り値:
\((Q, c)\)
Example
>>> from amplify import BinaryIntMatrix >>> m = BinaryIntMatrix(3) >>> m[0, 1] = 1 >>> m[0, 2] = 2 >>> m[1, 2] = 3 >>> m [[0, 1, 2], [0, 0, 3], [0, 0, 0]] >>> m.to_BinaryMatrix() ([[0, 1, 2], [0, 0, 3], [0, 0, 0]], 0)
- to_IsingMatrix(self: amplify.BinaryIntMatrix, ascending: bool = True) Tuple[amplify.IsingIntMatrix, int]
Converts the matrix to
IsingIntMatrix
.By this function, the QUBO formulation \(q^T Q q\) would be transformed to the Ising model formulation :math:s^{mathrm{T}} J s - mathrm{Tr}J + s^{mathrm{T}} cdot operatorname{diag} J`, where \(s\) is a vector of variables and \(J\) is an upper triangular square matrix. The conversion is along \(s = 2q - \left\{1 \right\}\).
This function returns the pair of the converted
IsingIntMatrix
\(J\) and the constant term \(c\) in the converted Ising model formulation.- 戻り値:
\((J, c)\)
Example
>>> from amplify import BinaryIntMatrix >>> m = BinaryIntMatrix(3) >>> m[0, 1] = 1 >>> m[0, 2] = 2 >>> m[1, 2] = 3 >>> m [[0, 1, 2], [0, 0, 3], [0, 0, 0]] >>> m.to_IsingMatrix() ([[0, 0, 0], [0, 0, 0], [0, 0, 0]], 0)
- to_Poly(self: amplify.BinaryIntMatrix) amplify.BinaryIntPoly
Converts the matrix to
BinaryIntPoly
.- 戻り値:
polynomial expression of the matrix
- 戻り値の型:
Example
>>> from amplify import BinaryIntMatrix >>> m = BinaryIntMatrix(3) >>> m[0, 1] = 1 >>> m[0, 2] = 2 >>> m[1, 2] = 3 >>> m [[0, 1, 2], [0, 0, 3], [0, 0, 0]] >>> m.to_Poly() q_0 q_1 + 2 q_0 q_2 + 3 q_1 q_2
- to_numpy(self: amplify.BinaryIntMatrix) numpy.ndarray[numpy.float64]
no docstring