pymoto.EinSum

class pymoto.EinSum(expression: str)

General linear algebra module which uses the Numpy function einsum

Many linear algebra multiplications can be implemented using this module:

Operation

EinSum arguments

Python equivalent

Vector sum

"i->", u

y = sum(u)

Elementwise multiply

"i,i->i", u, v

w = u * v

Dot product

"i,i->", u, v

y = np.dot(u,v)

Outer product

"i,j->ij", u, v

A = np.outer(u,v)

Matrix trace

"ii->", A

y = np.trace(A)

Matrix-vector product

"ij,j->i", A, b

x = A.dot(b)

Quadratic form

"i,ij,j->", b, A, b

y = b.dot(A.dot(b))

Matrix-matrix product

"ij,ij->ij", A, B

C = A * B

Transpose matrix prod.

"ji,ij->ij", A, B

C = A.T * B

Matrix projection

"ji,jk,kl->il", V, A, V

B = 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 einsum is available by installing the package opt_einsum.

Input signals:

*args (np.ndarray): Any number of inputs that are passed to einsum and match the expression

Output signal:

y (np.ndarray): Result of the einsum operation

References

__init__(expression: str)

Initialize the EinSum module

Parameters:

expression (str) – The einsum expression

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

sensitivity()

Calculate sensitivities using backpropagation

Attributes

n_in

Get the number of input signals

n_out

Get the number of output signals

sig_in

sig_out

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