Class: Micrograd::PowOp

Inherits:
Struct
  • Object
show all
Defined in:
lib/micrograd/op.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nObject

Returns the value of attribute n

Returns:

  • (Object)

    the current value of n



36
37
38
# File 'lib/micrograd/op.rb', line 36

def n
  @n
end

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of 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