persistent_chain = theano.shared(np.zeros((batch_size, n_hidden), dtype=theano.config.floatX), borrow=True)

    # construct the RBM class
    rbm = RBM(
        input=x,
        validation=test_set,
        n_visible=n_visible,
        n_labels=n_labels,
        n_hidden=n_hidden,
        np_rng=rng,
        theano_rng=theano_rng,
    )

    # get the cost and the gradient corresponding to one step of CD-15
    cost, updates = rbm.get_cost_updates(lr=learning_rate, persistent=persistent_chain, k=k)
    accuracy = rbm.get_cv_error()

    # make a prediction for an unlablled sample.
    t_unlabelled = T.tensor3("unlabelled")
    label, confidence = rbm.predict(t_unlabelled)

    #%%========================================================================
    # Training the RBM
    # ==========================================================================

    # it is ok for a theano function to have no output
    # the purpose of train_rbm is solely to update the RBM parameters
    train_rbm = theano.function(
        [index],
        cost,
        updates=updates,