#NEWLINE# def free_energy_at_beta( W_list , b_list , samples , beta , pa_bias = None , marginalize_odd = True ) : #NEWLINE# #INDENT# "\n    Compute the free-energy of the sample 'h1_sample', for model 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    samples : array-like object of theano shared variable\n        Samples from which we extract the samples of layer h1\n    beta : theano.tensor.scalar\n        Inverse temperature beta_k of model p_k(h1) at which to measure the\n        free-energy.\n    pa_bias : array-like object of theano shared variables\n        Biases for the A model\n    marginalize_odd : boolean\n        Whether to marginalize odd layers\n\n    Returns\n    -------\n    fe : symbolic variable\n        Free-energy of sample 'h1_sample', at inverse temperature beta\n    " #NEWLINE# depth = len ( b_list ) #NEWLINE# fe = 0.0 #NEWLINE# keep_idx = numpy . arange ( ( not marginalize_odd ) , depth , 2 ) #NEWLINE# for i in keep_idx : #NEWLINE# #INDENT# fe -= ( T . dot ( samples [ i ] , b_list [ i ] ) * beta ) #NEWLINE# #UNINDENT# marg_idx = numpy . arange ( marginalize_odd , depth , 2 ) #NEWLINE# for i in marg_idx : #NEWLINE# #INDENT# from_im1 = ( T . dot ( samples [ ( i - 1 ) ] , W_list [ i ] ) if ( i >= 1 ) else 0.0 ) #NEWLINE# from_ip1 = ( T . dot ( samples [ ( i + 1 ) ] , W_list [ ( i + 1 ) ] . T ) if ( i < ( depth - 1 ) ) else 0 ) #NEWLINE# net_input = ( ( ( from_im1 + from_ip1 ) + pa_bias [ i ] ) * beta ) #NEWLINE# fe -= T . sum ( T . nnet . softplus ( net_input ) , axis = 1 ) #NEWLINE# #UNINDENT# fe -= ( T . dot ( samples [ ( not marginalize_odd ) ] , pa_bias ) * ( 1.0 - beta ) ) #NEWLINE# return fe