-
Notifications
You must be signed in to change notification settings - Fork 2
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 #34 from fomorians/2.0
Pyoneer w/ 2.0 support
- Loading branch information
Showing
73 changed files
with
1,698 additions
and
1,522 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,6 +1,6 @@ | ||
/pyoneer.egg-info/ | ||
/build/ | ||
/dist/ | ||
/*.egg-info/ | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
|
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,4 +3,4 @@ repos: | |
rev: master | ||
hooks: | ||
- id: black | ||
language_version: python3.6 | ||
language_version: python3.6 |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import tensorflow as tf | ||
|
||
from pyoneer.activations.activations_impl import swish | ||
|
||
|
||
class ActivationsTest(tf.test.TestCase): | ||
def test_swish(self): | ||
x = tf.constant([-1.0, 0.0, +1.0]) | ||
actual = swish(x) | ||
expected = tf.constant([-0.268941, 0.0, 0.731059]) | ||
self.assertAllClose(actual, expected) | ||
|
||
|
||
if __name__ == "__main__": | ||
tf.test.main() |
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,7 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
from pyoneer.debugging.debugging_impl import Stopwatch | ||
|
||
__all__ = ["Stopwatch"] |
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,38 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import tensorflow as tf | ||
|
||
|
||
class Stopwatch(object): | ||
""" | ||
Stopwatch for measuring how long operations take. Great for fast and easy profiling. | ||
Example: | ||
>>> x = tf.constant(1.0) | ||
>>> y = tf.constant(2.0) | ||
>>> with Stopwatch() as watch: | ||
>>> z = x + y | ||
>>> tf.print(watch.duration) | ||
>>> # 0.00021505355834960938 | ||
""" | ||
|
||
def __init__(self): | ||
self.start_time = None | ||
self.end_time = None | ||
self.duration = None | ||
|
||
def start(self): | ||
self.start_time = tf.timestamp() | ||
|
||
def stop(self): | ||
self.end_time = tf.timestamp() | ||
self.duration = self.end_time - self.start_time | ||
|
||
def __enter__(self): | ||
self.start() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
self.stop() |
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,20 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import tensorflow as tf | ||
|
||
from pyoneer.debugging.debugging_impl import Stopwatch | ||
|
||
|
||
class DebuggingTest(tf.test.TestCase): | ||
def test_stopwatch(self): | ||
with Stopwatch() as stopwatch: | ||
pass | ||
self.assertIsNotNone(stopwatch.start_time) | ||
self.assertIsNotNone(stopwatch.end_time) | ||
self.assertIsNotNone(stopwatch.duration) | ||
|
||
|
||
if __name__ == "__main__": | ||
tf.test.main() |
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,7 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
from pyoneer.distributions.distributions_impl import MultiCategorical | ||
|
||
__all__ = ["MultiCategorical"] |
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,35 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import tensorflow as tf | ||
|
||
|
||
class MultiCategorical(object): | ||
""" | ||
Distribution composed of multiple distributions. | ||
Useful for representing `gym.spaces.MultiDiscrete`. | ||
Args: | ||
distributions: list of distributions. | ||
""" | ||
|
||
def __init__(self, distributions): | ||
self.distributions = distributions | ||
|
||
def log_prob(self, value): | ||
values = tf.split(value, len(self.distributions), axis=-1) | ||
log_probs = [ | ||
dist.log_prob(val[..., 0]) for dist, val in zip(self.distributions, values) | ||
] | ||
return tf.math.add_n(log_probs) | ||
|
||
def entropy(self): | ||
return tf.math.add_n([dist.entropy() for dist in self.distributions]) | ||
|
||
def sample(self): | ||
return tf.stack([dist.sample() for dist in self.distributions], axis=-1) | ||
|
||
def mode(self): | ||
return tf.stack([dist.mode() for dist in self.distributions], axis=-1) |
Oops, something went wrong.