Exemplo n.º 1
0
void
test_basic(const size_t n, const double data[], const double tol)
{
  gsl_rstat_workspace *rstat_workspace_p = gsl_rstat_alloc();
  const double expected_mean = gsl_stats_mean(data, 1, n);
  const double expected_var = gsl_stats_variance(data, 1, n);
  const double expected_sd = gsl_stats_sd(data, 1, n);
  const double expected_sd_mean = expected_sd / sqrt((double) n);
  const double expected_skew = gsl_stats_skew(data, 1, n);
  const double expected_kurtosis = gsl_stats_kurtosis(data, 1, n);
  double expected_rms = 0.0;
  double mean, var, sd, sd_mean, rms, skew, kurtosis;
  size_t i, num;
  int status;

  /* compute expected rms */
  for (i = 0; i < n; ++i)
    expected_rms += data[i] * data[i];

  expected_rms = sqrt(expected_rms / n);

  /* add data to rstat workspace */
  for (i = 0; i < n; ++i)
    gsl_rstat_add(data[i], rstat_workspace_p);

  mean     = gsl_rstat_mean(rstat_workspace_p);
  var      = gsl_rstat_variance(rstat_workspace_p);
  sd       = gsl_rstat_sd(rstat_workspace_p);
  sd_mean  = gsl_rstat_sd_mean(rstat_workspace_p);
  rms      = gsl_rstat_rms(rstat_workspace_p);
  skew     = gsl_rstat_skew(rstat_workspace_p);
  kurtosis = gsl_rstat_kurtosis(rstat_workspace_p);
  num      = gsl_rstat_n(rstat_workspace_p);

  gsl_test_int(num, n, "n n=%zu" , n);
  gsl_test_rel(mean, expected_mean, tol, "mean n=%zu", n);
  gsl_test_rel(var, expected_var, tol, "variance n=%zu", n);
  gsl_test_rel(sd, expected_sd, tol, "stddev n=%zu", n);
  gsl_test_rel(sd_mean, expected_sd_mean, tol, "stddev_mean n=%zu", n);
  gsl_test_rel(rms, expected_rms, tol, "rms n=%zu", n);
  gsl_test_rel(skew, expected_skew, tol, "skew n=%zu", n);
  gsl_test_rel(kurtosis, expected_kurtosis, tol, "kurtosis n=%zu", n);

  status = gsl_rstat_reset(rstat_workspace_p);
  gsl_test_int(status, GSL_SUCCESS, "rstat returned success");
  num = gsl_rstat_n(rstat_workspace_p);

  gsl_test_int(num, 0, "n n=%zu" , n);

  gsl_rstat_free(rstat_workspace_p);
}
Exemplo n.º 2
0
Arquivo: bin2d.c Projeto: pa345/lib
size_t
bin2d_n(const double x, const double y, const bin2d_workspace *w)
{
  size_t binx = bin2d_findbin(x, w->xmin, w->xmax, w->nx);
  size_t biny = bin2d_findbin(y, w->ymin, w->ymax, w->ny);
  size_t n;

  n = gsl_rstat_n(w->bins[BIN2D_IDX(binx, biny, w)]);

  return n;
} /* bin2d_n() */