-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reset rolling and add activation for amm
- Loading branch information
1 parent
61d3eba
commit ea62a55
Showing
11 changed files
with
209 additions
and
68 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
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
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,73 @@ | ||
""" | ||
Author: Wenyu Ouyang | ||
Date: 2025-01-01 10:20:02 | ||
LastEditTime: 2025-01-01 10:48:40 | ||
LastEditors: Wenyu Ouyang | ||
Description: test function for multi-layer perceptron model | ||
FilePath: \torchhydro\tests\test_ann.py | ||
Copyright (c) 2023-2024 Wenyu Ouyang. All rights reserved. | ||
""" | ||
|
||
import pytest | ||
from torch import nn | ||
from torchhydro.models.ann import SimpleAnn | ||
import torch | ||
|
||
|
||
def test_get_activation_tanh(): | ||
model = SimpleAnn(1, 1) | ||
activation = model._get_activation("tanh") | ||
assert isinstance(activation, nn.Tanh) | ||
|
||
|
||
def test_get_activation_sigmoid(): | ||
model = SimpleAnn(1, 1) | ||
activation = model._get_activation("sigmoid") | ||
assert isinstance(activation, nn.Sigmoid) | ||
|
||
|
||
def test_get_activation_relu(): | ||
model = SimpleAnn(1, 1) | ||
activation = model._get_activation("relu") | ||
assert isinstance(activation, nn.ReLU) | ||
|
||
|
||
def test_get_activation_linear(): | ||
model = SimpleAnn(1, 1) | ||
activation = model._get_activation("linear") | ||
assert isinstance(activation, nn.Identity) | ||
|
||
|
||
def test_get_activation_not_implemented(): | ||
model = SimpleAnn(1, 1) | ||
with pytest.raises(NotImplementedError): | ||
model._get_activation("unsupported_activation") | ||
|
||
|
||
def test_forward_single_layer(): | ||
model = SimpleAnn(3, 2, hidden_size=0) | ||
x = torch.randn(5, 3) | ||
output = model.forward(x) | ||
assert output.shape == (5, 2) | ||
|
||
|
||
def test_forward_multiple_layers(): | ||
model = SimpleAnn(3, 2, hidden_size=[4, 5], dr=[0.1, 0.2]) | ||
x = torch.randn(5, 3) | ||
output = model.forward(x) | ||
assert output.shape == (5, 2) | ||
|
||
|
||
def test_forward_with_dropout(): | ||
model = SimpleAnn(3, 2, hidden_size=[4, 5], dr=[0.1, 0.2]) | ||
model.train() # Enable dropout | ||
x = torch.randn(5, 3) | ||
output = model.forward(x) | ||
assert output.shape == (5, 2) | ||
|
||
|
||
def test_forward_activation(): | ||
model = SimpleAnn(3, 2, hidden_size=[4, 5], activation="sigmoid") | ||
x = torch.randn(5, 3) | ||
output = model.forward(x) | ||
assert output.shape == (5, 2) |
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
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
Oops, something went wrong.