-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
22 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .core import Dense, Activation, Reshape, Flatten | ||
from .fancy import Highway, DropOut | ||
from .recurrent import RLayer, LSTM, GRU, ClockworkLayer, Reservoir | ||
from .tensor import PoolLayer, ConvLayer | ||
from .tensor import PoolLayer, ConvLayer, GlobalAveragePooling |
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,4 @@ | ||
class NoBrainer: | ||
|
||
def __init__(self, outshape): | ||
self.outshape = outshape |
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,30 @@ | ||
import unittest | ||
|
||
import numpy as np | ||
|
||
from brainforge import layers | ||
from brainforge.util import testing | ||
|
||
|
||
class TestGlobalAveragePooling(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.inputs = np.empty([3, 5, 5], dtype="float32") | ||
for channel in range(3): | ||
self.inputs[channel] = np.full([5, 5], fill_value=channel+1, dtype="float32") | ||
self.outputs = np.array([1., 2., 3.], dtype="float32") | ||
self.brain = testing.NoBrainer(outshape=self.inputs.shape) | ||
self.layer = layers.GlobalAveragePooling() | ||
self.layer.connect(self.brain) | ||
|
||
def test_forward_pass_is_correct(self): | ||
|
||
output = self.layer.feedforward(self.inputs[None, ...])[0] | ||
np.testing.assert_equal(output, self.outputs) | ||
|
||
def test_backwards_pass_is_correct(self): | ||
|
||
self.layer.feedforward(self.inputs[None, ...]) | ||
delta = self.layer.backpropagate(self.outputs[None, ...])[0] | ||
|
||
np.testing.assert_allclose(delta, self.inputs / 25) |
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