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)中獲得增量?gsl_histogram:值等於兩個倉之間的邊,值將分配給哪個倉?
編輯:是的,我的範圍是統一的。
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)中獲得增量?gsl_histogram:值等於兩個倉之間的邊,值將分配給哪個倉?
編輯:是的,我的範圍是統一的。
如果你的bin分佈是線性的(如在實施例),那麼這是正在執行的代碼(從GSL-1.15 /直方圖/ 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
注意到> =對於下箱邊緣和<爲上層紙槽邊緣因此你的0.0的值應落入0.0 - 0.2倉
用於執行二進制搜索非線性倉分佈,即:
/* 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邊上的值將包含在兩者的'upper'bin中(與線性情況相同)
可能通過運行您的示例並觀察什麼倉的值被添加到
+1查找實際來源,這是比谷歌搜索更權威:) – gcbenison 2013-03-06 12:34:46
gsl_histogram_increment
appears to use條件L <= x < U
來決定是否將值x
賓縣(L, U)
。因此0
將最終在(0, 0.2)
。
+1驗證 – damage 2013-03-06 12:43:04
請注意'0.2'不能完全表示。 – PlasmaHH 2013-03-06 11:27:23