To generate mobile apps session metrics, we use Q tree in this quantiles function. However, when the data type is Long, the result is incorrect. In the last example of this documentation, the range of the median of List(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8) is (5.0,6.0), while the true median is 4.5.
Correction to the listed example, with our version this is what i get:
scala> val data = List(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8)
data: List[Int] = List(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8)
scala> val qtSemigroup = new QTreeSemigroup[Long](6)
qtSemigroup: com.twitter.algebird.QTreeSemigroup[Long] = com.twitter.algebird.QTreeSemigroup@7c46ceff
scala> val sum = qtSemigroup.sumOption(seqQTree).get
sum: com.twitter.algebird.QTree[Long] = QTree(0,4,16,0,Some(QTree(0,3,14,0,Some(QTree(0,2,6,0,Some(QTree(0,1,2,0,None,Some(QTree(1,0,2,2,None,None)))),Some(QTree(1,1,4,0,Some(QTree(2,0,2,4,None,None)),Some(QTree(3,0,2,6,None,None)))))),Some(QTree(1,2,8,0,Some(QTree(2,1,4,0,Some(QTree(4,0,2,8,None,None)),Some(QTree(5,0,2,10,None,None)))),Some(QTree(3,1,4,0,Some(QTree(6,0,2,12,None,None)),Some(QTree(7,0,2,14,None,None)))))))),Some(QTree(1,3,2,0,Some(QTree(2,2,2,0,Some(QTree(4,1,2,0,Some(QTree(8,0,2,16,None,None)),None)),None)),None)))
scala> sum.quantileBounds(0.5)
res22: (Double, Double) = (4.0,5.0)
See more details about this issue: https://github.com/twitter/algebird/issues/517
As a solution, we may change the data type from Long to Double.