Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
static ERL_NIF_TERM min(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_min(dl.list, 1, dl.length));
    free_double_list(dl);
    return final;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
/*! \fn double array_min(double *x, int n)
 *  \brief Return the minimum of an array. */
double array_min(double *x, int n)
{
	/*double m = x[0];
	for(int i=1;i<n;i++)
	{
		m = GSL_MIN_DBL(m,x[i]);
	}*/
	double m = gsl_stats_min(x,1,n);
	return m;
}
Ejemplo n.º 5
0
/* 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);
}
double comp_intersect_histogram2d_gsl (gsl_histogram2d * patch_histogram, gsl_histogram2d * texture_histogram, int bins_x, int bins_y) {	// high value is a positive match

	double these_histogram_sums [2] = {gsl_histogram2d_sum(patch_histogram), gsl_histogram2d_sum(texture_histogram)};
	double min_histogram_sum = gsl_stats_min(these_histogram_sums, 1, 2);

	double these_bin_values [2];
	double cum_min_bin_values = 0.0;

	int i, j;

	for (j=0; j<bins_y; j++)
	{
		for (i=0; i<bins_x; i++)
		{
			these_bin_values[0] = gsl_histogram2d_get(patch_histogram, i, j);
			these_bin_values[1] = gsl_histogram2d_get(texture_histogram, i, j);

			cum_min_bin_values += gsl_stats_min(these_bin_values, 1, 2); 
		}
	}

	return cum_min_bin_values/min_histogram_sum;

}
Ejemplo n.º 7
0
Archivo: stat.c Proyecto: lemahdi/mglib
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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
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);
}
Ejemplo n.º 11
0
CAMLprim value ml_gsl_stats_min(value data)
{
  size_t len = Double_array_length(data);
  double result = gsl_stats_min(Double_array_val(data), 1, len);
  return copy_double(result);
}