def setUp(self) -> None: super().setUp() self.action_object: SimAction = create_autospec(SimAction) self.action_object.get_space = Mock() self.action_object.get_space.return_value = Space(shape=(7, 13)) self.action_object.get_schedule = Mock() self.action_object.get_schedule.return_value = {"a": 1, "b": 2} self.observation_object1: SimObservation = create_autospec( SimObservation) self.observation_object1.name = "dummy_obs_1" self.observation_object1.get_space = Mock() self.observation_object1.get_space.return_value = Space(shape=(13, 17)) self.observation_object1.get_obs = Mock() self.observation_object1.get_obs.return_value = np.eye(3) self.observation_object2: SimObservation = create_autospec( SimObservation) self.observation_object2.name = "dummy_obs_2" self.observation_object2.get_space = Mock() self.observation_object2.get_space.return_value = Space(shape=(17, 19)) self.observation_object2.get_obs = Mock() self.observation_object2.get_obs.return_value = np.eye(4) self.reward_function1: Callable[[BaseSimEnv], float] = lambda env: 42 self.reward_function2: Callable[[BaseSimEnv], float] = lambda env: 1337 self.env: CustomSimEnv = CustomSimEnv( self.training_interface, [self.observation_object1, self.observation_object2], self.action_object, [self.reward_function1, self.reward_function2], )
def setUpClass(cls) -> None: # The type here is Any as space_function is actually a Mock # object, but there's no Mock type in the typing library. cls.space_function: Any = create_autospec(lambda interface: Space()) cls.to_schedule: Callable[ [GymTrainedInterface, np.ndarray], Dict[str, List[float]] ] = lambda interface, array: {"a": [0]} cls.name: str = "stub_action" cls.sim_action: SimAction = SimAction( cls.space_function, cls.to_schedule, cls.name ) cls.interface: GymTrainedInterface = create_autospec(GymTrainedInterface)
def setUpClass(cls) -> None: # The type here is Any as space_function is actually a Mock # object, but there's no Mock type in the typing library. cls.space_function: Any = create_autospec(lambda interface: Space()) cls.obs_function: Callable[ [GymTrainedInterface], np.ndarray] = lambda interface: np.array([0, 0]) cls.name: str = "stub_observation" cls.sim_observation: obs.SimObservation = obs.SimObservation( cls.space_function, cls.obs_function, cls.name) cls.interface: GymTrainedInterface = create_autospec( GymTrainedInterface)
def __init__(self, market: AbstractMarket, use_deposit=False, use_last_action=False, **kwargs): """MarketEnv constructor. Arguments market (AbstractMarket): Wrapper for access to the market through API, or other solutions. window (int): This is the size of the state of the environment (The number of time intervals). """ self.market = market self.use_deposit = use_deposit self.use_last_action = use_last_action self.last_action = dict() # TODO action space for multy symbols agent self.action_space = Discrete(3 * self.market.symbols_count) self.observation_space = Space(shape=self.market.shape, dtype=np.float)
def __init__(self, dataset: Dataset = MNIST, train: bool = True, time: int = 350, **kwargs): # language=rst """ Initializes the environment wrapper around the dataset. :param dataset: Object from datasets module. :param train: Whether to use train or test dataset. :param time: Length of spike train per example. :param kwargs: Raw data is multiplied by this value. """ self.dataset = dataset self.train = train self.time = time # Keyword arguments. self.intensity = kwargs.get('intensity', 1) self.max_prob = kwargs.get('max_prob', 1) assert 0 < self.max_prob <= 1, 'Maximum spiking probability must be in (0, 1].' self.obs = None if train: self.data, self.labels = self.dataset.get_train() else: self.data, self.labels = self.dataset.get_test() self.data = iter(self.data) self.labels = iter(self.labels) self.datum = next(self.data) self.label = next(self.labels) self.obs = self.datum self.preprocess() self.action_space = Space(shape=(10, ), dtype=int) self.action_space.n = 10