Ejemplo n.º 1
0
    print("\nStarting a Restricted Boltzmann Machine..")

    batch_size = 10
    ndim_hidden = 500
    n_train = 60000
    n_iterations = 60000 / batch_size  #math.floor(60000/batch_size)
    epochs = 10

    rbm = RestrictedBoltzmannMachine(ndim_visible=image_size[0] *
                                     image_size[1],
                                     ndim_hidden=ndim_hidden,
                                     is_bottom=True,
                                     image_size=image_size,
                                     is_top=False,
                                     n_labels=10,
                                     batch_size=batch_size)

    recon_err = []
    for i in range(epochs):
        rbm.cd1(visible_trainset=train_imgs, n_iterations=n_iterations)
        recon_err += rbm.get_err_rec()

    x_axis = np.arange(0, epochs, 1.0 / n_iterations)
    plt.title("Reconstruction Error along Epochs")
    plt.xlabel("Epoch")
    plt.ylabel("Reconstruction Error")
    plt.plot(x_axis, recon_err)
    plt.savefig('4_1.png')
    plt.show()
Ejemplo n.º 2
0
    n_iterations = 60000 / batch_size  #math.floor(60000/batch_size)
    epochs = 1

    rbm = RestrictedBoltzmannMachine(ndim_visible=image_size[0] *
                                     image_size[1],
                                     ndim_hidden=ndim_hidden,
                                     is_bottom=True,
                                     image_size=image_size,
                                     is_top=False,
                                     n_labels=10,
                                     batch_size=batch_size)

    recon_err_500 = []
    for i in range(epochs):
        rbm.cd1(visible_trainset=train_imgs, n_iterations=n_iterations)
        recon_err_500 += rbm.get_err_rec()

    # reset rbm
    ndim_hidden = 200
    rbm = RestrictedBoltzmannMachine(ndim_visible=image_size[0] *
                                     image_size[1],
                                     ndim_hidden=ndim_hidden,
                                     is_bottom=True,
                                     image_size=image_size,
                                     is_top=False,
                                     n_labels=10,
                                     batch_size=batch_size)
    recon_err_200 = []
    for i in range(epochs):
        rbm.cd1(visible_trainset=train_imgs, n_iterations=n_iterations)
        recon_err_200 += rbm.get_err_rec()
Ejemplo n.º 3
0
    batch_size = 20
    ndim_hidden = 500

    # set number of epochs
    epochs = 10

    # number of iterations to pass through the whole dataset
    n_iterations = math.floor(60000 / batch_size)

    rbm = RestrictedBoltzmannMachine(ndim_visible=image_size[0] *
                                     image_size[1],
                                     ndim_hidden=ndim_hidden,
                                     is_bottom=True,
                                     image_size=image_size,
                                     is_top=False,
                                     n_labels=10,
                                     batch_size=batch_size)

    reconstr_err = []

    for i in range(0, epochs):
        rbm.cd1(visible_trainset=train_imgs, n_iterations=n_iterations)
        reconstr_err += rbm.get_err_rec()

    x_axis = np.arange(len(reconstr_err)) / n_iterations
    plt.title("Reconstruction error along epochs")
    plt.xlabel("Epoch")
    plt.ylabel("Reconstruction error")
    plt.plot(x_axis, reconstr_err)
    plt.show()