Esempio n. 1
0
void AlexSim::writeHist(const QString filename) const
{
    long ii;
    long nbins=(long)((t-tStart)/burstDuration*10);
    if(nbins==0||photons.size()==0) qWarning()<<"writeHist: no photon records ";
    gsl_histogram * histDonor = gsl_histogram_alloc (nbins);
    gsl_histogram_set_ranges_uniform (histDonor, tStart, t); // change t to tEnd if the latter is implemented
    gsl_histogram * histAcceptor = gsl_histogram_alloc (nbins);
    gsl_histogram_set_ranges_uniform (histAcceptor, tStart, t); // change t to tEnd if the latter is implemented
    for (ii=0;ii<photons.size();ii++) {
#ifdef PHOTONMACRO
        if(isChannel(photons.at(ii),DonorEm)) gsl_histogram_increment (histDonor, photons.at(ii).time);
#else
        if(photons.at(ii).isChannel(DonorEm)) gsl_histogram_increment (histDonor, photons.at(ii).time);
#endif
        else gsl_histogram_increment (histAcceptor, photons.at(ii).time);
    }

    QFile file(filename);
    if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) QMessageBox::warning(0, "error", file.errorString());
    QTextStream out(&file);
    out <<"# Simulation data. photon count over time. parameters are:\n";
    out <<"# rateDonor="<<rateDemDex<<"\trateAcceptor="<<rateAemAex<<"\trateBackground="<<rateBackground<<"\tburstDuration="<<burstDuration<<"\tsigma="<<sigma<<"\ttStart="<<tStart<<"\ttEnd="<<tEnd()<<"\n";
    out.setRealNumberPrecision(11);
    out <<"#  time in ms \tdonor channel \tacceptor channel\n";

    for(ii=0;ii<histDonor->n;ii++) {
        out << histDonor->range[ii]*1e3 << "\t" << gsl_histogram_get(histDonor,ii) << "\t" << gsl_histogram_get(histAcceptor,ii) << "\n";
    }
    file.close();
    gsl_histogram_free (histDonor);
    gsl_histogram_free (histAcceptor);

    qDebug()<<nbins<<"histogram entries written to file "<<filename;
}
Esempio n. 2
0
void average_bin(double* array_x, double* array_y, double* bins, 
	double* binned_array, double *error_array, int bin_size, int array_size)
{
#ifdef PRINT_INFO
	fprintf(stdout, "\nBinning and averaging into %d bins an array of size:%d...", bin_size, array_size);
#endif
	int i=0, j=0; 

	gsl_histogram *h = gsl_histogram_alloc (bin_size-1);
	gsl_histogram *g = gsl_histogram_alloc (bin_size-1);
	gsl_histogram_set_ranges (h, bins, bin_size);
	gsl_histogram_set_ranges (g, bins, bin_size);
		
		for(i=0; i<array_size; i++)
		{
			gsl_histogram_increment  (h, array_x[i]);
			gsl_histogram_accumulate (g, array_x[i], array_y[i]);
		}

			for(j=0; j<bin_size-1; j++)
			{
				binned_array[j] = g->bin[j]/h->bin[j];
					if(h->bin[j]>0)	// Assuming poissonian error
						error_array[j] = g->bin[j] / sqrt(h->bin[j]);
			}

	gsl_histogram_free(h);
	gsl_histogram_free(g);
}
Esempio n. 3
0
void QwtHistogram::loadDataFromMatrix() {
  if (!d_matrix)
    return;

  int size = d_matrix->numRows() * d_matrix->numCols();
  const double *data = d_matrix->matrixModel()->dataVector();

  int n;
  gsl_histogram *h;
  if (d_autoBin) {
    double min, max;
    d_matrix->range(&min, &max);
    d_begin = floor(min);
    d_end = ceil(max);
    d_bin_size = 1.0;

    n = static_cast<int>(floor((d_end - d_begin) / d_bin_size));
    if (!n)
      return;

    h = gsl_histogram_alloc(n);
    if (!h)
      return;
    gsl_histogram_set_ranges_uniform(h, floor(min), ceil(max));
  } else {
    n = static_cast<int>((d_end - d_begin) / d_bin_size + 1);
    if (!n)
      return;

    h = gsl_histogram_alloc(n);
    if (!h)
      return;

    double *range = new double[n + 2];
    for (int i = 0; i <= n + 1; i++)
      range[i] = d_begin + i * d_bin_size;

    gsl_histogram_set_ranges(h, range, n + 1);
    delete[] range;
  }

  for (int i = 0; i < size; i++)
    gsl_histogram_increment(h, data[i]);

  QVarLengthArray<double> X(n), Y(n); // stores ranges (x) and bins (y)
  for (int i = 0; i < n; i++) {
    Y[i] = gsl_histogram_get(h, i);
    double lower, upper;
    gsl_histogram_get_range(h, i, &lower, &upper);
    X[i] = lower;
  }
  setData(X.data(), Y.data(), n);

  d_mean = gsl_histogram_mean(h);
  d_standard_deviation = gsl_histogram_sigma(h);
  d_min = gsl_histogram_min_val(h);
  d_max = gsl_histogram_max_val(h);

  gsl_histogram_free(h);
}
Esempio n. 4
0
bool myHistogram::Convert(vector<double> &x)
{
	gsl_histogram *r;
	size_t n=x.size();
	if(n<=2) return false;
	double *res;
	res=new double[n];
	size_t i;
	for(i=0;i<n;i++) res[i]=x[i];
	double std=gsl_stats_sd(res,1,n);
	double bin=3.49*std/pow(n*1.0,1.0/3);//Scott's ruler
	if(bin<=0) 
	{
		delete []res;
		return false;
	}
	double a=gsl_stats_min(res,1,n);
	double b=gsl_stats_max(res,1,n);
	int num=(int)((b-a)/bin);
	r=gsl_histogram_alloc(num);
	gsl_histogram_set_ranges_uniform(r,a,b);
	for(i=0;i<n;i++)
	{
		gsl_histogram_increment(r,res[i]);
	}	
	Convert(r,n);	
	gsl_histogram_free(r);
	delete []res;	
	return true;
}
Esempio n. 5
0
gsl_histogram * calc_hist(const gsl_vector * v, int nbins) {
	double max;
	double min;
	unsigned int i;
	double binwidth;
	double sum = 0;
	double val;
	gsl_histogram * h;

	gsl_vector_minmax(v, &min, &max);
	binwidth = (max - min) / nbins;
	dump_d("min", min);
	dump_d("max", max);

	debug("allocating the histogram");
	h = gsl_histogram_alloc(v->size);
	debug("setting range");
	require(gsl_histogram_set_ranges_uniform (h, min, max));

	/* with out the following, the max element doesn't fall in the last bin */
	h->range[h->n] += 1;

	debug("summing up");
	for (i = 0; i < v->size; i++) {
		val = gsl_vector_get(v, i);
		sum += val;
		require(gsl_histogram_increment (h, val));
	}
	debug("scaling");
	/* double gsl_histogram_sum (const gsl_histogram * h) */
	require(gsl_histogram_scale (h, 1/sum));
	debug("done");
	return h;
}
Esempio n. 6
0
// receive vector<vector<unsigned int>> representing a list of tuples
// these tuples have pairs of particleTypeIds which should be considered
// in rdf calculation.
RadialDistribution::RadialDistribution(
	std::vector<double>& range,
	bool isPeriodic,
	double boxsize,
	std::vector< std::vector<unsigned int> > considered,
	std::string inFilename)
{
	this->recPeriod    = 1;
	this->clearPeriod  = 0;
	this->filename     = inFilename;
	this->isPeriodic   = isPeriodic;
	this->boxsize      = boxsize;
	this->numberOfBins = range.size() - 1;
	this->radialDistribution = gsl_histogram_alloc(this->numberOfBins);
	this->rangeOfBins  = range;
	const double * cRange = &range[0];
	gsl_histogram_set_ranges(this->radialDistribution, cRange, range.size());
	// calculate centers of bins
	double center;
	for (int i=0; i < (rangeOfBins.size() - 1) ; i++) {
		center = 0.5 * ( rangeOfBins[i] + rangeOfBins[i+1] );
		this->binCenters.push_back(center);
		this->bins.push_back(0.);
	}
	this->consideredPairs = considered;
}
Esempio n. 7
0
int main(void) {
	struct data ntuple_row;

	gsl_ntuple *ntuple
	= gsl_ntuple_open ("test.dat", &ntuple_row,
	sizeof (ntuple_row));
	double lower = 1.5;

	gsl_ntuple_select_fn S;
	gsl_ntuple_value_fn V;

	gsl_histogram *h = gsl_histogram_alloc (100);
	gsl_histogram_set_ranges_uniform(h, 0.0, 10.0);

	S.function = &sel_func;
	S.params = &lower;

	V.function = &val_func;
	V.params = 0;

	gsl_ntuple_project (h, ntuple, &V, &S);

	gsl_histogram_fprintf (stdout, h, "%f", "%f");
	gsl_histogram_free (h);
	gsl_ntuple_close (ntuple);

	return 0;
}
Esempio n. 8
0
File: kde.c Progetto: gulkhan007/kde
int histc(double *data, int length, double *xmesh, int n , double *bins)
{
	XML_IN;

	printf("-1\n");

	gsl_histogram * h = gsl_histogram_alloc(n-1);

	printf("0\n");

	gsl_histogram_set_ranges (h, xmesh, n);
	
	double h_max = gsl_histogram_max(h);
	double h_min = gsl_histogram_min(h);

	printf("h_min: %g h_max: %g\n",h_min,h_max);

	for (int i=0; i<length; i++)
		gsl_histogram_increment (h, data[i]);

	printf("2\n");

	for (int i=0;i<n-1;i++)
		bins[i] = gsl_histogram_get (h, i);

	printf("3\n");

	gsl_histogram_fprintf (stdout, h, "%g", "%g");
	/*...*/

	gsl_histogram_free(h);

	XML_OUT;
	return 0;
}
Esempio n. 9
0
gsl_histogram *
gsl_histogram_calloc (size_t n)
{
  gsl_histogram * h = gsl_histogram_alloc (n);

  if (h == 0)
    {
      return h;
    }

  {
    size_t i;

    for (i = 0; i < n + 1; i++)
      {
        h->range[i] = i;
      }

    for (i = 0; i < n; i++)
      {
        h->bin[i] = 0;
      }
  }

  h->n = n;

  return h;
}
Esempio n. 10
0
File: MCMC.cpp Progetto: rfok/MCMC
               //calls the Point(int) constructor, creating Point object parameters, before calling MCMC's
