Skip to content

Commit

Permalink
Add tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
thieu1995 committed Aug 15, 2023
1 parent 82441a7 commit 72de14c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python
# Created by "Thieu" at 15:45, 15/08/2023 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%
22 changes: 22 additions & 0 deletions tests/test_MhaElmClassifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# Created by "Thieu" at 15:45, 15/08/2023 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%

import numpy as np
from intelelm import MhaElmClassifier

np.random.seed(41)


def test_MhaElmClassifier_class():
X = np.random.rand(100, 6)
y = np.random.randint(0, 2, size=100)

opt_paras = {"name": "GA", "epoch": 10, "pop_size": 30}
model = MhaElmClassifier(hidden_size=10, act_name="elu", obj_name="AS", optimizer="BaseGA", optimizer_paras=opt_paras, verbose=False)
model.fit(X, y)
pred = model.predict(X)
assert MhaElmClassifier.SUPPORTED_CLS_OBJECTIVES == model.SUPPORTED_CLS_OBJECTIVES
assert pred[0] in (0, 1)
24 changes: 24 additions & 0 deletions tests/test_MhaElmRegressor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python
# Created by "Thieu" at 15:45, 15/08/2023 ----------%
# Email: nguyenthieu2102@gmail.com %
# Github: https://github.com/thieu1995 %
# --------------------------------------------------%

import numpy as np
from intelelm import MhaElmRegressor

np.random.seed(42)


def test_MhaElmRegressor_class():
X = np.random.uniform(low=0.0, high=1.0, size=(100, 5))
noise = np.random.normal(loc=0.0, scale=0.1, size=(100, 5))
y = 2 * X + 1 + noise

opt_paras = {"name": "GA", "epoch": 10, "pop_size": 30}
model = MhaElmRegressor(hidden_size=10, act_name="elu", obj_name="RMSE", optimizer="BaseGA", optimizer_paras=opt_paras, verbose=False)
model.fit(X, y)

pred = model.predict(X)
assert MhaElmRegressor.SUPPORTED_REG_OBJECTIVES == model.SUPPORTED_REG_OBJECTIVES
assert len(pred) == X.shape[0]

0 comments on commit 72de14c

Please sign in to comment.