<commit_before>#ifndef MLEARN_RBM_COST_INCLUDE
#define MLEARN_RBM_COST_INCLUDE

// MLearn includes
#include <MLearn/Core>
#include <MLearn/NeuralNets/Regularizer.h>
#include <MLearn/Optimization/CostFunction.h>
#include <MLearn/NeuralNets/ActivationFunction.h>
#include <MLearn/Utility/LookUp/BinomialCoefficientLU.h>
#include <MLearn/Utility/MemoryPool/MLVectorPool.h>
#include "RBMUtils.h"
#include "RBMProcessing.h"

// STL includes
#include <cmath>

namespace MLearn{

	namespace NeuralNets{

		namespace RBMSupport{

			/*
			*	\brief Hidden distribution integral computer
			*/
			template < RBMUnitType HID_TYPE >
			class HiddenIntegral{
			public:
				template < typename RBM, typename DERIVED >
				static inline typename RBM::SCALAR compute_integral( const Eigen::MatrixBase<DERIVED>& interaction_terms, RBM& rbm ){
					static_assert( std::is_same<typename DERIVED::Scalar,typename RBM::SCALAR>::value, "Scalar types must be the same" );
					static_assert( DERIVED::ColsAtCompileTime == 1, "Expected column vector!" );
					typename RBM::SCALAR integral = 0;
					auto& bias_hidden = rbm.bias_hidden;
					auto binary_op = [](const typename RBM::SCALAR& s1, const typename RBM::SCALAR& s2){
						typename RBM::SCALAR sum = s1 + s2; 
						if (sum > 0)
							return static_cast<typename RBM::SCALAR>( std::log(1+std::exp(sum)) );
						else 
							return static_cast<typename RBM::SCALAR>( std::log(1+std::exp(-sum)) + sum );
					};

					integral = -(interaction_terms.binaryExpr(bias_hidden,binary_op).sum());<commit_msg>Bug fixed: bernoulli hidden layer<commit_after>#ifndef MLEARN_RBM_COST_INCLUDE
#define MLEARN_RBM_COST_INCLUDE

// MLearn includes
#include <MLearn/Core>
#include <MLearn/NeuralNets/Regularizer.h>
#include <MLearn/Optimization/CostFunction.h>
#include <MLearn/NeuralNets/ActivationFunction.h>
#include <MLearn/Utility/LookUp/BinomialCoefficientLU.h>
#include <MLearn/Utility/MemoryPool/MLVectorPool.h>
#include "RBMUtils.h"
#include "RBMProcessing.h"

// STL includes
#include <cmath>

namespace MLearn{

	namespace NeuralNets{

		namespace RBMSupport{

			/*
			*	\brief Hidden distribution integral computer
			*/
			template < RBMUnitType HID_TYPE >
			class HiddenIntegral{
			public:
				template < typename RBM, typename DERIVED >
				static inline typename RBM::SCALAR compute_integral( const Eigen::MatrixBase<DERIVED>& interaction_terms, RBM& rbm ){
					static_assert( std::is_same<typename DERIVED::Scalar,typename RBM::SCALAR>::value, "Scalar types must be the same" );
					static_assert( DERIVED::ColsAtCompileTime == 1, "Expected column vector!" );
					typename RBM::SCALAR integral = 0;
					auto& bias_hidden = rbm.bias_hidden;
					auto binary_op = [](const typename RBM::SCALAR& s1, const typename RBM::SCALAR& s2){
						typename RBM::SCALAR sum = s1 + s2; 
						if (sum < 0)
							return static_cast<typename RBM::SCALAR>( std::log(1+std::exp(sum)) );
						else 
							return static_cast<typename RBM::SCALAR>( std::log(1+std::exp(-sum)) + sum );
					};

					integral = -(interaction_terms.binaryExpr(bias_hidden,binary_op).sum());
{'fraction_non_alphanumeric': 0.1223369916074887, 'fraction_numerical': 0.005810200129115558, 'mean_word_length': 4.6654478976234, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1048561', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1070, 'n_words': 225}