def __init__(self, consumes=None): """Generic learning constructor """ # initialize evaluation Serializable.__init__(self, "") self.models = [] self.predictions = [] self.prediction_roles = [] self.prediction_model_indexes = []
def __init__(self, config): self.config = config Serializable.__init__(self, "") self.output_folder = join(config.folders.run, "results") self.print_measures = self.config.measures self.print_aggregations = self.config.iter_aggregations if self.print_aggregations is None: self.print_aggregations = ("mean", "std")
def test_save_load_json(self): attrs = {'a': 1, 'b': [2, 3.0, True, None], 'c': [4, 5, 6], 'd': 'x'} Serializable.save_json(attrs, self.fname) loaded = Serializable.load_json(self.fname) # note that str -> unicode, tuple -> list to_str = lambda x: str(x) if isinstance(x, unicode) else x loaded = dict( zip(map(to_str, loaded.keys()), map(to_str, loaded.values()))) assert loaded == attrs
def __init__(self, skip_init=False): """Dataset constructor Arguments: skip_init {bool} -- Wether to initialize the serializable superclass mechanism """ random.seed(self.config.misc.seed) if skip_init or self.config is None: return Serializable.__init__(self, self.dir_name) self.config.full_name = self.name self.filter_stopwords = self.config.filter_stopwords self.remove_digits = self.config.remove_digits
def copy(self): """Create a deep copy the environment. TODO: Investigate if this can be done somehow else, especially for gym envs. """ return Serializable.clone(self)
def test_empty_variable_kwargs_functionality(self): simple_object_1 = SimpleSerializable( 'ARG1', *('ARGS[1]', 'ARGS[2]'), kwarg1='KWARG1') simple_object_2 = Serializable.clone(simple_object_1) assert_objects_match(simple_object_1, simple_object_2)
def test_variable_kwargs_functionality(self): simple_object_1 = SimpleSerializable( 'ARG1', **{'kwargs[1]': 'KWARGS[1]', 'kwargs[2]': 'KWARGS[2]'}) simple_object_2 = Serializable.clone(simple_object_1) assert_objects_match(simple_object_1, simple_object_2)
def test_default_initialization(self): class UninitializedSerializable(Serializable): def __init__(self, arg1, *args, kwarg1=None, **kwargs): self.arg1 = arg1 self.args = args self.kwarg1 = kwarg1 self.kwargs = kwargs simple_object_1 = UninitializedSerializable( 'ARG1', *('ARGS[1]', 'ARGS[2]'), kwarg1='KWARG1', **{'kwargs[1]': 'KWARGS[1]', 'kwargs[2]': 'KWARGS[2]'}) with self.assertRaises(AssertionError): Serializable.clone(simple_object_1)
def test_missing_default_values(self): simple_object_1 = SimpleSerializable( 'ARG1', *('ARGS[1]', 'ARGS[2]'), **{'kwargs[1]': 'KWARGS[1]', 'kwargs[2]': 'KWARGS[2]'}) simple_object_2 = Serializable.clone(simple_object_1) assert_objects_match(simple_object_1, simple_object_2)
def __init__(self, timestep, power_nominal, input_link, file_path=None): # Read component parameters from json file if file_path: self.load(file_path) else: print( 'Attention: No json file for power component efficiency specified' ) self.specification = "MPPT_HQST_40A_12V_34V" # [-] Specification of power component self.efficiency_nominal = 0.951 # [1] Nominal power component efficeincy self.voltage_loss = 0.009737 # [-] Dimensionless parameter for component model self.resistance_loss = 0.031432 # [-] Dimensionless parameter for component model self.power_self_consumption = 0.002671 # [-] Dimensionless parameter for component model self.end_of_life_power_components = 315360000 # [s] End of life time in seconds self.investment_costs_specific = 0.036 # [$/Wp] Specific investment costs # Integrate Serializable for serialization of component parameters Serializable.__init__(self) # not needed !? # Integrate Simulatable class for time indexing Simulatable.__init__(self) # not needed !? # Integrate input power self.input_link = input_link # [s] Timestep self.timestep = timestep #Calculate star parameters of efficeincy curve self.voltage_loss_star = self.voltage_loss self.resistance_loss_star = self.resistance_loss / self.efficiency_nominal self.power_self_consumption_star = self.power_self_consumption * self.efficiency_nominal ## Power model # Initialize power self.power = 0 # set nominal power of power component self.power_nominal = power_nominal ## Economic model # Nominal installed component size for economic calculation self.size_nominal = power_nominal
def test_mixed_argument_types(self): simple_object_1 = SimpleSerializable( 'ARG1', *('ARGS[1]', 'ARGS[2]'), kwarg1='KWARG1', **{'kwargs[1]': 'KWARGS[1]', 'kwargs[2]': 'KWARGS[2]'}) simple_object_2 = Serializable.clone(simple_object_1) assert_objects_match(simple_object_1, simple_object_2)
def __init__(self, timestep, power_nominal, input_link, file_path=None): ''' Parameters ---------- timestep: int. Simulation timestep in seconds power_nominal : int. Nominal power of power component in watt [W] input_link : class. Class of component which supplies input power file_path : json file to load power component parameters ''' # Read component parameters from json file if file_path: self.load(file_path) else: print( 'Attention: No json file for power component efficiency specified' ) self.specification = "Generic system controller" # [-] Specification of power component self.end_of_life_power_components = 315360000 # [s] End of life time in seconds self.investment_costs_specific = 0.036 # [$/Wp] Specific investment costs # Integrate Serializable for serialization of component parameters Serializable.__init__(self) # not needed !? # Integrate Simulatable class for time indexing Simulatable.__init__(self) # not needed !? # Integrate input power self.input_link = input_link # [s] Timestep self.timestep = timestep ## Power model # Initialize power self.power = 0 # set nominal power of power component self.power_nominal = power_nominal ## Economic model # Nominal installed component size for economic calculation self.size_nominal = power_nominal
def __setstate__(self, state): Serializable.__setstate__(self, state) self.set_weights(state['pickled_weights'])
def __getstate__(self): state = Serializable.__getstate__(self) state['pickled_weights'] = self.get_weights() return state
def populate(self): Serializable.__init__(self, self.dir_name) self.set_serialization_params() self.acquire_data()
def test_kwargs_functionality(self): simple_object_1 = SimpleSerializable('ARG1', kwarg1='KWARG1') simple_object_2 = Serializable.clone(simple_object_1) assert_objects_match(simple_object_1, simple_object_2)