コード例 #1
0
ファイル: test_utils.py プロジェクト: disc5/neupy
    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)
コード例 #2
0
ファイル: test_utils.py プロジェクト: itdxer/neupy
    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)
コード例 #3
0
    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)
コード例 #4
0
ファイル: base.py プロジェクト: mayblue9/neupy
    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)
コード例 #5
0
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))
コード例 #6
0
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()
コード例 #7
0
ファイル: properties.py プロジェクト: mayblue9/neupy
 def __str__(self):
     return str(preformat_value(self.default))
コード例 #8
0
ファイル: properties.py プロジェクト: vamsijkrishna/neupy
 def __str__(self):
     return str(preformat_value(self.default))