Class: Micrograd::TanhOp

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



28
29
30
# File 'lib/micrograd/op.rb', line 28

def x
  @x
end

Instance Method Details

#backward(value) ⇒ Object



29
30
31
32
33
# File 'lib/micrograd/op.rb', line 29

def backward(value)
  x.grad += (1 - value.data**2) * value.grad
  x.backward
rescue
end