#NEWLINE# def neg_sampling( W_list , b_list , nsamples , beta = 1.0 , pa_bias = None , marginalize_odd = True , theano_rng = None ) : #NEWLINE# #INDENT# "\n    Generate a sample from the intermediate distribution defined at inverse\n    temperature 'beta', starting from state 'nsamples'. See file docstring for\n    equation of p_k(h1).\n\n    Parameters\n    ----------\n    W_list : array-like object of theano shared variables\n        Weight matrices of the DBM. Its first element is ignored, since in the\n        Pylearn2 framework a visible layer does not have a weight matrix.\n    b_list : array-like object of theano shared variables\n        Biases of the DBM\n    nsamples : array-like object of theano shared variables\n        Negative samples corresponding to the previous states\n    beta : theano.tensor.scalar\n        Inverse temperature parameter\n    marginalize_odd : boolean\n        Whether to marginalize odd layers\n    theano_rng : theano RandomStreams\n        Random number generator\n\n    Returns\n    -------\n    new_nsamples : array-like object of symbolic matrices\n        new_nsamples[i] contains new samples for i-th layer.\n    " #NEWLINE# depth = len ( b_list ) #NEWLINE# new_nsamples = [ nsamples [ i ] for i in xrange ( depth ) ] #NEWLINE# _sample_even_odd ( W_list , b_list , new_nsamples , beta , odd = marginalize_odd ) #NEWLINE# _activation_even_odd ( W_list , b_list , new_nsamples , beta , odd = ( not marginalize_odd ) ) #NEWLINE# new_nsamples [ ( not marginalize_odd ) ] += ( pa_bias * ( 1.0 - beta ) ) #NEWLINE# for i in xrange ( ( not marginalize_odd ) , depth , 2 ) : #NEWLINE# #INDENT# new_nsamples [ i ] = T . nnet . sigmoid ( new_nsamples [ i ] ) #NEWLINE# new_nsamples [ i ] = theano_rng . binomial ( size = nsamples [ i ] . get_value ( ) . shape , n = 1 , p = new_nsamples [ i ] , dtype = floatX ) #NEWLINE# #UNINDENT# return new_nsamples