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: 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.

__init__(**kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

_get_name() → str[source]

Get the name for display.

_get_op_name() → str[source]

Get the name for indexing.

dim
isscalar() → bool[source]
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.

_broadcast_shape(x: auto_diff.op.operation.Operation, y: auto_diff.op.operation.Operation)[source]
_broadcast_backward(gradient: auto_diff.op.operation.Operation)[source]
transpose(axes: Optional[Sequence[int]] = None, **kwargs) → auto_diff.op.operation.Operation[source]

See OpTranspose.

reshape(shape: Sequence[int], **kwargs) → auto_diff.op.operation.Operation[source]

See OpReshape.

flatten(**kwargs) → auto_diff.op.operation.Operation[source]

See OpFlatten.

expand_dims(axis: Optional[int] = None, **kwargs) → auto_diff.op.operation.Operation[source]

See OpExpandDims.

squeeze(axis=None, **kwargs) → auto_diff.op.operation.Operation[source]

See OpSqueeze.

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.

simplify() → auto_diff.op.operation.Operation[source]
_Operation__op_collection = {}
_Operation__op_counter = [0]