int main(int argc, char **argv) { enum Constexpr {n_points = 1000}; double mu = 1.0; gsl_odeiv2_system sys = {ode_func, ode_jac, 2, &mu}; gsl_odeiv2_driver * d= gsl_odeiv2_driver_alloc_y_new( &sys, gsl_odeiv2_step_rk8pd, 1e-6, 1e-6, 0.0 ); int i; double t = 0.0; double t1 = 100.0; /* Initial condition: f = 0 with speed 0. */ double y[2] = {1.0, 0.0}; double dt = t1 / n_points; double datax[n_points]; double datay[n_points]; for (i = 0; i < n_points; i++) { double ti = i * dt; int status = gsl_odeiv2_driver_apply(d, &t, ti, y); if (status != GSL_SUCCESS) { fprintf(stderr, "error, return value=%d\n", status); break; } /* Get output. */ printf("%.5e %.5e %.5e\n", t, y[0], y[1]); datax[i] = y[0]; datay[i] = y[1]; } /* Cleanup. */ gsl_odeiv2_driver_free(d); /* Plot. */ if (argc > 1 && argv[1][0] == '1') { plsdev("xwin"); plinit(); plenv( gsl_stats_min(datax, 1, n_points), gsl_stats_max(datax, 1, n_points), gsl_stats_min(datay, 1, n_points), gsl_stats_max(datay, 1, n_points), 0, 1 ); plstring(n_points, datax, datay, "*"); plend(); } return EXIT_SUCCESS; }
static ERL_NIF_TERM max(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[]) { double_list dl = alloc_double_list(env, argv[0]); ARG_ERROR_IF_DL_IS_NULL(dl); ERL_NIF_TERM final = enif_make_double(env, gsl_stats_max(dl.list, 1, dl.length)); free_double_list(dl); return final; }
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; }
void function_initial_estimate( const double* pdX, const double* pdY, int iLength, double* pdParameterEstimates ) { double dMin; double dMax; gsl_stats_minmax( &dMin, &dMax, pdX, 1, iLength ); pdParameterEstimates[0] = gsl_stats_mean( pdX, 1, iLength ); pdParameterEstimates[1] = ( dMax - dMin ) / 2.0; pdParameterEstimates[2] = gsl_stats_max( pdY, 1, iLength ); }
/*! \fn double array_max(double *x, int n) * \brief Return the maximum of an array. */ double array_max(double *x, int n) { /*double m = x[0]; for(int i=1;i<n;i++) { m = GSL_MAX_DBL(m,x[i]); }*/ double m = gsl_stats_max(x,1,n); return m; }
/* Statistics code * Make only one call to reading for a particular time range and compute all our stats */ void _compute_statistics(cdb_range_t *range, uint64_t *num_recs, cdb_record_t *records) { uint64_t i = 0; uint64_t valid = 0; double sum = 0.0; double *values = calloc(*num_recs, sizeof(double)); for (i = 0; i < *num_recs; i++) { if (!isnan(records[i].value)) { sum += values[valid] = records[i].value; valid++; } } range->num_recs = valid; range->mean = gsl_stats_mean(values, 1, valid); range->max = gsl_stats_max(values, 1, valid); range->min = gsl_stats_min(values, 1, valid); range->sum = sum; range->stddev = gsl_stats_sd(values, 1, valid); range->absdev = gsl_stats_absdev(values, 1, valid); /* The rest need sorted data */ gsl_sort(values, 1, valid); range->median = gsl_stats_median_from_sorted_data(values, 1, valid); range->pct95th = gsl_stats_quantile_from_sorted_data(values, 1, valid, 0.95); range->pct75th = gsl_stats_quantile_from_sorted_data(values, 1, valid, 0.75); range->pct50th = gsl_stats_quantile_from_sorted_data(values, 1, valid, 0.50); range->pct25th = gsl_stats_quantile_from_sorted_data(values, 1, valid, 0.25); /* MAD must come last because it alters the values array * http://en.wikipedia.org/wiki/Median_absolute_deviation */ for (i = 0; i < valid; i++) { values[i] = fabs(values[i] - range->median); if (values[i] < 0.0) { values[i] *= -1.0; } } /* Final sort is required MAD */ gsl_sort(values, 1, valid); range->mad = gsl_stats_median_from_sorted_data(values, 1, valid); free(values); }
int main(void) { double data[5] = {17.2, 18.1, 16.5, 18.3, 12.6}; double mean, variance, largest, smallest; mean = gsl_stats_mean(data, 1, 5); variance = gsl_stats_variance(data, 1, 5); largest = gsl_stats_max(data, 1, 5); smallest = gsl_stats_min(data, 1, 5); printf ("The dataset is %g, %g, %g, %g, %g\n", data[0], data[1], data[2], data[3], data[4]); printf ("The sample mean is %g\n", mean); printf ("The estimated variance is %g\n", variance); printf ("The largest value is %g\n", largest); printf ("The smallest value is %g\n", smallest); return 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; }
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; }
void streamRtsFile(xmlTextReaderPtr reader) { if (reader == NULL) { fprintf(stderr, "Unable to access the file.\n"); exit(EXIT_FAILURE); } int ret; if (verbose) { printf("=== Analyzing ===\n"); } ret = xmlTextReaderRead(reader); while (ret == 1 && cont > 0) { processNode(reader); ret = xmlTextReaderRead(reader); } if (ret != 0 && cont > 0) { printf("Failed to parse.\n"); return; } printf("=== FU result ===\n"); double mean = gsl_stats_mean(fuArray, 1, limit); printf("Mean:\t\t%.5f (%.3f)\n", mean, mean * 100.0); double variance = gsl_stats_variance_m(fuArray, 1, limit, mean); printf("Variance:\t%.5f\n", variance); double stddev = gsl_stats_sd_m(fuArray, 1, limit, mean); printf("Std. Dev:\t%.5f\n", stddev); double max = gsl_stats_max(fuArray, 1, limit); printf("Max:\t\t%.5f (%.3f)\n", max, max * 100.0); double min = gsl_stats_min(fuArray, 1, limit); printf("Min:\t\t%.5f (%.3f)\n", min, min * 100.0); printf("Total RTS:\t%d\n", rtsNr); printf("Valid RTS:\t%d\n", validFuCnt); printf("Invalid RTS:\t%d\n", invalidFuCnt); }
double bayestar_log_posterior_toa_phoa_snr( double ra, double sin_dec, double distance, double u, double twopsi, double t, double gmst, /* Greenwich mean sidereal time in radians. */ int nifos, /* Input: number of detectors. */ const float (**responses)[3], /* Pointers to detector responses. */ const double **locations, /* Pointers to locations of detectors in Cartesian geographic coordinates. */ const double *toas, /* Input: array of times of arrival with arbitrary relative offset. (Make toas[0] == 0.) */ const double *phoas, /* Input: array of times of arrival with arbitrary relative offset. (Make toas[0] == 0.) */ const double *snrs, /* Input: array of SNRs. */ const double *w_toas, /* Input: sum-of-squares weights, (1/TOA variance)^2. */ const double *w1s, /* Input: first moments of angular frequency. */ const double *w2s, /* Input: second moments of angular frequency. */ const double *horizons, /* Distances at which a source would produce an SNR of 1 in each detector. */ int prior_distance_power) /* Use a prior of (distance)^(prior_distance_power) */ { int iifo; const double dec = asin(sin_dec); const double u2 = gsl_pow_2(u); const double complex exp_i_twopsi = exp_i(twopsi); (void)w2s; /* FIXME: remove unused parameter */ /* Compute time of arrival errors */ double dt[nifos]; toa_errors(dt, M_PI_2 - dec, ra, gmst, nifos, locations, toas); { double mean_dt = gsl_stats_wmean(w_toas, 1, dt, 1, nifos); for (iifo = 0; iifo < nifos; iifo++) dt[iifo] += t - mean_dt; } /* Rescale distances so that furthest horizon distance is 1. */ double d1[nifos]; { const double d1max = gsl_stats_max(horizons, 1, nifos); for (iifo = 0; iifo < nifos; iifo ++) d1[iifo] = horizons[iifo] / d1max; distance /= d1max; } double logp = 0; double complex i0arg_complex = 0; double A = 0; double B = 0; /* Loop over detectors */ for (iifo = 0; iifo < nifos; iifo++) { double complex F; XLALComputeDetAMResponse( (double *)&F, /* Type-punned real part */ 1 + (double *)&F, /* Type-punned imag part */ responses[iifo], ra, dec, 0, gmst); F *= d1[iifo]; const double complex tmp = F * exp_i_twopsi; double complex phase_rhotimesr = 0.5 * (1 + u2) * creal(tmp) + I * u * cimag(tmp); const double abs_rhotimesr_2 = cabs2(phase_rhotimesr); const double abs_rhotimesr = sqrt(abs_rhotimesr_2); phase_rhotimesr /= abs_rhotimesr; i0arg_complex += exp_i(phoas[iifo] + w1s[iifo] * dt[iifo]) * phase_rhotimesr * gsl_pow_2(snrs[iifo]); logp += -0.5 * w_toas[iifo] * gsl_pow_2(dt[iifo]); A += abs_rhotimesr_2; B += abs_rhotimesr * snrs[iifo]; } A *= -0.5; const double i0arg = cabs(i0arg_complex); /* Should be equivalent to, but more accurate than: logp += log(gsl_sf_bessel_I0(i0arg)) */ logp += log(gsl_sf_bessel_I0_scaled(i0arg)) + i0arg; logp += log_radial_integrand(distance, A, B, prior_distance_power); return logp; }
CAMLprim value ml_gsl_stats_max(value data) { size_t len = Double_array_length(data); double result = gsl_stats_max(Double_array_val(data), 1, len); return copy_double(result); }