def test_preformat_value(self): def my_func(): pass class MyClass(object): pass self.assertEqual('my_func', preformat_value(my_func)) self.assertEqual('MyClass', preformat_value(MyClass)) expected = ['my_func', 'MyClass', 1] actual = preformat_value((my_func, MyClass, 1)) np.testing.assert_array_equal(expected, actual) expected = ['my_func', 'MyClass', 1] actual = preformat_value([my_func, MyClass, 1]) np.testing.assert_array_equal(expected, actual) expected = sorted(['my_func', 'MyClass', 'x']) actual = sorted(preformat_value({my_func, MyClass, 'x'})) np.testing.assert_array_equal(expected, actual) self.assertEqual(1, preformat_value(1)) expected = (3, 2) actual = preformat_value(np.ones((3, 2))) np.testing.assert_array_equal(expected, actual) expected = (1, 2) actual = preformat_value(np.matrix([[1, 1]])) np.testing.assert_array_equal(expected, actual)
def repr_options(self): options = [] for option_name in self.options: option_value = getattr(self, option_name) option_value = preformat_value(option_value) option_repr = "{}={}".format(option_name, option_value) options.append(option_repr) return ', '.join(options)
def _repr_options(self): options = [] for option_name in self.options: option_value = getattr(self, option_name) option_value = preformat_value(option_value) option_repr = "{}={}".format(option_name, option_value) options.append(option_repr) return ', '.join(options)
def logging_info_about_the_data(network, input_train, input_test): logs = network.logs training_shapes = preformat_value(input_train) logs.title("Start training") logs.message("TRAINING DATA", "shapes: {}".format(training_shapes)) if isinstance(training_shapes[0], int): training_shapes = [training_shapes] if input_test is not None: test_shapes = preformat_value(input_test) logs.message("TEST DATA", "shapes: {}".format(test_shapes)) if isinstance(test_shapes[0], int): test_shapes = [test_shapes] for training_shape, test_shape in zip(training_shapes, test_shapes): if training_shape[1:] != test_shape[1:]: raise ValueError( "Train and test samples should have the same feature " "shapes. Got training input with shape {} and test " "input with shape {}".format(training_shape, test_shape))
def show_network_options(network, highlight_options=None): """ Display all available parameters options for Neural Network. Parameters ---------- network : object Neural network instance. highlight_options : list List of enabled options. In that case all options from that list would be marked with a green color. """ available_classes = [cls.__name__ for cls in network.__class__.__mro__] logs = network.logs if highlight_options is None: highlight_options = {} def group_by_class_name(value): _, option = value option_priority = -available_classes.index(option.class_name) return option_priority, option.class_name grouped_options = groupby( sorted(network.options.items(), key=group_by_class_name), group_by_class_name, ) logs.title("Main information") logs.message("ALGORITHM", network.class_name()) logs.newline() for (_, class_name), options in grouped_options: if not options: continue logs.write("{}:".format(class_name)) for key, data in sorted(options): if key in highlight_options: msg_color = 'green' value = highlight_options[key] else: msg_color = 'gray' value = data.value formated_value = preformat_value(value) msg_text = "{} = {}".format(key, formated_value) logs.message("OPTION", msg_text, color=msg_color) logs.newline()
def __str__(self): return str(preformat_value(self.default))