def get_environment(self): """ Return Sigmoid env with current configuration Returns ------- SigmoidEnv Sigmoid environment """ if "instance_set" not in self.config.keys(): self.read_instance_set() # Read test set if path is specified if "test_set" not in self.config.keys() and "test_set_path" in self.config.keys(): self.read_instance_set(test=True) if ( "env_type" in self.config ): # The env_type determines which Sigmoid environment to use. if self.config["env_type"].lower() in [ "continuous", "cont", ]: # Either continuous ... if ( self.config["action_space"] == "Box" ): # ... in both actions and x-axis state, only ... env = ContinuousSigmoidEnv(self.config) elif ( self.config["action_space"] == "Discrete" ): # ... continuous in the x-axis state or ... env = ContinuousStateSigmoidEnv(self.config) else: raise Exception( f'The given environment type "{self.config["env_type"]}" does not support the' f' chosen action_space "{self.config["action_space"]}". The action space has to' f' be either of type "Box" for continuous actions or "Discrete".' ) else: # ... discrete. env = SigmoidEnv(self.config) else: # If the type is not specified we the simplest, fully discrete version. env = SigmoidEnv(self.config) for func in self.wrap_funcs: env = func(env) return env
def get_environment(self): """ Return Sigmoid env with current configuration Returns ------- SigmoidEnv Sigmoid environment """ if "instance_set" not in self.config.keys(): self.read_instance_set() return SigmoidEnv(self.config)
def get_benchmark(self, dimension=None, seed=0): """ Get Benchmark from DAC paper Parameters ------- dimension : int Sigmoid dimension, was 1, 2, 3 or 5 in the paper seed : int Environment seed Returns ------- env : SigmoidEnv Sigmoid environment """ self.config = objdict(SIGMOID_DEFAULTS.copy()) if dimension == 1: self.set_action_values([3]) if dimension == 2: self.set_action_values([3, 3]) if dimension == 3: self.set_action_values((3, 3, 3)) if dimension == 5: self.set_action_values((3, 3, 3, 3, 3)) self.config.seed = seed self.config.instance_set = [0] env = SigmoidEnv(self.config) def sample_sigmoid(): rng = np.random.default_rng() shifts = rng.normal( self.config.cutoff / 2, self.config.cutoff / 4, self.config.action_space_args[0], ) slopes = ( rng.choice([-1, 1], self.config.action_space_args[0]) * rng.uniform(size=self.config.action_space_args[0]) * self.config.slope_multiplier ) return np.concatenate((shifts, slopes)) sampling_env = InstanceSamplingWrapper(env, sampling_function=sample_sigmoid) return sampling_env
def get_environment(self): """ Return Sigmoid env with current configuration Returns ------- SigmoidEnv Sigmoid environment """ if "instance_set" not in self.config.keys(): self.read_instance_set() env = SigmoidEnv(self.config) for func in self.wrap_funcs: env = func(env) return env
def get_benchmark(self, dimension=None, seed=0): """ Get Benchmark from DAC paper Parameters ------- dimension : int Sigmoid dimension, was 1, 2, 3 or 5 in the paper seed : int Environment seed Returns ------- env : SigmoidEnv Sigmoid environment """ self.config = objdict(SIGMOID_DEFAULTS.copy()) if dimension == 1: self.set_action_values([3]) self.config.instance_set_path = ( "../instance_sets/sigmoid/sigmoid_1D3M_train.csv") self.config.benchmark_info["state_description"] = [ "Remaining Budget", "Shift (dimension 1)", "Slope (dimension 1)", "Action", ] if dimension == 2: self.set_action_values([3, 3]) if dimension == 3: self.set_action_values((3, 3, 3)) self.config.instance_set_path = ( "../instance_sets/sigmoid/sigmoid_3D3M_train.csv") self.config.benchmark_info["state_description"] = [ "Remaining Budget", "Shift (dimension 1)", "Slope (dimension 1)", "Shift (dimension 2)", "Slope (dimension 2)", "Shift (dimension 3)", "Slope (dimension 3)", "Action 1", "Action 2", "Action 3", ] if dimension == 5: self.set_action_values((3, 3, 3, 3, 3)) self.config.instance_set_path = ( "../instance_sets/sigmoid/sigmoid_5D3M_train.csv") self.config.benchmark_info["state_description"] = [ "Remaining Budget", "Shift (dimension 1)", "Slope (dimension 1)", "Shift (dimension 2)", "Slope (dimension 2)", "Shift (dimension 3)", "Slope (dimension 3)", "Shift (dimension 4)", "Slope (dimension 4)", "Shift (dimension 5)", "Slope (dimension 5)", "Action 1", "Action 2", "Action 3", "Action 4", "Action 5", ] self.config.seed = seed self.read_instance_set() env = SigmoidEnv(self.config) return env
def make_env(self): config = SIGMOID_DEFAULTS config["instance_set"] = {20: [0, 1, 2, 3]} env = SigmoidEnv(config) return env