Esempio n. 1
0
    def test_simple_zca(self):
        plt.style.use('ggplot')

        original_image_name = format_image_name("simple_zca.png")
        original_image = os.path.join(PLOTS_DIR, original_image_name)
        image = os.path.join(IMGDIR, "cifar10.png")

        data = imread(image)
        data = data[:, :, 0]

        comparison_kwargs = dict(figsize=(10, 6), tol=0.05)

        with image_comparison(original_image, **comparison_kwargs) as fig:
            ax = fig.add_subplot(1, 1, 1)

            zca = preprocessing.ZCA(0.001)
            zca.train(data)
            data_transformed = zca.transform(data)

            ax.imshow(data_transformed, cmap=plt.cm.binary)

        with image_comparison(original_image, **comparison_kwargs) as fig:
            ax = fig.add_subplot(1, 1, 1)

            zca = preprocessing.ZCA(0.001)
            data_transformed = zca.fit(data).transform(data)

            ax.imshow(data_transformed, cmap=plt.cm.binary)
Esempio n. 2
0
    def test_max_weight(self):
        original_image_name = format_image_name("max_weight_hinton.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = 100 * np.random.randn(20, 20)
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax, max_weight=10, add_legend=True)
Esempio n. 3
0
    def test_log_scale(self):
        original_image_name = format_image_name("log_scale.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image) as fig:
            ax = fig.add_subplot(1, 1, 1)
            network = reproducible_network_train(step=0.3)
            network.plot_errors(logx=True, ax=ax, show=False)
Esempio n. 4
0
    def test_hinton_only_negative(self):
        original_image_name = format_image_name("hinton_only_negative.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = -np.random.random((20, 20))
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax)
Esempio n. 5
0
    def test_log_scale(self):
        original_image_name = format_image_name("log_scale.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image) as fig:
            ax = fig.add_subplot(1, 1, 1)
            network = reproducible_network_train(step=0.3)
            plots.error_plot(network, logx=True, ax=ax, show=False)
Esempio n. 6
0
    def test_max_weight(self):
        original_image_name = format_image_name("max_weight_hinton.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = 100 * np.random.randn(20, 20)
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax, max_weight=10, add_legend=True)
Esempio n. 7
0
    def test_simple_plot(self):
        original_image_name = format_image_name("simple_plot.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image) as fig:
            ax = fig.add_subplot(1, 1, 1)
            network = reproducible_network_train(step=0.3)
            network.plot_errors(ax=ax, show=False)
Esempio n. 8
0
    def test_simple_plot(self):
        original_image_name = format_image_name("simple_plot.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image) as fig:
            ax = fig.add_subplot(1, 1, 1)
            network = reproducible_network_train(step=0.3)
            plots.error_plot(network, ax=ax, show=False)
Esempio n. 9
0
    def test_hinton_1darray(self):
        original_image_name = format_image_name("hinton_1darray.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 4)) as fig:
            weight = -np.random.randn(20)
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax)
Esempio n. 10
0
    def test_hinton_only_negative(self):
        original_image_name = format_image_name("hinton_only_negative.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = -np.random.random((20, 20))
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax)
Esempio n. 11
0
    def test_hinton_without_legend(self):
        original_image_name = format_image_name("hinton_without_legend.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = np.random.randn(20, 20)
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax, add_legend=False)
Esempio n. 12
0
    def test_hinton_without_legend(self):
        original_image_name = format_image_name("hinton_without_legend.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = np.random.randn(20, 20)
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax, add_legend=False)
Esempio n. 13
0
    def test_hinton_1darray(self):
        original_image_name = format_image_name("hinton_1darray.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 4)) as fig:
            weight = -np.random.randn(20)
            ax = fig.add_subplot(1, 1, 1)
            plots.hinton(weight, ax=ax)
Esempio n. 14
0
    def test_simple_hinton(self):
        original_image_name = format_image_name("simple_hinton.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = np.random.randn(20, 20)
            ax = fig.add_subplot(1, 1, 1)
            plt.sca(ax)  # To test the case when ax=None
            plots.hinton(weight, add_legend=True)
Esempio n. 15
0
    def test_simple_hinton(self):
        original_image_name = format_image_name("simple_hinton.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image, figsize=(10, 6)) as fig:
            weight = np.random.randn(20, 20)
            ax = fig.add_subplot(1, 1, 1)
            plt.sca(ax)  # To test the case when ax=None
            plots.hinton(weight, add_legend=True)
Esempio n. 16
0
    def test_plot_with_validation_dataset(self):
        original_image_name = format_image_name("with_validation.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image) as fig:
            ax = fig.add_subplot(1, 1, 1)

            x_train, x_test, y_train, y_test = simple_classification()
            gdnet = algorithms.GradientDescent((10, 12, 1), step=0.25)
            gdnet.train(x_train, y_train, x_test, y_test, epochs=100)
            plots.error_plot(gdnet, ax=ax, show=False)
Esempio n. 17
0
    def test_plot_with_validation_dataset(self):
        original_image_name = format_image_name("with_validation.png")
        original_image = os.path.join(IMGDIR, original_image_name)

        with image_comparison(original_image) as fig:
            ax = fig.add_subplot(1, 1, 1)

            x_train, x_test, y_train, y_test = simple_classification()
            gdnet = algorithms.GradientDescent((10, 12, 1), step=0.25)
            gdnet.train(x_train, y_train, x_test, y_test, epochs=100)
            gdnet.plot_errors(ax=ax, show=False)