Created
August 1, 2019 23:07
-
-
Save dioptx/5f50023a069c563718be07e54ea02d6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import warnings | |
# loaded config | |
lstm_conf = { | |
'WINDOW_SIZE' : 15, | |
'NUM_OF_FEATURES': 42, | |
'LABEL_LENGTH': 4, | |
'BATCH_SIZE': 25, | |
'EPOCHS': 100 | |
} | |
class Config(object): | |
def __init__(self, conf): | |
self._config = conf # set it to conf | |
def get_property(self, property_name): | |
if property_name not in self._config.keys(): # we don't want KeyError | |
return ValueError # just return None if not found | |
return self._config[property_name] | |
def set_property(self, property_name, value): | |
if property_name not in self._config.keys(): # we don't want KeyError | |
return ValueError # just return None if not found | |
# Raise a warning in case the user sets a property with a different type | |
if type(property_name) != type(value): | |
warnings.warn('Setting configuration property from {0}, to {1}'.format(type(property_name), type(value)), | |
RuntimeWarning) | |
self._config[property_name] = value | |
class LstmConfig(Config): | |
def __init__(self): | |
super(LstmConfig, self).__init__(conf= lstm_conf) | |
@property | |
def window_size(self): | |
return self.get_property('WINDOW_SIZE') | |
@window_size.setter | |
def window_size(self, value): | |
self.set_property('WINDOW_SIZE', value) | |
@property | |
def num_of_features(self): | |
return self.get_property('NUM_OF_FEATURES') | |
@num_of_features.setter | |
def num_of_features(self, value): | |
self.set_property('NUM_OF_FEATURES', value) | |
@property | |
def label_length(self): | |
return self.get_property('LABEL_LENGTH') | |
@label_length.setter | |
def label_length(self, value): | |
self.set_property('LABEL_LENGTH', value) | |
@property | |
def batch_size(self): | |
return self.get_property('BATCH_SIZE') | |
@batch_size.setter | |
def batch_size(self, value): | |
self.set_property('BATCH_SIZE', value) | |
@property | |
def epochs(self): | |
return self.get_property('EPOCHS') | |
@epochs.setter | |
def epochs(self, value): | |
self.set_property('EPOCHS', value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment