<commit_before>#ifndef GIBBS_SAMPLER_HPP
#define GIBBS_SAMPLER_HPP
//#include "rejection_sampler_1d.hpp"
#include "base_urand.hpp"
//#include "arms.hpp"
#include "discrete_sample.hpp"
#include "continuous_sample.hpp"
#include <vector>
#include <memory>

namespace mcmc_utilities
{
  template <typename T_p,typename T_var>
  void gibbs_sample(const probability_density_md<T_p,T_var>& pd,T_var& init_var,base_urand<T_p>& rnd)
  {
    for(int i=0;i<get_size(init_var);++i)
      {
	auto xrange=pd.var_range(init_var,i);
	if(xrange.first>get_element(init_var,i)||xrange.second<get_element(init_var,i))
	  {
	    var_out_of_range e;
	    e.attach_message("gibbs sampler #1");
	    throw e;
	  }
      }
    
    
    size_t idx=0;
    typedef typename element_type_trait<T_var>::element_type T_var1;
    class conditional_probability_density
      :public probability_density_1d<typename element_type_trait<T_var>::element_type>
    {
    public:
      size_t* p_idx;
      T_var* p_init_var;
      const probability_density_md<T_p,T_var>* ppd;
    private:
      T_p do_eval_log(const T_var1& x1)const
      {
	set_element(*p_init_var,*p_idx,x1);
	T_p result= ppd->eval_log(*p_init_var,*p_idx);
	return result;
      }
      
      std::pair<T_var1,T_var1> do_var_range()const
      {
	//ppd->var_range(xmin,xmax,*p_init_var,(*p_idx));
	return ppd->var_range(*p_init_var,*p_idx);<commit_msg>	修改：     core/gibbs_sampler.hpp<commit_after>#ifndef GIBBS_SAMPLER_HPP
#define GIBBS_SAMPLER_HPP
//#include "rejection_sampler_1d.hpp"
#include "base_urand.hpp"
//#include "arms.hpp"
#include "discrete_sample.hpp"
#include "continuous_sample.hpp"
#include <vector>
#include <memory>

namespace mcmc_utilities
{
  template <typename T_p,typename T_var>
  void gibbs_sample(const probability_density_md<T_p,T_var>& pd,T_var& init_var,base_urand<T_p>& rnd)
  {
    for(int i=0;i<get_size(init_var);++i)
      {
	auto xrange=pd.var_range(init_var,i);
	if(xrange.first>get_element(init_var,i)||xrange.second<get_element(init_var,i))
	  {
	    var_out_of_range e;
	    e.attach_message("gibbs sampler #1");
	    throw e;
	  }
      }
    
    
    size_t idx=0;
    typedef typename element_type_trait<T_var>::element_type T_var1;
    class conditional_probability_density
      :public probability_density_1d<typename element_type_trait<T_var>::element_type>
    {
    public:
      size_t* p_idx;
      T_var* p_init_var;
      const probability_density_md<T_p,T_var>* ppd;
    private:
      T_p do_eval_log(const T_var1& x1)const
      {
	set_element(*p_init_var,*p_idx,x1);
	T_p result= ppd->eval_log(*p_init_var,*p_idx);
	if(!std::isfinite(result))
	  {
	    std::cerr<<"inside gibbs:"<<std::endl;
	    std::cerr<<"x="<<x1<<std::endl;
	  }
	return result;
      }
      
      std::pair<T_var1,T_var1> do_var_range()const
      {
	//ppd->var_range(xmin,xmax,*p_init_var,(*p_idx));
	return ppd->var_range(*p_init_var,*p_idx);
{'fraction_non_alphanumeric': 0.13191343181037443, 'fraction_numerical': 0.00790106492614222, 'mean_word_length': 4.473684210526316, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 31, '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': '2188241', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1203, 'n_words': 159}