-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve #18: Levinson (chapter 5) implementation coverage testing
- removed prints from implementations and tests, added proper logging instead
- Loading branch information
1 parent
0d3dc09
commit 204321d
Showing
7 changed files
with
167 additions
and
69 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 |
---|---|---|
|
@@ -3,8 +3,13 @@ __pycache__ | |
*.egg-info | ||
env | ||
.pyenv* | ||
.env* | ||
.coverage | ||
.vscode | ||
|
||
.ipynb_checkpoints | ||
|
||
dsp | ||
|
||
# images | ||
*.svg |
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 |
---|---|---|
@@ -1,24 +1,93 @@ | ||
"""""" | ||
"""Test validation of levinson based recursion routines.""" | ||
|
||
import logging | ||
|
||
import numpy as np | ||
from pyssp.levinson import glev, gtor | ||
from pyssp import levinson | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def test_glev(): | ||
'''Example 5.3.1, Page 266''' | ||
r = [4, 2, 1] | ||
b = [9, 6, 12] | ||
|
||
res = glev(r, b) | ||
print(res) | ||
expected = [2, -1, 3] | ||
|
||
sol = levinson.glev(r, b) | ||
logger.info(sol) | ||
|
||
assert np.allclose(sol, expected) | ||
|
||
|
||
def test_gtor(): | ||
def test_gtor() -> None: | ||
'''Based on example 5.2.6''' | ||
expected_rx = np.array([2, -1, -1/4, 1/8]) | ||
|
||
gamma = [1/2, 1/2, 1/2] | ||
epsilon = 2 * (3 / 4)**3 | ||
res = gtor(gamma, epsilon) | ||
true_results = np.array([2, -1, -1/4, 1/8]) | ||
print(res) | ||
rx = levinson.gtor(gamma, epsilon) | ||
assert np.allclose(rx, expected_rx) | ||
|
||
|
||
def test_atog() -> None: | ||
|
||
a = [1, 0.5, -0.1, -0.5] | ||
expected_g = np.array([0.5, 0.2, -0.5]) | ||
|
||
gamma = levinson.atog(a) | ||
logger.info(gamma) | ||
logger.info(expected_g) | ||
|
||
assert np.allclose(gamma, expected_g) | ||
|
||
|
||
def test_rtog() -> None: | ||
rx = [2, -1, -1/4, 1/8] | ||
expected_g = np.array([0.5, 0.5, 0.5]) | ||
|
||
gamma = levinson.rtog(rx) | ||
logger.info(gamma) | ||
logger.info(expected_g) | ||
|
||
assert np.allclose(gamma, expected_g) | ||
|
||
|
||
def test_ator() -> None: | ||
a = [1, 1, 7/8, 1/2] | ||
epsilon = 2 * (3 / 4)**3 | ||
b = epsilon**2 | ||
expected_rx = np.array([2, -1, -1/4, 1/8]) | ||
|
||
rx = levinson.ator(a, b = b) | ||
logger.info(rx) | ||
logger.info(expected_rx) | ||
|
||
assert np.array_equal(rx, expected_rx) | ||
|
||
|
||
def test_gtoa() -> None: | ||
gamma = [0.5, 0.2, -0.5] | ||
expected_a = np.array([1, 0.5, -0.1, -0.5]) | ||
|
||
a = levinson.gtoa(gamma) | ||
logger.info(a) | ||
logger.info(expected_a) | ||
|
||
assert np.allclose(a, expected_a) | ||
|
||
def test_rtoa() -> None: | ||
rx = np.array([2, -1, -1/4, 1/8]) | ||
expected_a = [1, 1, 7/8, 1/2] | ||
expected_eps = 2 * (3 / 4)**3 | ||
|
||
a, eps = levinson.rtoa(rx) | ||
|
||
logger.info(f"{a=}") | ||
logger.info(f"{expected_a=}") | ||
logger.info(f"{eps=}") | ||
logger.info(f"{expected_eps=}") | ||
|
||
assert np.allclose(a, expected_a) and np.allclose(eps, expected_eps) |
Oops, something went wrong.