-
Notifications
You must be signed in to change notification settings - Fork 5
/
environment.py
38 lines (31 loc) · 1.09 KB
/
environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gym
import numpy as np
import random
import fetch_slide_2
# hardcoded for fetch_slide_2, with only friction
class RandomizedEnvironment:
""" Randomized environment class """
def __init__(self, experiment, parameter_ranges, goal_range):
self._experiment = experiment
self._parameter_ranges = parameter_ranges
self._goal_range = goal_range
self._params = [0]
random.seed(123)
def sample_env(self):
mini = self._parameter_ranges[0]
maxi = self._parameter_ranges[1]
pick = mini + (maxi - mini)*random.random()
self._params = np.array([pick])
self._env = gym.make(self._experiment)
self._env.env.reward_type="dense"
self._env.set_property('object0', 'geom_friction', [pick, 0.005, .0001])
def get_env(self):
"""
Returns a randomized environment and the vector of the parameter
space that corresponds to this very instance
"""
return self._env, self._params
def close_env(self):
self._env.close()
def get_goal(self):
return