xpress.Dot
xpress.Dot |
Alternative dot-product operator for an arbitrary number of NumPy single- or multi-dimensional arrays. Following the convention for dot-product, the result of Dot for a list of k objects T1, T2, ..., Tk of d1, d2, ..., dk dimensions is an object of d1 + d2 + ... + dk - 2(k-1) dimensions. For each i-th factor in [1,2,...,k-1], the arity of the last dimension of Ti must match the arity of the penultimate dimension of Ti+1 (or its arity if Ti+1 is single-dimensional, i.e., a vector).
a = xpress.Dot (t1, t2, ..., out)
out
|
(optional) NumPy array of the correct dimension and arity where the result is stored. If not provided, the dot product is returned.
|
import numpy as np import xpress as xp N = 10 M = 20 S = range (N) x = np.array ([xp.var () for i in S]) x0 = np.random.random (N) # creates an N-vector of random numbers p = xp.problem () # objective function is the squared Euclidean distance of the # variable vector x from a fixed point x0 p.setObjective (xp.Dot ((x-x0), (x-x0))) A = np.random.random ((M,N)) b = np.random.random (M) # constraint Ax = b, random MxN matrix A and M-vector b p.addConstraint (xp.Dot (A, x) == b) # Create a single quadratic constraint with # a positive semidefinite matrix Q + N^3 * I Q = np.random.random ((N,N)) p.addConstraint (xp.Dot (x, Q + N**3 * np.eye (N), x) <= 1) # Create four quadratic constraints using an order-three # tensor, i.e., a three-dimensional array. k = 4 T = np.random.random ((k,N,N)) q = np.random.random (k) p.addConstraint (xp.Dot (x, T, x) <= q)
From an operational standpoint, the dot product of k multi-dimensional arrays is the result of k-1 dot products of two factors each, and proceeds as in the following Python code:
result = T[0] for i in range (1,k): result = xpress.Dot (result, T[i])
vi1,i2,...,id'-1, j1,j2,...,jd''-2,jd'' = ∑1≤h≤nd' t'i1,i2,...,id'-1,h· t''j1,j2,...,jd''-2,h,jd''.
It is assumed here that nd' = md''-1. Two simple cases may help understand the behavior of the operator: for two single-dimensional arrays v' and v'' of size n, the result is the inner product
∑1≤h≤n v'h· v''h.
For two matrices A and B of sizes m×n and n×p respectively, the result is the m×p matrix C whose generic element is
Cij = ∑1≤h≤n Aih· Bhj.
The Dot operator is functionally equivalent to Python's dot operator from the NumPy package. However, the Xpress Dot operator is the only one that can work on variables and expressions containing variables.
© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.