c++ - gsl_histogram : Value being equal to an edge between two bins, 值会分配给哪个bin?

标签 c++ c gsl

gsl_histogram 的哪个 bin 的值恰好落在两个 bin 之间的边缘?
例如。当我调用 gsl_histogram_increment( h, x) 时,x 恰好为 0 且 bin 边缘为 -0.2、0、0.2、0.4 等,我会得到正范围内的增量 (0, 0.2 ) 或负范围 (-0.2, 0)?

编辑:是的,我的范围是统一的。

最佳答案

如果您的 bin 分布是线性的(如您的示例所示),那么这是正在执行的代码(取自 gsl-1.15/histogram/find.c):

  /* optimize for linear case */

#ifdef LINEAR_OPT
  {
    double u =  (x - range[0]) / (range[n] - range[0]);
    i_linear = (size_t) (u * n);
  }

  if (x >= range[i_linear] && x < range[i_linear + 1])
    {
      *i = i_linear;
      return 0;
    }
#endif

请注意 >= 表示 bin 下边缘,< 表示 bin 上边缘,因此您的 0.0 值应该落入 0.0 - 0.2 bin

对于非线性 bin 分布,执行二进制搜索,即:

  /* perform binary search */

  upper = n ;
  lower = 0 ;

  while (upper - lower > 1)
    {
      mid = (upper + lower) / 2 ;

      if (x >= range[mid])
        {
          lower = mid ;
        }
      else
        {
          upper = mid ;
        }
    }

  *i = lower ;

请注意 >= 的用法意味着落在 bin 边缘的值将包含在两者的“上”bin 中(与线性情况相同)

也许可以通过运行您的示例并观察将值添加到哪个 bin 来仔细检查

关于c++ - gsl_histogram : Value being equal to an edge between two bins, 值会分配给哪个bin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15246006/

相关文章:

c++ - 在 C++ 中使用 cURL 和多线程

c++ - C++ 中的运行时接口(interface)和对象组合

c++ - C/C++ malloc 一 block 内存,然后将不同的部分用于不同的任意类型

c - 从字符串 C 中获取 int 值

c中的命令行解释器

c++ - 从 QML 访问 C++ 函数

c - 用于枚举格式 C 代码的 Eclipse 插件

c++ - g++ 与 GSL 的链接问题

c - OpenMP 和 GSL RNG - 性能问题 - 4 线程实现比纯顺序线程(四核 CPU)慢 10 倍

通过 M<N 的 GSL 计算矩阵的零空间会产生错误