A very simple class wrapping an Iterable[Product2[A,B]] and providing
basic weighted statistics like weighted mean and weighted variance.
The first element of the Pair is the value and the second element the weight.
There is an implicit conversion from a Seq[Product2[A,B]] to a
WeightedStats[A,B] imported with com.github.marklister.collections. So you do
not need to do anything to use this class. Simply use the mean, stdDev
or variance methods on an appropriate sequence:
import com.github.marklister.collections.io._
import com.github.marklister.collections._
Welcome to Scala version 2.10.1 (OpenJDK Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> CollSeq((1,2),(2,1),(3,3)).mean
res1: Double = 2.1666666666666665
I would really prefer to use an external library. If you know of one please
raise an issue on Github
A very simple class wrapping an
Iterable[Product2[A,B]]
and providing basic weighted statistics like weighted mean and weighted variance.The first element of the Pair is the value and the second element the weight.
There is an implicit conversion from a
Seq[Product2[A,B]]
to aWeightedStats[A,B]
imported with com.github.marklister.collections. So you do not need to do anything to use this class. Simply use themean
,stdDev
orvariance
methods on an appropriate sequence:I would really prefer to use an external library. If you know of one please raise an issue on Github