Skip to content

Commit 51db4e8

Browse files
committed
added gaussian noise exploration
1 parent 6c9847d commit 51db4e8

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

examples/configs/ddpg.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
"target_update_weight": 0.999,
3333

3434
"actions_exploration": {
35-
"type": "ornstein_uhlenbeck",
35+
"type": "gaussian_noise",
3636
"sigma": 0.2,
37-
"mu": 0.0,
38-
"theta": 0.15
37+
"mu": 0.0
3938
},
4039

4140
"saver": {

tensorforce/core/explorations/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,25 @@
1818
from tensorforce.core.explorations.constant import Constant
1919
from tensorforce.core.explorations.epsilon_anneal import EpsilonAnneal
2020
from tensorforce.core.explorations.epsilon_decay import EpsilonDecay
21+
from tensorforce.core.explorations.gaussian_noise import GaussianNoise
2122
from tensorforce.core.explorations.ornstein_uhlenbeck_process import OrnsteinUhlenbeckProcess
2223

2324

2425
explorations = dict(
2526
constant=Constant,
2627
epsilon_anneal=EpsilonAnneal,
2728
epsilon_decay=EpsilonDecay,
29+
gaussian_noise=GaussianNoise,
2830
ornstein_uhlenbeck=OrnsteinUhlenbeckProcess
2931
)
3032

3133

32-
__all__ = ['Exploration', 'Constant', 'EpsilonAnneal', 'EpsilonDecay', 'OrnsteinUhlenbeckProcess', 'explorations']
34+
__all__ = [
35+
'Exploration',
36+
'Constant',
37+
'EpsilonAnneal',
38+
'EpsilonDecay',
39+
'GaussianNoise',
40+
'OrnsteinUhlenbeckProcess',
41+
'explorations'
42+
]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2017 reinforce.io. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
16+
import tensorflow as tf
17+
18+
from tensorforce.core.explorations import Exploration
19+
20+
21+
class GaussianNoise(Exploration):
22+
"""
23+
Explores via gaussian noise.
24+
"""
25+
26+
def __init__(
27+
self,
28+
sigma=0.3,
29+
mu=0.0,
30+
scope='gaussian_noise',
31+
summary_labels=()
32+
):
33+
"""
34+
Initializes distribution values for gaussian noise
35+
"""
36+
self.sigma = sigma
37+
self.mu = float(mu) # need to add cast to float to avoid tf type-mismatch error in case mu=0.0
38+
39+
super(GaussianNoise, self).__init__(scope=scope, summary_labels=summary_labels)
40+
41+
def tf_explore(self, episode, timestep, action_shape):
42+
return tf.random_normal(shape=action_shape[1:], mean=self.mu, stddev=self.sigma)

0 commit comments

Comments
 (0)