Class: NeuralNetworkRb::Activations::ReLU
- Inherits:
-
Object
- Object
- NeuralNetworkRb::Activations::ReLU
- Defined in:
- lib/neural_network_rb/activations/relu.rb
Instance Method Summary collapse
- #calc(x) ⇒ Object
- #grad(output) ⇒ Object
-
#initialize(next_layer, options = {}) ⇒ ReLU
constructor
A new instance of ReLU.
- #predict(input) ⇒ Object
- #train(input, target) ⇒ Object
Constructor Details
#initialize(next_layer, options = {}) ⇒ ReLU
Returns a new instance of ReLU.
7 8 9 |
# File 'lib/neural_network_rb/activations/relu.rb', line 7 def initialize(next_layer, = {}) @next_layer = next_layer end |
Instance Method Details
#calc(x) ⇒ Object
20 21 22 |
# File 'lib/neural_network_rb/activations/relu.rb', line 20 def calc(x) x * (x > 0) end |
#grad(output) ⇒ Object
24 25 26 |
# File 'lib/neural_network_rb/activations/relu.rb', line 24 def grad(output) 1.0 * (output > 0) end |
#predict(input) ⇒ Object
16 17 18 |
# File 'lib/neural_network_rb/activations/relu.rb', line 16 def predict(input) @next_layer.predict(calc(input)) end |
#train(input, target) ⇒ Object
11 12 13 14 |
# File 'lib/neural_network_rb/activations/relu.rb', line 11 def train(input, target) output = calc(input) grad(output) * @next_layer.train(output, target) end |