Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
super(GaussianNoise, self).__init__(scope=scope, **kwargs)
self.mean = mean
self.sd = sd
def noise(self):
if backend == "tf":
return tf.random_normal(
shape=(1,) + self.action_space.shape,
mean=self.mean,
stddev=self.sd,
dtype=self.action_space.dtype
)
class ConstantNoise(NoiseComponent):
"""
Simple constant noise component.
"""
def __init__(self, value=0.0, scope="constant_noise", **kwargs):
super(ConstantNoise, self).__init__(scope=scope, **kwargs)
self.value = value
def noise(self):
if backend == "tf":
return tf.constant(self.value)
DataOp: The noise value.
"""
return tf.constant(0.0)
def _graph_fn_value(self):
"""
Args:
action (DataOp): The float-type action value.
Returns:
DataOp: The noise value.
"""
return self.noise()
class GaussianNoise(NoiseComponent):
"""
Simple Gaussian noise component.
"""
def __init__(self, mean=0.0, sd=1.0, scope="gaussian_noise", **kwargs):
super(GaussianNoise, self).__init__(scope=scope, **kwargs)
self.mean = mean
self.sd = sd
def noise(self):
if backend == "tf":
return tf.random_normal(
shape=(1,) + self.action_space.shape,
mean=self.mean,
stddev=self.sd,
dtype=self.action_space.dtype
def __init__(self, action_space, scope="noise", **kwargs):
"""
Args:
action_space: The action space.
"""
super(NoiseComponent, self).__init__(scope=scope, **kwargs)
self.action_space = action_space
# Our interface.
self.define_outputs("noise")
self.add_graph_fn(None, "noise", self._graph_fn_value)