def test_bad_hyperparams(self): sealed = dlc.HyperParams( (dlc.ParamDesc('model_name', 'Name of Model', None, 'im2latex'), dlc.ParamDesc('layer_type', 'Type of layers to be created', ['CNN', 'MLP', 'LSTM', 'RNN']), dlc.ParamDesc('num_layers', 'Number of layers to create', list(range(1, 11))), dlc.ParamDesc('unset', 'Unset property', list(range(1, 11))), dlc.ParamDesc('none', 'None property', (None, ), None))).seal() frozen = dlc.HyperParams(sealed, {'num_layers': 10}).freeze() self.assertRaises(KeyError, setattr, sealed, "x", "MyNeuralNetwork") self.assertRaises(KeyError, self.dictSet, sealed, "x", "MyNeuralNetwork") self.assertRaises(KeyError, setattr, frozen, "name", "MyNeuralNetwork") self.assertRaises(KeyError, self.dictSet, frozen, "name", "MyNeuralNetwork") self.assertRaises(ValueError, setattr, sealed, "layer_type", "SVM") self.assertRaises(ValueError, self.dictSet, sealed, "layer_type", "SVM") self.assertRaises(KeyError, getattr, sealed, "x") self.assertRaises(KeyError, self.dictGet, sealed, "x") self.assertRaises(KeyError, getattr, frozen, 'layer_type') self.assertRaises(KeyError, getattr, sealed, 'layer_type')
def test_good_params(self): sealed = dlc.Params( (dlc.ParamDesc('model_name', 'Name of Model', None, 'im2latex'), dlc.ParamDesc('layer_type', 'Type of layers to be created', ['CNN', 'MLP', 'LSTM', 'RNN'], 'LSTM'), dlc.ParamDesc('num_layers', 'Number of layers to create', range(1, 11)), dlc.ParamDesc('unset', 'Unset property', range(1, 11)))).seal() frozen = dlc.Params(sealed, {'num_layers': 10}).freeze() sealed.layer_type = 'MLP' self.assertEqual(sealed.layer_type, 'MLP') self.assertEqual(sealed['layer_type'], 'MLP') sealed['layer_type'] = 'CNN' self.assertEqual(sealed.layer_type, 'CNN') self.assertEqual(sealed['layer_type'], 'CNN') self.assertEqual(frozen.model_name, 'im2latex') self.assertEqual(frozen.layer_type, 'LSTM') self.assertEqual(frozen['num_layers'], 10) self.assertEqual(frozen.num_layers, 10)
def test_good_hyperparams(self): sealed = dlc.HyperParams( (dlc.ParamDesc('model_name', 'Name of Model', None, 'im2latex'), dlc.ParamDesc('layer_type', 'Type of layers to be created', ['CNN', 'MLP', 'LSTM', 'RNN'], 'MLP'), dlc.ParamDesc('num_layers', 'Number of layers to create', list(range(1, 11))), dlc.ParamDesc('unset', 'Unset property', list(range(1, 11))), dlc.ParamDesc('none', 'None property', (None, ), None))).seal() frozen = dlc.HyperParams(sealed, {'num_layers': 10}).freeze() self.assertRaises(dlc.OneValError, setattr, sealed, "model_name", "xyz") self.assertRaises(dlc.OneValError, setattr, sealed, "layer_type", "xyz") self.assertEqual(sealed.layer_type, 'MLP') self.assertEqual(sealed['layer_type'], 'MLP') self.assertEqual(frozen.model_name, 'im2latex') self.assertEqual(frozen['num_layers'], 10) self.assertEqual(frozen.num_layers, 10) self.assertEqual(frozen.none, None) self.assertEqual(frozen['none'], None) self.assertEqual(sealed.none, None) self.assertEqual(sealed['none'], None)