MCMC::MCMC() : parameters(DIMENSION), proposal_mean(DIMENSION,0.0), proposal_var(DIMENSION,PROPOSAL_VAR) {   
    rng = gsl_rng_alloc(gsl_rng_ranlxs0); //assigning a RNG to an MCMC object
    
	simulationLength = 5000000;
    accepts = 0;
    rejects = 0;
    
    bin_num = 50;
    range_min = 0;
    range_max = 5.0;
    thin_factor = 25;

    h = gsl_histogram_alloc(bin_num);
	gsl_histogram_set_ranges_uniform(h, range_min, range_max);

    bin_num_X = 50;
    bin_num_Y = 50;
    X_min = 0;
    X_max = 2;
    Y_min = 0;
    Y_max = 2;
    
    h2d	= gsl_histogram2d_alloc (bin_num_X, bin_num_Y);
    gsl_histogram2d_set_ranges_uniform (h2d, X_min, X_max, Y_min, Y_max);

}
Esempio n. 11
0
//Overloaded Constructors
population::population(int N_in, int L_in, double r_in, int seed_in, gsl_rng* rng_in) { //Neutral Evolution!
    try {
        if (r_in < 0 || r_in > 1 || N_in < 0 || L_in <0) {throw "Bad inputs. Check arguments.";}
        else {
            N = N_in;
            L = L_in;
            r = r_in;
            gen_pop = 0;
            neutral = true;
            avgFit = 0;
            selective_weight = vector<double>(N); //All zeros
            genetic_weight = vector< vector<int> >(N,vector<int>(L));
            fixations = vector< vector<fixation_event> > (N);
            seed = seed_in ? seed_in:get_random_seed();
            rng = rng_in;
            gsl_rng_set(rng,seed);
            blockHist = gsl_histogram_alloc(L);
            gsl_histogram_set_ranges_uniform(blockHist,1,L+1);
            for(int i=0;i<N;i++) {
                pop.push_back(genome(i,L,rng));
            }
            updateBlockSizes();
        }
    }
    catch(const char* Message) {cout << "Error: " << Message << "\n";}
}
Esempio n. 12
0
population::population(int N_in, int L_in, double r_in, int seed_in, gsl_rng* rng_in, vector< vector<double> >& fit) {
    try {
        if (fit.size() != N_in || fit[0].size() != L_in) {throw "Incorrect Fitness Landscape dimensions!";}
        else if (r_in < 0 || r_in > 1 || N_in < 0 || L_in <0) {throw "Bad inputs. Check arguments.";}
        else {
            N = N_in;
            L = L_in;
            r = r_in;
            gen_pop = 0;
            neutral = false;
            avgFit = 0;
            selective_weight = vector<double>(N);
            genetic_weight = vector< vector<int> >(N,vector<int>(L));
            fixations = vector< vector<fixation_event> > (N);
            seed = seed_in ? seed_in : get_random_seed();
            rng = rng_in;
            gsl_rng_set(rng,seed);
            blockHist = gsl_histogram_alloc(L);
            gsl_histogram_set_ranges_uniform(blockHist,1,L+1); //Questionable range choice. As it stands now, the bins are partitioned as follows {[1,2),[2,3)......[L,L+1)}. Thus if all have length L, then average will come out to be (L+.5). Will have to rescale.
            map<int,double> genome_fit;
            for(int i=0;i<N;i++) {
                genome_fit = convert_vector_toMap(fit[i]);
                if (!genome_fit.empty()) {pop.push_back(genome(i, L, rng, genome_fit));}
                else {pop.push_back(genome(i,L,rng));}
                avgFit += pop[i].get_fit();
            }
            avgFit/=N;
            update_selection_weights();
            updateBlockSizes();
        }
    }
    catch (const char* Message) {
        cout << "Error:" << Message << "\n";
    }
}
Esempio n. 13
0
/* Histogram a PETSC vector 
 *
 * x is the vector
 * nbins -- number of bins
 * xmin, xmax -- histogram xmin, xmax -- assume uniform bins
 * hh -- output vector -- assumed to be defined.
 */
