Class: Micrograd::PowOp
- Inherits:
-
Struct
- Object
- Struct
- Micrograd::PowOp
- Defined in:
- lib/micrograd/op.rb
Instance Attribute Summary collapse
-
#n ⇒ Object
Returns the value of attribute n.
-
#x ⇒ Object
Returns the value of attribute x.
Instance Method Summary collapse
Instance Attribute Details
#n ⇒ Object
Returns the value of attribute n
36 37 38 |
# File 'lib/micrograd/op.rb', line 36 def n @n end |
#x ⇒ Object
Returns the value of attribute x
36 37 38 |
# File 'lib/micrograd/op.rb', line 36 def x @x end |
Instance Method Details
#backward(value) ⇒ Object
37 38 39 40 41 |
# File 'lib/micrograd/op.rb', line 37 def backward(value) x.grad += n * (x.data ** (n-1)) * value.grad x.backward end |