'Computes the free energy F(v) = - log sum_h exp(-E(v,h)).
Parameters
v : array-like, shape (n_samples, n_features)
Values of the visible layer.
Returns
free_energy : array-like, shape (n_samples,)
The value of the free energy.'

def _free_energy(self, v):

    return ((- safe_sparse_dot(v, self.intercept_visible_)) - np.logaddexp(0, (safe_sparse_dot(v, self.components_.T) + self.intercept_hidden_)).sum(axis=1))