void VecHist(const Vec& x, int nbins, double xmin, double xmax, vector<double>& hh) {
  gsl_histogram *h1; 
  double *_x, x1;
  PetscInt lo, hi;
  vector<double> tmp(nbins);

  // Set up the histogram struct
  h1 = gsl_histogram_alloc(nbins);
  gsl_histogram_set_ranges_uniform(h1, xmin, xmax);

  // Get the array
  VecGetOwnershipRange(x, &lo, &hi);
  hi -= lo;
  VecGetArray(x, &_x);
  for (PetscInt ii=0; ii < hi; ++ii) {
    x1 = _x[ii];
    if (x1 < xmin) x1 = xmin;
    if (x1 >= xmax) x1 = xmax - 1.e-10;
    gsl_histogram_increment(h1, x1);
  }
  VecRestoreArray(x, &_x);
  
  // Fill the temporary output vector
  for (int ii =0; ii<nbins; ++ii) 
    tmp[ii] = gsl_histogram_get(h1, ii);

  // MPI Allreduce
  MPI_Allreduce(&tmp[0], &hh[0], nbins, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD); 

  // Clean up
  gsl_histogram_free(h1);
}
Esempio n. 14
0
void AlexSim::simTestLognormal()
{
    int n=10000; // number of samples
    int nbins=100; // number of bins for the histogram

    QFile file("./AlexSimTestLognormal.txt");

    if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) QMessageBox::information(0, "error", file.errorString());
    QTextStream out(&file);
    out <<"# Test lognormal distribution. Parameters are: burstDuration="<<burstDuration<<"\tvariance="<<burstDurationVar<<"\n";
    out <<"# burst duration in ms\tfrequency\n";
    out.setRealNumberPrecision(11);

    gsl_histogram * hist = gsl_histogram_alloc (nbins);
    gsl_histogram_set_ranges_uniform (hist, 0, 10*burstDuration);
    for (int ii=0;ii<n;ii++) {
        gsl_histogram_increment (hist,gsl_ran_lognormal(r,mu,sigma));
    }

    for(unsigned int ii=0;ii<hist->n;ii++) {
        out << hist->range[ii]*1e3 << "\t" << gsl_histogram_get(hist,ii) << "\n";
    }
    file.close();
    gsl_histogram_free (hist);
}
Esempio n. 15
0
/* ==== */
static gsl_histogram *
ini_histogram_uniform(const int n,
		      const double min,
		      const double max)
{
  gsl_histogram *a = gsl_histogram_alloc(n);
  gsl_histogram_set_ranges_uniform(a,min,max);
  return a;
}
Esempio n. 16
0
gsl_histogram *AlexData::burstRateDistribution(size_t nbins)
{
    gsl_histogram *hist =  gsl_histogram_alloc(nbins);
    gsl_histogram_set_ranges_uniform(hist,burstSearchParamsGlobal.MinBurstrate*1e-3,burstSearchParamsGlobal.MaxBurstrate*1e-3);

    for(int i=0;i<burstVectorDual.size();++i)
        gsl_histogram_increment(hist, burstVectorDual.at(i).burstrate()*1e-3);

    return hist;
}
Esempio n. 17
0
gsl_histogram * create_hist(int nbins, double min, double max) {
	gsl_histogram * h;

	h = gsl_histogram_alloc(nbins);
	gsl_histogram_set_ranges_uniform(h, min, max);

	/* with out the following, the max element doesn't fall in the last bin */
	h->range[h->n] += (max - min) / 10000;
	return h;
}
Esempio n. 18
0
gsl_histogram *AlexData::burstDurationDistribution(size_t nbins)
{
    gsl_histogram *hist =  gsl_histogram_alloc(nbins);
    gsl_histogram_set_ranges_uniform(hist,0,burstSearchParamsGlobal.MaxDuration*1e3);

    for(int i=0;i<burstVectorDual.size();++i)
        gsl_histogram_increment(hist, burstVectorDual.at(i).duration*1e3);

    return hist;
}
Esempio n. 19
0
void QwtHistogram::initData(double *Y, int size)
{
	if(size<2 || (size == 2 && Y[0] == Y[1]))
	{//non valid histogram data
		double x[2], y[2];
		for (int i = 0; i<2; i++ ){
			y[i] = 0;
			x[i] = 0;
		}
		setData(x, y, 2);
		return;
	}

	int n = 10;//default value
	QVarLengthArray<double> x(n), y(n);//double x[n], y[n]; //store ranges (x) and bins (y)
	gsl_histogram * h = gsl_histogram_alloc (n);
	if (!h)
		return;

	gsl_vector *v;
	v = gsl_vector_alloc (size);
	for (int i = 0; i<size; i++ )
		gsl_vector_set (v, i, Y[i]);

	double min, max;
	gsl_vector_minmax (v, &min, &max);
	gsl_vector_free (v);

	d_begin = floor(min);
	d_end = ceil(max);

	gsl_histogram_set_ranges_uniform (h, floor(min), ceil(max));

	for (int i = 0; i<size; i++ )
		gsl_histogram_increment (h, Y[i]);

	for (int i = 0; i<n; i++ ){
		y[i] = gsl_histogram_get (h, i);
		double lower, upper;
		gsl_histogram_get_range (h, i, &lower, &upper);
		x[i] = lower;
	}

	setData(x.data(), y.data(), n);//setData(x, y, n);

	d_bin_size = (d_end - d_begin)/(double)n;
	d_autoBin = true;
    d_mean = gsl_histogram_mean(h);
	d_standard_deviation = gsl_histogram_sigma(h);
	d_min = gsl_histogram_min_val(h);
	d_max = gsl_histogram_max_val(h);

	gsl_histogram_free (h);
}
Esempio n. 20
0
int
main (int argc, char **argv)
{
  double a = 0.0, b = 1.0;
  size_t n = 10;

  if (argc != 3 && argc !=4)
    {
      printf ("Usage: gsl-histogram xmin xmax [n]\n");
      printf (
"Computes a histogram of the data on stdin using n bins from xmin to xmax.\n"
"If n is unspecified then bins of integer width are used.\n");
      exit (0);
    }

  a = atof (argv[1]);
  b = atof (argv[2]);

  if (argc == 4) 
    {
      n = atoi (argv[3]);
    }
  else
    {
      n = (int)(b - a) ;
    }

  {
    double x;
    gsl_histogram *h = gsl_histogram_alloc (n);

    gsl_histogram_set_ranges_uniform (h, a, b);

    while (fscanf(stdin, "%lg", &x) == 1)
      {
        gsl_histogram_increment(h, x);
      }

#ifdef DISPLAY_STATS
    {
      double mean = gsl_histogram_mean (h);
      double sigma = gsl_histogram_sigma (h);
      fprintf (stdout, "# mean = %g\n", mean);
      fprintf (stdout, "# sigma = %g\n", sigma);
    }
#endif

    gsl_histogram_fprintf (stdout, h, "%g", "%g");

    gsl_histogram_free (h);
  }

  return 0;
}
Esempio n. 21
0
gsl_histogram* population::get_cumulant_fit_hist(int l, double sigma) {
    //Initialize histogram.
    gsl_histogram* fit_hist = gsl_histogram_alloc(1000); //Think more about bin size.
    gsl_histogram_set_ranges_uniform(fit_hist, -10*l*sigma, 10*l*sigma);
    for (int n=0; n<N; n++) { //Iterate over the entire population.
        for (int i=0; i<L-l; i+l/2) { //Center Locus @ i+l/2
            gsl_histogram_increment(fit_hist,pop[n].sub_cumulant_fit(i,l)); //Histogram delta_f values. 
        }   
    }
    return fit_hist;
}
Esempio n. 22
0
gsl_histogram *AlexData::burstSizeDistribution(size_t nbins, double maxBurstSize)
{
    if(maxBurstSize==0) maxBurstSize = burstSearchParamsGlobal.MaxBurstrate*burstSearchParamsGlobal.MaxDuration;
    gsl_histogram *hist =  gsl_histogram_alloc(nbins);
    gsl_histogram_set_ranges_uniform(hist,burstSearchParamsGlobal.MinBurstSize,maxBurstSize);

    for(int i=0;i<burstVectorDual.size();++i)
        gsl_histogram_increment(hist, burstVectorDual.at(i).numberOfPhotons);

    return hist;
}
Esempio n. 23
0
void DistToPA(gsl_histogram * h, double mag, double sigma)
{

double m1 = 0.5*mag + 0.5;
double s1 = 0.25*sigma;
double n1 = m1*(1. - m1)/s1 - 1.; 
double a1 = m1*n1;
double b1 = (1. - m1)*n1;

    for (int pa = 1; pa < 8; pa++) {
        char line[80];
        double x;
        double data[6000];
        int size = 0;
        int nbins = h->n;
        gsl_histogram * hpa = gsl_histogram_alloc( nbins);
        gsl_histogram_set_ranges_uniform( hpa, 0.0, 1.0);

        char fname[50];
        sprintf(fname,"/home/jonatas/mzanlz/mZ_pa%d.dat",pa);
        FILE * fp;
        fp = fopen(fname,"rt");
        while(fgets(line,80,fp) != NULL){
            x = atof(line); 
            size++;
            data[size] = x;
            gsl_histogram_increment( hpa, x);
        }
        double m2 = 0.5*gsl_stats_mean( data, 1, size ) + 0.5;
        double s2 = 0.25*gsl_stats_variance( data, 1, size );
        double n2 = m2*(1. - m2)/s2 - 1.; 
        double a2 = m2*n2;
        double b2 = (1. - m2)*n2;


        NormalizaGSLHistograma( hpa );
        //char hname[100];
        //sprintf(hname,"pa%d",pa);
        //PrintGSLHistogram( hpa, hname );        

        gsl_histogram_sub( hpa, h);
        double D = 0;
        for (size_t i = 0; i < nbins; i++) {
            D += gsl_histogram_get( hpa , i )*gsl_histogram_get( hpa , i );
        }
        // printf("%g %g ", sqrt(D), KLbetas(a1,b1,a2,b2));

        fclose(fp);
        gsl_histogram_free( hpa );
    }

}
Esempio n. 24
0
File: i2c.c Progetto: useche/btstats
static gsl_histogram *new_hist()
{
	gsl_histogram *h;

	/* allocate bins and set ranges uniformally */
	h = gsl_histogram_alloc(N_BINS);
	gsl_histogram_set_ranges_uniform(h,0,N_BINS*BINS_SEP);

	/* last bin should hold everything greater
	 * than (N_BINS-1)*BINS_SEP */
	h->range[h->n] = DBL_MAX;

	return h;
}
Esempio n. 25
0
size_t histogram (size_t N, double *data, size_t nbins, double bin_min, double bin_max, gsl_histogram **hist) {
  size_t i;

  /* prepare the gsl_histogram structure */
  *hist = gsl_histogram_alloc (nbins);
  gsl_histogram_set_ranges_uniform (*hist, bin_min, bin_max);

  /* populate the bins in the histogram */
  for (i=0; i<N; i++)
    gsl_histogram_increment (*hist, data [i]);

  /* success */
  return MYLIB_SUCCESS;
}
Esempio n. 26
0
		/* Number the entries per bin in a given array */
