Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# limitations under the License.
# ==============================================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib import autograph
import tensorflow as tf
import numpy as np
from yarl.components import Component
from yarl.spaces import Continuous, Tuple, Dict
class Memory(Component):
def __init__(self, *args, **kwargs):
super(Memory, self).__init__(*args, **kwargs)
self.record_space = Dict(
state=Dict(state1=float, state2=float),
reward=float
)
self.memory = self.get_variable("memory", trainable=False, from_space=self.record_space)
self.index = self.get_variable("index", trainable=False, dtype=int)
self.capacity = 5
# TODO: put this into splitter component:
self.var_list = [self.memory["state"]["state1"], self.memory["state"]["state2"], self.memory["reward"]]
# TODO: this is normally done automatically by Component (see commented-out code below)
self.insert = autograph.to_graph(self.computation_insert, verbose=True, partial_types={int}) #, partial_types={str, tuple})
#self.define_inputs("record")
#self.define_outputs("insert")
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
from yarl.components import Component
class GaussianNoise(Component):
pass
from __future__ import print_function
from math import log
import numpy as np
from six.moves import xrange as range_
from yarl import get_backend, YARLError, SMALL_NUMBER
from yarl.components import Component
from yarl.components.layers import DenseLayer
from yarl.spaces import Space, IntBox, ContainerSpace
if get_backend() == "tf":
import tensorflow as tf
class NNOutputAdapter(Component):
"""
A Component that cleans up a neural network's output and gets it ready for parameterizing a Distribution Component.
Cleanup includes reshaping (for the desired action space), adding a distribution bias, making sure probs are not
0.0 or 1.0, etc..
API:
ins:
nn_output (SingleDataOp): The raw neural net output to be cleaned up for further processing in a
Distribution.
outs:
logits (SingleDataOp): The reshaped, cleaned-up NN output logits (after possible bias) but before being
translated into Distribution parameters (e.g. via Softmax).
parameters (SingleDataOp): The final results of translating the raw NN-output into Distribution-readable
parameters.
"""
def __init__(self, action_output_name=None, biases_spec=False, scope="nn-output-adapter", **kwargs):
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from yarl import backend
from yarl.components import Component
if backend == 'tf':
import tensorflow as tf
class NoiseComponent(Component):
"""
A base class Component that takes an action input and outputs some noise value.
API:
ins:
action (float): The action value input.
outs:
noise (float): The noise value to be added to the action.
"""
def __init__(self, action_space, scope="noise", **kwargs):
"""
Args:
action_space: The action space.
"""
super(NoiseComponent, self).__init__(scope=scope, **kwargs)