Operations¶
auto_diff.Operation is used for representing calculation graphs. All the operations (e.g. sum, dot) are subclasses of auto_diff.Operation. The names and arguments of these operations follow the definitions of numpy, therefore you can use the operations similar to numpy:
import auto_diff as np
x = np.array([[1, 2], [3, 4]])
y = np.array([[5, 6], [7, 8]])
z = np.dot(x, y)
However, the result of operations is another operation, no real calculation is performed in this stage. You need to call forward explicitly to get the final result:
print(z)
print(z.forward())
-
class
auto_diff.Operation(**kwargs)[source]¶ Bases:
objectAbstract 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]¶
-