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; }
void ALEXHistogramsWidget::plotHistogramS() { // pr histogram plot=ui->widPlotHistS; JKQTPdatastore* ds=plot->get_plotter()->getDatastore(); plot->get_plotter()->clearGraphs(true); ds->clear(); plot->get_plotter()->getYAxis()->set_axisLabel("S"); plot->get_plotter()->getXAxis()->set_axisLabel("frequency"); int nbins=ui->spinBoxBins->value(); gsl_histogram * histS=gsl_histogram_calloc_uniform(nbins,ad->rangeALEX.minP,ad->rangeALEX.maxP); gsl_histogram * histSFiltered=gsl_histogram_calloc_uniform(nbins,ad->rangeALEX.minP,ad->rangeALEX.maxP); for(int i=0;i<ad->burstVectorDual.size();++i) { gsl_histogram_increment(histS,ad->burstVectorDual.at(i).stoichiometryRatio); if(!ad->burstVectorDual.at(i).isMasked(ad->FRETparams)) gsl_histogram_increment(histSFiltered,ad->burstVectorDual.at(i).stoichiometryRatio); } qDebug("plot S histogram"); unsigned long long nrows=histS->n; size_t yColumn=ds->addCopiedColumn(histS->range, nrows, "s"); // adds column and returns column ID size_t xColumn=ds->addCopiedColumn(histS->bin, nrows, "all"); size_t xColumnFiltered=ds->addCopiedColumn(histSFiltered->bin, nrows, "selected"); gsl_histogram_free(histS); gsl_histogram_free(histSFiltered); JKQTPbarVerticalGraph* g=new JKQTPbarVerticalGraph(plot->get_plotter()); // g->set_title("S"); g->set_xColumn(xColumn); g->set_yColumn(yColumn); g->set_shift(0); g->set_width(1); g->set_style(Qt::NoPen); g->set_fillColor(QColor(DISTRIBUTION_COLOR)); plot->addGraph(g); g=new JKQTPbarVerticalGraph(plot->get_plotter()); g->set_xColumn(xColumnFiltered); g->set_yColumn(yColumn); g->set_shift(0); g->set_width(1); g->set_style(Qt::NoPen); g->set_fillColor(QColor(DISTRIBUTION_COLOR_SELECTED)); plot->addGraph(g); plot->get_plotter()->zoomToFit(); // JKQTPhorizontalRange *gr; // gr = new JKQTPhorizontalRange(plot->get_plotter()); // gr->set_rangeMin(ad->FRETparams.MinS); // gr->set_rangeMax(ad->FRETparams.MaxS); // gr->set_invertedRange(true); // QColor col = QColor(Qt::lightGray); // col.setAlpha(ui->spinBoxAlpha->value()); // gr->set_fillColor(col); // gr->set_style(Qt::NoPen); // gr->set_plotCenterLine(false); // plot->addGraph(gr); }
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; }
/* Record the radial distribution already normalized * correctly for the current timestep. */ void RadialDistribution::record( std::vector<Particle>& activeParticles, double t) { double radius = 0.; for (int i=0; i<activeParticles.size(); i++) { for (int j=0; j<activeParticles.size(); j++) { if (this->isInConsidered( activeParticles[i].typeId, activeParticles[j].typeId)) { if (i != j) { getMinDistanceSquared( radius, activeParticles[i].position, activeParticles[j].position, this->isPeriodic, this->boxsize); radius = sqrt(radius); gsl_histogram_increment(this->radialDistribution, radius); } } } } // copy the hist to 'bins' while scaling every value correctly for (int i=0; i<bins.size(); i++) { bins[i] += gsl_histogram_get(this->radialDistribution, i) / (binCenters[i] * binCenters[i]); } gsl_histogram_reset(this->radialDistribution); }
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); }
void append_to_hists(gsl_histogram ** hists, unsigned int n, const char * filename) { FILE * input; unsigned int i; int col; double v; int line = 0; input = openfile(filename); while (!feof(input)) { for (i = 0; i < n; i++) { col = fscanf(input, "%lf", &v); if (col != 1) { if (feof(input)) break; fprintf(stderr, "field could not be read: %d, line %d in %s\n", i + 1, line + 1, filename); exit(1); } gsl_histogram_increment(hists[i], v); } line++; } dump_i("read lines", line); fclose(input); }
/* 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); }
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); }
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; }
int gsl_ntuple_project (gsl_histogram * h, gsl_ntuple * ntuple, gsl_ntuple_value_fn * value_func, gsl_ntuple_select_fn * select_func) { size_t nread; do { nread = fread (ntuple->ntuple_data, ntuple->size, 1, ntuple->file); if (nread == 0 && feof(ntuple->file)) { break ; } if (nread != 1) { GSL_ERROR ("failed to read ntuple for projection", GSL_EFAILED); } if (EVAL(select_func, ntuple->ntuple_data)) { gsl_histogram_increment (h, EVAL(value_func, ntuple->ntuple_data)); } } while (1); return GSL_SUCCESS; }
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); }
void MCMC::entropyPlot(double norm, string fileName, string fileOut){ vector<double> convergence; fstream file; file.open(fileName.c_str(), ios::in); if (file.is_open()){ int step = 0; while(file.good()){ double x; ++step; file >> x; gsl_histogram_increment(h,x); double conv = 0; for(int i =0; i < bin_num; i++){ double range_avg = (h->range[i] + h->range[i+1])/2.0; Point param = Point(DIMENSION,range_avg); //this might need to change in multidimensions // i.e. make a point object constructor Point(int, vector) double f1 = posterior_distribution(param)/norm; double f2 = h->bin[i]/((h->range[i+1] - h->range[i])*(step/thin_factor)); conv += loss(f1,f2); } convergence.push_back(conv); } }
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; }
void population::updateBlockSizes(){ gsl_histogram_reset(blockHist); for (int i=0;i<N;i++){ for (int j=0; j<pop[i].g.size(); j++) { gsl_histogram_increment(blockHist,pop[i].g[j].get_width()); } } }
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; }
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; }
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; }
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); }
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; }
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; }
void update_fit_cumulant_histogram_2(gsl_histogram* h, int l, vector<vector<double> >& fitness_landscape) { int L = fitness_landscape[0].size(); for (int n=0; n<fitness_landscape.size(); n++) { for (int i=0; i<(L-l); i+=((l/2)+(l%2))) { //Iterate over entire genome. double delta_fit = 0; for (int j=i; j<=i+l; j++) { delta_fit += fitness_landscape[n][j]; } gsl_histogram_increment(h,delta_fit); } } }
/** * nc_cluster_abundance_bin_realization: (skip) * @zr: FIXME * @h: FIXME * * FIXME */ void nc_cluster_abundance_bin_realization (GArray *zr, gsl_histogram **h) { guint i; for (i = 0; i < zr->len; i++) { int j; const gdouble z = g_array_index (zr, gdouble, i); for (j = 0; h[j] != NULL; j++) gsl_histogram_increment (h[j], z); } }
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 ); } }
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; }
/* 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); }
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; }
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; }
/** @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); }
void update_fit_cumulant_histogram(gsl_histogram* h, int l, vector<vector<double> >& fitness_landscape) { //If no fixation vector is passed, assume you want unconditioned histogram. double delta_fit = 0; double last_delta_fit = 0; int L = fitness_landscape[0].size(); for (int n=0; n<fitness_landscape.size(); n++) { for (int i=0; i<(L-l); i++) { //Iterate over entire genome. if (i == 0) { delta_fit = 0; for (int j=0; j<l; j++) { delta_fit += fitness_landscape[n][j]; } last_delta_fit = delta_fit; } else { delta_fit = delta_fit - fitness_landscape[n][i-1] + fitness_landscape[n][i+l]; last_delta_fit = delta_fit; } gsl_histogram_increment(h,delta_fit); } } }
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; }