在Java中实现区间数据的高效频率表的方法

huangapple go评论76阅读模式
英文:

Efficient way to implement frequency table on interval data in Java

问题

我正在尝试创建一个频率表,最终要用它来创建直方图。输入数据的类型是Double,应该都在区间[-1;1]内。我想将这个区间分成宽度为0.02的箱子,并计算每个区间内值的出现次数,不需要存储数据。

我尝试使用Apache Commons Frequency,但似乎只适用于离散值。

是否有一个库可以实现这个功能?

英文:

I am trying to create a frequency table to eventually create a histogram. The input data is of type Double and should all fall in the interval [-1;1]. I would like to divide this interval into bins with a width of e.g. .02 and count the occurrences of values in each interval, there is no need to store the data.

I tried using Apache Commons Frequency, but that only seems to work with discrete values.

Is there a library that achieves this?

答案1

得分: 0

以下是翻译好的部分:

"While I haven't been able to find a library that does what I wanted, here's the solution I came up with in case anyone finds this in the future:

我尚未找到符合我的要求的库,但这是我想出的解决方案,以防将来有人发现:

I created a datatype representing an Interval similar to one I found in Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

我创建了一个表示区间的数据类型,类似于我在《算法》第4版,Robert Sedgewick和Kevin Wayne著中找到的一个。

The actual frequency table is implemented as a TreeMap<Interval, Integer>, since that is able to store the entries in the order of the keys (the Interval implementation needs a Comparator for this to work). Then all I needed to add was method to add observations, which increments the value of the interval in the TreeMap.

实际的频率表是实现为TreeMap<Interval, Integer>,因为它能够按键的顺序存储条目(Interval的实现需要一个Comparator才能正常工作)。然后,我只需要添加一个用于添加观测值的方法,该方法会增加TreeMap中区间的值。

May not be the most efficient way to solve this, but it seems to work for my purposes.

这可能不是解决此问题的最有效方式,但似乎适用于我的目的。"

英文:

While I haven't been able to find a library that does what I wanted, here's the solution I came up with in case anyone finds this in the future:

I created a datatype representing an Interval similar to one I found in Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

The actual frequency table is implemented as a TreeMap<Interval, Integer>, since that is able to store the entries in the order of the keys (the Interval implementation needs a Comparator for this to work). Then all I needed to add was method to add observations, which increments the value of the interval in the TreeMap.

May not be the most efficient way to solve this, but it seems to work for my purposes.

huangapple
  • 本文由 发表于 2020年8月5日 15:39:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63260502.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定