void lin_bin(double* array, double* bins, int bin_size, int array_size, int* binned_array)
{
	int i=0, j=0;
#ifdef PRINT_INFO
	fprintf(stdout, "\nBinning into %d bins an array of size:%d...", bin_size, array_size);
#endif
	gsl_histogram *h = gsl_histogram_alloc (bin_size-1);
	gsl_histogram_set_ranges (h, bins, bin_size);
		
		for(i=0; i<array_size; i++)
			gsl_histogram_increment(h, array[i]);
		
		for(j=0; j<bin_size-1; j++)
			binned_array[j] = (int) h->bin[j];

	gsl_histogram_free(h);
}
Esempio n. 27
0
bool myHistogram::Convert(double *res,int n)
{
	gsl_histogram *r;
	if(n<=2) return false;
	double std=gsl_stats_sd(res,1,n);
	double bin=3.49*std/pow(n*1.0,1.0/3);//Scott's ruler
	if(bin<=0) return false;	
	double a=gsl_stats_min(res,1,n);
	double b=gsl_stats_max(res,1,n);
	int num=(int)((b-a)/bin);
	r=gsl_histogram_alloc(num);
	gsl_histogram_set_ranges_uniform(r,a,b);
	for(int i=0;i<n;i++)
	{
		gsl_histogram_increment(r,res[i]);
	}	
	Convert(r,n);	
	gsl_histogram_free(r);	
	return true;
}
Esempio n. 28
0
bool HistList::AddHist(double *res,int n,double m,double sd,CString raw)
{
	gsl_histogram *r;
	if(n<=0) return false;
	double std=gsl_stats_sd(res,1,n);
	double bin=3.49*std/pow(n*1.0,1.0/3);//Scott's ruler
	if(bin<=0) return false;	
	double a=gsl_stats_min(res,1,n);
	double b=gsl_stats_max(res,1,n);
	int num=(int)((b-a)/bin);
	r=gsl_histogram_alloc(num);
	gsl_histogram_set_ranges_uniform(r,a,b);
	for(int i=0;i<n;i++)
	{
		gsl_histogram_increment(r,res[i]);
	}
	bool bResult=AddHist(r,m,sd,raw);
	gsl_histogram_free(r);
	return bResult;
}
Esempio n. 29
0
/** @short Markov Chain Monte Carlo 
		@param rng the GSL random number generator 
		@param p the vector of parameters being searched over 
		@param x the vector of observations */
