math.operator
- class tinychain.math.operator.Abs(subject)[source]
Bases:
Unary- backward(_variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Acos(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Acosh(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Add(subject, args)[source]
Bases:
DualBroadcast- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Asin(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Asinh(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Atan(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Atanh(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Cond(subject, args)[source]
Bases:
OperatorA boolean condition
- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Cos(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Cosh(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Custom(subject)[source]
Bases:
UnaryA custom operator
- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- forward()
Return the result of evaluating this Operator
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Div(subject, args)[source]
Bases:
DualBroadcast- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Dual(subject, args)[source]
Bases:
OperatorA differentiable operator with two arguments
- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- forward()
Return the result of evaluating this Operator
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.DualBroadcast(subject, args)[source]
Bases:
Operator- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- forward()
Return the result of evaluating this Operator
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Exp(subject)[source]
Bases:
Unary- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Gradients[source]
Bases:
dict- clear() None. Remove all items from D.
- copy() a shallow copy of D
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F.[source]
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values
- class tinychain.math.operator.Log(subject, args)[source]
Bases:
Operator- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.LogicalAnd(subject, args)[source]
Bases:
DualBroadcast- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.LogicalNot(subject)[source]
Bases:
Unary- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.LogicalOr(subject, args)[source]
Bases:
DualBroadcast- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.LogicalXor(subject, args)[source]
Bases:
DualBroadcast- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.MatMul(subject, args)[source]
Bases:
Dual- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Mul(subject, args)[source]
Bases:
DualBroadcast- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Operator(subject, args)[source]
Bases:
OpA differentiable operator like addition, multiplication, exponentiation, etc.
- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Pow(subject, args)[source]
Bases:
Dual- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Sin(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Sinh(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Sub(subject, args)[source]
Bases:
DualBroadcast- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Tan(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Tanh(subject)[source]
Bases:
Trig- backward(variable=None)[source]
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- gradients(loss)[source]
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Trig(subject)[source]
Bases:
Unary- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- forward()
Return the result of evaluating this Operator
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()[source]
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- class tinychain.math.operator.Unary(subject)[source]
Bases:
Operator- backward(variable=None)
Return the derivative of this
Operator(may be a numeric constant or itself anOperator).If a variable is specified, this will be the partial derivative w/r/t the given variable.
- forward()
Return the result of evaluating this Operator
- gradients(loss)
Return the
GradientsthisOperatorwith respect to the given variables.If no variables are specified, this will return the Gradients of each
Variablethat this Operator depends on.
- property shape
The shape of the result of this operation
- simplify()
Return a simplified but logically equivalent version of this
Operator, if possible. For example, Mul(2, 1).simplify() will return 2.IMPORTANT: don’t call simplify until after constructing an entire operator graph. This is because simplify may discard parts of the operator graph needed to apply the chain rule correctly.
- tinychain.math.operator.chain_rule(op, *args)[source]
Compute the chain rule coefficient of the given
Operator.This function will return 1 if the given numeric is constant, or has only constant inputs.
- tinychain.math.operator.constant(numeric)[source]
Return the given numeric state as a constant, i.e. not the result of a differentiable
Operator.
- tinychain.math.operator.derivative_of(state_or_function, variable=None, keepdims=False)[source]
Find the derivative of the given state_or_function.
If a differentiable state is given, this will construct a new op to calculate it derivative, which can be a partial derivative if a variable is specified.
If a differentiable function is given, a new callable function will be returned which computes its derivative.
If state_or_function is not differentiable, a TypeError will be raised.
- tinychain.math.operator.gradients(numeric, loss, variables=None)[source]
Return the gradient of a numeric state with respect to the given loss.
If one variable is given, one gradient will be returned, or a KeyError will be raised if not present in the graph. If a list of variables is given, a corresponding list of gradients will be returned. If no variables are given, a
Gradientsobject whose keys are the inputs of the graph will be returned.
- tinychain.math.operator.is_constant(numeric)[source]
Return False if the given numeric state is the result of an
Operator, i.e. a differentiable function.
- tinychain.math.operator.is_one(numeric)[source]
Return True if the given numeric state is a constant with value one.
- tinychain.math.operator.is_zero(numeric)[source]
Return True if the given numeric state is a constant with value zero.
- tinychain.math.operator.ones_like(numeric, keepdims=True)[source]
Construct a constant with each element equal to one, with the same shape and data type as numeric.
- tinychain.math.operator.operator(state_or_ref)[source]
Return the Operator instance which produces the given state_or_ref, if any