-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add new data generators * Update pre-commit hooks and reformat. * remove protobuf from requirements.txt * Specify NT version * Add tests for generators and add MPG + Abalone * Update comment
- Loading branch information
Showing
15 changed files
with
690 additions
and
10 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,47 @@ | ||
""" | ||
ZnNL: A Zincwarecode package. | ||
License | ||
------- | ||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License v2.0 which accompanies this distribution, and is | ||
available at https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zincwarecode Project. | ||
Contact Information | ||
------------------- | ||
email: zincwarecode@gmail.com | ||
github: https://github.com/zincware | ||
web: https://zincwarecode.com/ | ||
Citation | ||
-------- | ||
If you use this module please cite us with: | ||
Summary | ||
------- | ||
Test Abaone generator. | ||
""" | ||
from znnl.data import AbaloneDataGenerator | ||
|
||
|
||
class TestAbaloneGenerator: | ||
""" | ||
Class for testing the Abalone generator. | ||
""" | ||
|
||
def test_creation(self): | ||
""" | ||
Test if one can create the generator. | ||
""" | ||
generator = AbaloneDataGenerator(train_fraction=0.8) | ||
|
||
assert generator is not None | ||
assert generator.train_ds["inputs"].shape == (3342, 10) | ||
assert generator.train_ds["targets"].shape == (3342, 1) | ||
|
||
assert generator.test_ds["inputs"].shape == (835, 10) | ||
assert generator.test_ds["targets"].shape == (835, 1) |
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,60 @@ | ||
""" | ||
ZnNL: A Zincwarecode package. | ||
License | ||
------- | ||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License v2.0 which accompanies this distribution, and is | ||
available at https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zincwarecode Project. | ||
Contact Information | ||
------------------- | ||
email: zincwarecode@gmail.com | ||
github: https://github.com/zincware | ||
web: https://zincwarecode.com/ | ||
Citation | ||
-------- | ||
If you use this module please cite us with: | ||
Summary | ||
------- | ||
Test CIFAR10 generator. | ||
""" | ||
from znnl.data import CIFAR10Generator | ||
|
||
|
||
class TestCIFARGenerator: | ||
""" | ||
Class for testing the CIFAR generator. | ||
""" | ||
|
||
def test_one_hot_creation(self): | ||
""" | ||
Test if one can create the generator. | ||
""" | ||
generator = CIFAR10Generator(ds_size=500) | ||
|
||
assert generator is not None | ||
assert generator.train_ds["inputs"].shape == (500, 32, 32, 3) | ||
assert generator.train_ds["targets"].shape == (500, 10) | ||
|
||
assert generator.test_ds["inputs"].shape == (500, 32, 32, 3) | ||
assert generator.test_ds["targets"].shape == (500, 10) | ||
|
||
def test_serial_creation(self): | ||
""" | ||
Test if one can create the generator. | ||
""" | ||
generator = CIFAR10Generator(ds_size=500, one_hot_encoding=False) | ||
|
||
assert generator is not None | ||
assert generator.train_ds["inputs"].shape == (500, 32, 32, 3) | ||
assert generator.train_ds["targets"].shape == (500, 1) | ||
|
||
assert generator.test_ds["inputs"].shape == (500, 32, 32, 3) | ||
assert generator.test_ds["targets"].shape == (500, 1) |
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,93 @@ | ||
""" | ||
ZnNL: A Zincwarecode package. | ||
License | ||
------- | ||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License v2.0 which accompanies this distribution, and is | ||
available at https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zincwarecode Project. | ||
Contact Information | ||
------------------- | ||
email: zincwarecode@gmail.com | ||
github: https://github.com/zincware | ||
web: https://zincwarecode.com/ | ||
Citation | ||
-------- | ||
If you use this module please cite us with: | ||
Summary | ||
------- | ||
Unit test for the decision boundary. | ||
""" | ||
import jax.numpy as np | ||
import numpy as onp | ||
from pytest import approx | ||
|
||
from znnl.data.decision_boundary import ( | ||
DecisionBoundaryGenerator, | ||
circle, | ||
linear_boundary, | ||
) | ||
|
||
|
||
class TestDecisionBoundary: | ||
""" | ||
Unit test for the decision boundary. | ||
""" | ||
|
||
def test_linear_boundary(self): | ||
""" | ||
Test the linear boundary. | ||
""" | ||
target_ratio = 0.0 | ||
for _ in range(10): | ||
input_data = onp.random.uniform(0, 1, size=(10000, 2)) | ||
target_ratio += linear_boundary(input_data, 1.0, 0.0).mean() | ||
|
||
assert target_ratio / 10 == approx(0.5, rel=0.01) | ||
|
||
def test_circle(self): | ||
""" | ||
Test the circle boundary. | ||
""" | ||
target_ratio = 0.0 | ||
for _ in range(10): | ||
input_data = onp.random.uniform(0, 1, size=(10000, 2)) | ||
target_ratio += circle(input_data, 0.25).mean() | ||
|
||
# P(x in class 1) = 1 - (pi / 16) | ||
assert target_ratio / 10 == approx(1 - (np.pi / 16), abs=0.01) | ||
|
||
def test_one_hot_decision_boundary_generator(self): | ||
""" | ||
Test the actual generator. | ||
""" | ||
generator = DecisionBoundaryGenerator( | ||
n_samples=10000, discriminator="circle", one_hot=True | ||
) | ||
|
||
# Check the dataset shapes | ||
assert generator.train_ds["inputs"].shape == (10000, 2) | ||
assert generator.train_ds["targets"].shape == (10000, 2) | ||
assert generator.test_ds["inputs"].shape == (10000, 2) | ||
assert generator.test_ds["targets"].shape == (10000, 2) | ||
|
||
def test_serial_decision_boundary_generator(self): | ||
""" | ||
Test the actual generator. | ||
""" | ||
generator = DecisionBoundaryGenerator( | ||
n_samples=10000, discriminator="circle", one_hot=False | ||
) | ||
|
||
# Check the dataset shapes | ||
assert generator.train_ds["inputs"].shape == (10000, 2) | ||
assert generator.train_ds["targets"].shape == (10000, 1) | ||
assert generator.test_ds["inputs"].shape == (10000, 2) | ||
assert generator.test_ds["targets"].shape == (10000, 1) |
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,47 @@ | ||
""" | ||
ZnNL: A Zincwarecode package. | ||
License | ||
------- | ||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License v2.0 which accompanies this distribution, and is | ||
available at https://www.eclipse.org/legal/epl-v20.html | ||
SPDX-License-Identifier: EPL-2.0 | ||
Copyright Contributors to the Zincwarecode Project. | ||
Contact Information | ||
------------------- | ||
email: zincwarecode@gmail.com | ||
github: https://github.com/zincware | ||
web: https://zincwarecode.com/ | ||
Citation | ||
-------- | ||
If you use this module please cite us with: | ||
Summary | ||
------- | ||
Test MPG generator. | ||
""" | ||
from znnl.data import MPGDataGenerator | ||
|
||
|
||
class TestMPGGenerator: | ||
""" | ||
Class for testing the MPG generator. | ||
""" | ||
|
||
def test_creation(self): | ||
""" | ||
Test if one can create the generator. | ||
""" | ||
generator = MPGDataGenerator(train_fraction=0.8) | ||
|
||
assert generator is not None | ||
assert generator.train_ds["inputs"].shape == (314, 9) | ||
assert generator.train_ds["targets"].shape == (314, 1) | ||
|
||
assert generator.test_ds["inputs"].shape == (78, 9) | ||
assert generator.test_ds["targets"].shape == (78, 1) |
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.