void mcmc(const gsl_rng *rng, gsl_vector *p, const gsl_vector *x)
{
	gsl_vector * p_test = gsl_vector_alloc(p->size);
	size_t i;
	
	gsl_histogram * hist = gsl_histogram_alloc(nbins);
	gsl_histogram_set_ranges_uniform(hist, min, max);

	for(i=0; i < chain_length; i++)
	{
		gsl_vector_memcpy(p_test,p);
		propose(rng, p_test);
		double lnLikelihoodRatio = ln_lik_fn(p_test, x) - ln_lik_fn(p, x);
		if (take_step(rng, lnLikelihoodRatio))
			p = p_test;
		gsl_histogram_increment(hist, p->data[1]);
	}
	gsl_vector_free(p_test);
	gsl_histogram_fprintf(stdout, hist, "%g", "%g");
	gsl_histogram_free(hist);
}
Esempio n. 30
0
QVector<QPointF> DistanceToAtom::histogram(int bins) {
    QVector<QPointF> histogramVector;

    if(!m_isValid) {
        qFatal("DistanceToAtom is not valid. Run compute() first.");
        exit(1);
    }
    float minValue = 1e90;
    float maxValue = 0;

    for(const float &val : m_values) {
        if(val >= 0) {
            minValue = std::min(minValue, (float)sqrt(val));
            maxValue = std::max(maxValue, (float)sqrt(val));
        }
    }
    gsl_histogram *hist = gsl_histogram_alloc (bins);
    gsl_histogram_set_ranges_uniform (hist, minValue, maxValue);
    for(const float &value : m_values) {
        if(value >= 0) {
            gsl_histogram_increment (hist, sqrt(value));
        }
    }

    histogramVector.resize(bins);
    for(int i=0; i<bins; i++) {
        double upper, lower;
        gsl_histogram_get_range(hist, i, &lower, &upper);
        float middle = 0.5*(upper+lower);
        histogramVector[i].setX(middle);
        histogramVector[i].setY(gsl_histogram_get(hist,i));
    }

    gsl_histogram_free (hist);

    return histogramVector;
}