Binary Operations¶
dot¶
The inverse operation of dot is dot.
-
class
auto_diff.
OpDot
(x: auto_diff.op.operation.Operation, y: auto_diff.op.operation.Operation, **kwargs)[source]¶ Bases:
auto_diff.op.operation.Operation
Dot product of two tensors.
If either x or y is a scalar, then it is equivalent to
OpMultiply
.If both x and y are 1-D arrays, it is the inner product of vectors, the result is a scalar:
z=∑kxk⋅ykPartial derivatives of a single element:
∂L∂xi=∂L∂z⋅∂z∂xi=∂L∂z⋅yi∂L∂yi=∂L∂z⋅∂z∂yi=∂L∂z⋅xiVector derivatives:
∂L∂x=∂L∂z⋅y∂L∂y=∂L∂z⋅xNote that since z is a scalar, the calculation of vector derivatives in this case is the dot operation.
If both x and y are 2-D arrays, it is the matrix multiplication, the result is a 2-D array:
zij=∑kxik⋅ykjPartial derivative of a single element:
∂L∂xij=∑a,b∂L∂zab⋅∂zab∂xij=∑a,b∂L∂zab⋅∂(∑kxak⋅ykb)∂xij=∑b∂L∂zib⋅∂(xij⋅yjb)∂xij=∑k∂L∂zik⋅yjk=∑k(∂L∂Z)ik⋅(YT)kj∂L∂yij=∑k(XT)ik⋅(∂L∂Z)kjThe results of partial derivatives are the same as the definition of the dot operation, therefore the matrix derivatives are:
∂L∂X=∂L∂Z⋅YT∂L∂Y=XT⋅∂L∂ZIf x is an N-D tensor and y is an M-D tensor (M >= 2), it is a sum product over the last axis of x and second-to-last axis of y.
If x is an N-D tensor and y is a 1-D array, it is a sum product over the last axis of x and y. It is a special case of the previous condition if y is considered as a K x 1 matrix and result is squeezed.