This repository has been archived by the owner on Feb 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add unittest for PCAEncoder
- Loading branch information
1 parent
5a745b1
commit 16fa80b
Showing
2 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import unittest | ||
import numpy as np | ||
|
||
from gnes.encoder.base import BaseEncoder | ||
|
||
|
||
class TestPCAEncoder(unittest.TestCase): | ||
|
||
def setUp(self): | ||
dirname = os.path.dirname(__file__) | ||
self.dump_path = os.path.join(dirname, 'pca_encoder.bin') | ||
self.yaml_path = os.path.join(dirname, 'yaml', 'pca.yml') | ||
self.test_numeric = np.random.randint(0, 255, (1000, 1024)).astype('float32') | ||
|
||
def test_encoding(self): | ||
self.encoder = BaseEncoder.load_yaml(self.yaml_path) | ||
# train before encode to create pca_components | ||
self.encoder.train(self.test_numeric) | ||
vec = self.encoder.encode(self.test_numeric) | ||
self.assertEqual(vec.shape, (1000, 300)) | ||
# dump after train with valied pca_components | ||
self.encoder.dump(self.dump_path) | ||
encoder2 = BaseEncoder.load(self.dump_path) | ||
vec = encoder2.encode(self.test_numeric) | ||
self.assertEqual(vec.shape, (1000, 300)) | ||
|
||
def tearDown(self): | ||
if os.path.exists(self.dump_path): | ||
os.remove(self.dump_path) |
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,8 @@ | ||
!PCAEncoder | ||
parameters: | ||
output_dim: 300 | ||
gnes_config: | ||
name: pca_encoder | ||
on_gpu: false | ||
work_dir: ./ | ||
|