auto_diff.op package¶
Submodules¶
auto_diff.op.op_constant module¶
-
class
auto_diff.op.op_constant.
OpConstant
(x: Union[int, float, list, numpy.ndarray], **kwargs)[source]¶ Bases:
auto_diff.op.operation.Operation
Contains a constant.
-
__init__
(x: Union[int, float, list, numpy.ndarray], **kwargs)[source]¶ Parameters: - x – The constant value.
- kwargs –
-
auto_diff.op.op_flatten module¶
-
class
auto_diff.op.op_flatten.
OpFlatten
(x: auto_diff.op.operation.Operation, **kwargs)[source]¶ Bases:
auto_diff.op.op_reshape.OpReshape
Flatten the tensor to 1-D array.
auto_diff.op.op_placeholder module¶
-
class
auto_diff.op.op_placeholder.
OpPlaceholder
(shape: Sequence[int], **kwargs)[source]¶ Bases:
auto_diff.op.operation.Operation
The placeholder that represents values to be feed.
auto_diff.op.op_reshape module¶
-
class
auto_diff.op.op_reshape.
OpReshape
(x: auto_diff.op.operation.Operation, shape: Sequence[int], **kwargs)[source]¶ Bases:
auto_diff.op.operation.Operation
Reshape the tensor to a given shape.
-
__init__
(x: auto_diff.op.operation.Operation, shape: Sequence[int], **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
auto_diff.op.op_transpose module¶
-
class
auto_diff.op.op_transpose.
OpTranspose
(x: auto_diff.op.operation.Operation, axes: Optional[Sequence[int]] = None, **kwargs)[source]¶ Bases:
auto_diff.op.operation.Operation
Transpose the tensor.
Basic operation without axes:
Y=XTPartial derivative of a single element:
∂L∂xij=∑i,j∂L∂yij⋅∂yij∂xij=∂L∂yji⋅∂yji∂xij=∂L∂yji⋅∂xij∂xij=∂L∂yjiMatrix derivative:
∂L∂X=(∂L∂Y)TGenerally, axes should be a permutation of the dimensions, suppose there is a function f that maps from (0,1,…,k) to the new permutation, then this transpose operation would be:
yi1,i2,…,ik=xf(i1),f(i2),…,f(ik)The partial derivative of xi1,i2,…,ik is 1 only with yf(i1)−1,f(i2)−1,…,f(ik)−1. Therefore the derivative should be another transpose operation with inverse mapping function f−1.
-
__init__
(x: auto_diff.op.operation.Operation, axes: Optional[Sequence[int]] = None, **kwargs)[source]¶ Parameters: - x – Input operation.
- axes – A permutation of dimensions. The dimensions will be reversed if it is None.
- kwargs – Arguments for parent.
-
auto_diff.op.op_variable module¶
-
class
auto_diff.op.op_variable.
OpVariable
(initializer: Union[Callable, int, float, list, numpy.ndarray], shape: tuple = None, **kwargs)[source]¶ Bases:
auto_diff.op.operation.Operation
Contains weights that could be updated.
-
__init__
(initializer: Union[Callable, int, float, list, numpy.ndarray], shape: tuple = None, **kwargs)[source]¶ Parameters: - initializer – A function that accepts shape as its arguments or a numpy array.
- shape – Must be provided if the initializer is a function.
- kwargs –
-
auto_diff.op.operation module¶
-
class
auto_diff.op.operation.
Operation
(**kwargs)[source]¶ Bases:
object
Abstract operation for building computing graph.
-
__op_counter
= None¶ The counter for giving each operation a unique index.
-
__op_collection
= None¶ Collection of existing operations.
-
STEP_KEY
= '__step__'¶ The key for extracting step information from session.
-
dim
¶
-
forward
(feed_dict: Mapping[Union[str, Operation], numpy.ndarray] = None) → numpy.ndarray[source]¶ Do the calculations to get the output of the operations.
Parameters: feed_dict – Contains the real values of placeholders, see OpPlaceholder
.Returns: A numpy array.
-
_forward
(feed_dict: Mapping[Union[str, Operation], numpy.ndarray]) → numpy.ndarray[source]¶ Forward operation to be implemented.
-
backward
(gradient: Optional[auto_diff.op.operation.Operation] = None) → None[source]¶ Update gradients recursively.
Parameters: gradient – Current gradient.
-
_backward
(gradient: auto_diff.op.operation.Operation) → None[source]¶ Backward operation to be implemented.
-
transpose
(axes: Optional[Sequence[int]] = None, **kwargs) → auto_diff.op.operation.Operation[source]¶ See
OpTranspose
.
-
expand_dims
(axis: Optional[int] = None, **kwargs) → auto_diff.op.operation.Operation[source]¶ See
OpExpandDims
.
-
sum
(axis: Union[int, Sequence[int], None] = None, keepdims: bool = False, **kwargs) → auto_diff.op.operation.Operation[source]¶ See
OpSum
.
-
dot
(x: auto_diff.op.operation.Operation, **kwargs) → auto_diff.op.operation.Operation[source]¶ See
OpDot
.
-
_Operation__op_collection
= {}¶
-
_Operation__op_counter
= [0]¶
-