-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sigmoid activation, support for disabling grad
- Loading branch information
Paul Ilioaica
committed
Sep 19, 2024
1 parent
12c40bc
commit 2d2b9d3
Showing
4 changed files
with
27 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from activation_functions.activation import ActivationFunction | ||
import math | ||
|
||
class SigmoidActivation(ActivationFunction): | ||
def _simgoid(self, x): | ||
return 1 / (1 + math.exp(-x)) | ||
|
||
def forward(self, input): | ||
return self._simgoid(input.value) | ||
|
||
def _build_backward_function(self, input, out): | ||
def _backward(): | ||
input.grad += out.grad * out.value * (1 - out.value) if out.requires_grad else 0 | ||
return _backward |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters