Class: RubyZero::Core::Functions::Function
- Inherits:
-
Object
- Object
- RubyZero::Core::Functions::Function
- Defined in:
- lib/rubyzero/core/functions/function.rb
Overview
Function class
Direct Known Subclasses
Add, Div, DivScalar, DotProduct, Exp, Log, Mean, Mul, MulScalar, Neg, Pow, ReLU, Repeat, Reshape, Sigmoid, Sub, Sum, SwapAxes
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #backward(*args, **kwargs, &block) ⇒ Object
- #call(*args) ⇒ Object
- #forward(*args, **kwargs, &block) ⇒ Object
-
#initialize(*args, **kwargs, &block) ⇒ Function
constructor
A new instance of Function.
- #inspect ⇒ Object
Constructor Details
#initialize(*args, **kwargs, &block) ⇒ Function
Returns a new instance of Function.
8 9 10 |
# File 'lib/rubyzero/core/functions/function.rb', line 8 def initialize(*args, **kwargs, &block) end |
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
7 8 9 |
# File 'lib/rubyzero/core/functions/function.rb', line 7 def inputs @inputs end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/rubyzero/core/functions/function.rb', line 7 def output @output end |
Class Method Details
.plot(range: (-10..10).step(0.01)) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/rubyzero/core/functions/function.rb', line 29 def self.plot(range: (-10..10).step(0.01)) inputs = range.to_a outputs = inputs.map{|t| self.new().call(RubyZero::Core::Tensor.new(t)).data[0]} plot = UnicodePlot.lineplot(inputs, outputs, name: self.name) plot.render end |
Instance Method Details
#backward(*args, **kwargs, &block) ⇒ Object
14 15 16 |
# File 'lib/rubyzero/core/functions/function.rb', line 14 def backward(*args, **kwargs, &block) raise Execptions::NotImplementedError, "#{self.class}#backward() not implemented" end |
#call(*args) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/rubyzero/core/functions/function.rb', line 17 def call(*args) @inputs = args @output = forward(*args) if @inputs.any?{|t| t.requires_grad?} @output.grad_fn = self @output.requires_grad = true end return @output end |
#forward(*args, **kwargs, &block) ⇒ Object
11 12 13 |
# File 'lib/rubyzero/core/functions/function.rb', line 11 def forward(*args, **kwargs, &block) raise Execptions::NotImplementedError, "#{self.class}#forward() not implemented" end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/rubyzero/core/functions/function.rb', line 26 def inspect return "#<#{self.class}>" end |