-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from brendanhasz/refactor-tests-2020-12-23
Add KL divergence between Deterministic + others for pytorch
- Loading branch information
Showing
131 changed files
with
5,083 additions
and
3,805 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 2.1.0 | ||
current_version = 2.1.1 | ||
|
||
[bumpversion:file:setup.py] | ||
|
||
|
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,2 +1,4 @@ | ||
[flake8] | ||
ignore = E203,E501,W503,E731,E741,F401,F403,F405 | ||
ignore = E203,E501,W503,E731,E741 | ||
per-file-ignores = | ||
src/probflow/__init__.py:F401,F403 |
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 |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
from probflow.utils.io import * | ||
from probflow.utils.settings import * | ||
|
||
__version__ = "2.1.0" | ||
__version__ = "2.1.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
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 |
---|---|---|
|
@@ -139,5 +139,4 @@ def calibration_curve( | |
TODO: Docs... | ||
""" | ||
pass | ||
# TODO |
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 |
---|---|---|
|
@@ -895,5 +895,4 @@ def summary(self): | |
model would have to add to it the observation dist | ||
""" | ||
pass | ||
# TODO |
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,4 +1,4 @@ | ||
from typing import Callable, List, Union | ||
from typing import Callable, List | ||
|
||
import probflow.utils.ops as O | ||
|
||
|
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
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
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
import numpy as np | ||
import pandas as pd | ||
import tensorflow as tf | ||
|
||
import probflow as pf | ||
|
||
|
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
|
||
import numpy as np | ||
import tensorflow as tf | ||
|
||
import probflow as pf | ||
|
||
|
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,42 @@ | ||
import numpy as np | ||
|
||
from probflow.applications import DenseClassifier | ||
|
||
|
||
def test_DenseClassifier(): | ||
"""Tests probflow.applications.DenseClassifier""" | ||
|
||
# Data | ||
x = np.random.randn(100, 5).astype("float32") | ||
w = np.random.randn(5, 1).astype("float32") | ||
y = x @ w + 1 | ||
y = np.round(1.0 / (1.0 + np.exp(-y))).astype("float32") | ||
|
||
# Create the model | ||
model = DenseClassifier([5, 20, 15, 2]) | ||
|
||
# Fit the model | ||
model.fit(x, y, batch_size=10, epochs=3) | ||
|
||
# Predictive functions | ||
model.predict(x) | ||
|
||
|
||
def test_MultinomialDenseClassifier(): | ||
"""Tests probflow.applications.DenseClassifier w/ >2 output classes""" | ||
|
||
# Data | ||
x = np.random.randn(100, 5).astype("float32") | ||
w = np.random.randn(5, 3).astype("float32") | ||
b = np.random.randn(1, 3).astype("float32") | ||
y = x @ w + b | ||
y = np.argmax(y, axis=1).astype("int32") | ||
|
||
# Create the model | ||
model = DenseClassifier([5, 20, 15, 3]) | ||
|
||
# Fit the model | ||
model.fit(x, y, batch_size=10, epochs=3) | ||
|
||
# Predictive functions | ||
model.predict(x) |
103 changes: 103 additions & 0 deletions
103
tests/unit/pytorch/applications/test_dense_regression.py
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,103 @@ | ||
import numpy as np | ||
|
||
from probflow.applications import DenseRegression | ||
|
||
|
||
def test_DenseRegression(): | ||
"""Tests probflow.applications.DenseRegression""" | ||
|
||
# Data | ||
x = np.random.randn(100, 5).astype("float32") | ||
w = np.random.randn(5, 1).astype("float32") | ||
y = x @ w + 1 | ||
|
||
# Create the model | ||
model = DenseRegression([5, 20, 15, 1]) | ||
|
||
# Fit the model | ||
model.fit(x, y, batch_size=10, epochs=3) | ||
|
||
# Predictive functions | ||
preds = model.predict(x[:11, :]) | ||
assert isinstance(preds, np.ndarray) | ||
assert preds.ndim == 2 | ||
assert preds.shape[0] == 11 | ||
assert preds.shape[1] == 1 | ||
|
||
# predictive interval | ||
lb, ub = model.predictive_interval(x[:12, :], ci=0.9) | ||
assert isinstance(lb, np.ndarray) | ||
assert lb.ndim == 2 | ||
assert lb.shape[0] == 12 | ||
assert lb.shape[1] == 1 | ||
assert isinstance(ub, np.ndarray) | ||
assert ub.ndim == 2 | ||
assert ub.shape[0] == 12 | ||
assert ub.shape[1] == 1 | ||
|
||
|
||
def test_DenseRegression_heteroscedastic(): | ||
"""Tests probflow.applications.DenseRegression w/ heteroscedastic""" | ||
|
||
# Data | ||
x = np.random.randn(100, 5).astype("float32") | ||
w = np.random.randn(5, 1).astype("float32") | ||
y = x @ w + 1 | ||
y = y + np.exp(y) * np.random.randn(100, 1).astype("float32") | ||
|
||
# Create the model | ||
model = DenseRegression([5, 20, 15, 1], heteroscedastic=True) | ||
|
||
# Fit the model | ||
model.fit(x, y, batch_size=10, epochs=3) | ||
|
||
# Predictive functions | ||
preds = model.predict(x[:11, :]) | ||
assert isinstance(preds, np.ndarray) | ||
assert preds.ndim == 2 | ||
assert preds.shape[0] == 11 | ||
assert preds.shape[1] == 1 | ||
|
||
# predictive interval | ||
lb, ub = model.predictive_interval(x[:12, :], ci=0.9) | ||
assert isinstance(lb, np.ndarray) | ||
assert lb.ndim == 2 | ||
assert lb.shape[0] == 12 | ||
assert lb.shape[1] == 1 | ||
assert isinstance(ub, np.ndarray) | ||
assert ub.ndim == 2 | ||
assert ub.shape[0] == 12 | ||
assert ub.shape[1] == 1 | ||
|
||
|
||
def test_DenseRegression_multivariate(): | ||
"""Tests probflow.applications.DenseRegression w/ >1 output dims""" | ||
|
||
# Data | ||
N = 256 | ||
Di = 7 | ||
Do = 3 | ||
x = np.random.randn(N, Di).astype("float32") | ||
w = np.random.randn(Di, Do).astype("float32") | ||
y = x @ w + 0.1 * np.random.randn(N, Do).astype("float32") | ||
|
||
# Create the model | ||
model = DenseRegression([Di, 16, Do]) | ||
|
||
# Fit the model | ||
model.fit(x, y, batch_size=128, epochs=3) | ||
|
||
# Predictive functions | ||
preds = model.predict(x[:11, :]) | ||
assert isinstance(preds, np.ndarray) | ||
assert preds.ndim == 2 | ||
assert preds.shape[0] == 11 | ||
assert preds.shape[1] == Do | ||
|
||
# Predictive functions | ||
preds = model.predictive_sample(x[:11, :], n=13) | ||
assert isinstance(preds, np.ndarray) | ||
assert preds.ndim == 3 | ||
assert preds.shape[0] == 13 | ||
assert preds.shape[1] == 11 | ||
assert preds.shape[2] == Do |
Oops, something went wrong.