<commit_before>#include <core/distribution.hpp>
#include <core/gibbs_sampler.hpp>
#include <math/distributions.hpp>
#include <core/urand.hpp>
#include <vector>
#include <fstream>
#include <cassert>
using namespace std;
using namespace mcmc_utilities;

class coal_distribution
  :public probability_density_md<double,std::vector<double> >
{
private:
  std::vector<double> year;
  std::vector<double> n_accident;
public:
  coal_distribution()
  {
    ifstream ifs("coal.dat");
    for(;;)
      {
	double y,n;
	ifs>>y>>n;
	if(!ifs.good())
	  {
	    break;
	  }
	year.push_back(y);
	n_accident.push_back(n);
      }
  }

  double do_eval_log(const std::vector<double>& x)const
  {
    
    
    double lambda1=x[0];
    double lambda2=x[1];
    double k=x[2];
    double logp=0;
    double lambda=0;
    for(int i=0;i<year.size();++i)
      {
	if(year[i]<k)
	  {
	    lambda=lambda1;
	  }
	else
	  {
	    lambda=lambda2;
	  }
	int n=n_accident[i];
	double logp1=logdpoisson(n,lambda);
	logp+=logp1;
      }

    return logp;
  }

  std::pair<double,double> do_var_range(const std::vector<double>& x,size_t ndim)const
  {
    if(ndim==0||ndim==1)
      {
	return make_pair(0.0001,100.);
      }
    else
      {
	return make_pair(0,year.back()+1);
      }
  }
};

int main()
{
  coal_distribution cd;
  std::vector<double> x;
  x.push_back(3);
  x.push_back(4);
  x.push_back(50);
  urand<double> rng;
  
  //cout<<cd.eval_log(x)<<endl;
  for(int n=0;n<10000;++n)
    {
      //gibbs_sample<double,std::vector<double> >(cd,x,1,as,10);
      gibbs_sample(cd,x,rng);
      for(int i=0;i<x.size();++i)
	{
	  cout<<x[i]<<" ";
	}
      cout<<endl;
    }
}<commit_msg>	修改：     test_coal.cpp<commit_after>#include <core/distribution.hpp>
#include <core/gibbs_sampler.hpp>
#include <math/distributions.hpp>
#include <core/urand.hpp>
#include <vector>
#include <fstream>
#include <cassert>
using namespace std;
using namespace mcmc_utilities;

class coal_distribution
  :public probability_density_md<double,std::vector<double> >
{
private:
  std::vector<double> year;
  std::vector<double> n_accident;
public:
  coal_distribution()
  {
    ifstream ifs("coal.dat");
    for(;;)
      {
	double y,n;
	ifs>>y>>n;
	if(!ifs.good())
	  {
	    break;
	  }
	year.push_back(y);
	n_accident.push_back(n);
      }
  }

  double do_eval_log(const std::vector<double>& x)const
  {
    
    
    double lambda1=x[0];
    double lambda2=x[1];
    double k=x[2];
    double logp=0;
    double lambda=0;
    for(int i=0;i<year.size();++i)
      {
	if(year[i]<k)
	  {
	    lambda=lambda1;
	  }
	else
	  {
	    lambda=lambda2;
	  }
	int n=n_accident[i];
	double logp1=logdpoisson(n,lambda);
	logp+=logp1;
      }

    return logp;
  }

  std::pair<double,double> do_var_range(const std::vector<double>& x,size_t ndim)const
  {
    if(ndim==0||ndim==1)
      {
	return make_pair(1e-6,100.);
      }
    else
      {
	return make_pair(0,year.back()+1);
      }
  }
};

int main()
{
  coal_distribution cd;
  std::vector<double> x;
  x.push_back(3);
  x.push_back(4);
  x.push_back(50);
  urand<double> rng;
  
  //cout<<cd.eval_log(x)<<endl;
  for(int n=0;n<10000;++n)
    {
      //gibbs_sample<double,std::vector<double> >(cd,x,1,as,10);
      gibbs_sample(cd,x,rng);
      for(int i=0;i<x.size();++i)
	{
	  cout<<x[i]<<" ";
	}
      cout<<endl;
    }
}
{'fraction_non_alphanumeric': 0.17694854047547398, 'fraction_numerical': 0.0219681011134517, 'mean_word_length': 3.2615384615384615, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 47, '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': '3708277', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1418, 'n_words': 202}