pymoto.EinSum
- class pymoto.EinSum(expression: str)
General linear algebra module which uses the Numpy function
einsumMany linear algebra multiplications can be implemented using this module:
Operation
EinSum arguments
Python equivalent
Vector sum
"i->", uy = sum(u)Elementwise multiply
"i,i->i", u, vw = u * vDot product
"i,i->", u, vy = np.dot(u,v)Outer product
"i,j->ij", u, vA = np.outer(u,v)Matrix trace
"ii->", Ay = np.trace(A)Matrix-vector product
"ij,j->i", A, bx = A.dot(b)Quadratic form
"i,ij,j->", b, A, by = b.dot(A.dot(b))Matrix-matrix product
"ij,ij->ij", A, BC = A * BTranspose matrix prod.
"ji,ij->ij", A, BC = A.T * BMatrix projection
"ji,jk,kl->il", V, A, VB = V.T.dot(A.dot(V))Many more advanced operations are supported (see References), with exception of expressions with repeated indices (e.g.
iij->ij).An optimized version of
einsumis available by installing the package opt_einsum.- Input signals:
*args(np.ndarray): Any number of inputs that are passed toeinsumand match the expression- Output signal:
y(np.ndarray): Result of theeinsumoperation
References
- __init__(expression: str)
Initialize the EinSum module
- Parameters:
expression (str) – The
einsumexpression
Methods
__init__(expression)Initialize the EinSum module
connect(sig_in[, sig_out])Connect without automatic adding to a function network
get_input_sensitivities([as_list])get_input_states([as_list])get_output_sensitivities([as_list])get_output_states([as_list])reset()Reset the state of the sensitivities (they are set to zero or to None)
response()Calculate the response from sig_in and output this to sig_out
Calculate sensitivities using backpropagation
Attributes
Get the number of input signals
Get the number of output signals
- connect(sig_in: Signal | Iterable[Signal], sig_out: Signal | Iterable[Signal] = None)
Connect without automatic adding to a function network
- get_input_sensitivities(as_list=False)
- get_input_states(as_list=False)
- get_output_sensitivities(as_list=False)
- get_output_states(as_list=False)
- property n_in: int
Get the number of input signals
- property n_out: int
Get the number of output signals
Note: Cannot be used in the initial __call__()
- reset()
Reset the state of the sensitivities (they are set to zero or to None)
- response()
Calculate the response from sig_in and output this to sig_out
- sensitivity()
Calculate sensitivities using backpropagation
Based on the sensitivity we get from sig_out, reverse the process and output the new sensitivities to sig_in
- sig_in: List = None
- sig_out: List = None