All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.utils.StatisticsUtils.scala Maven / Gradle / Ivy

The newest version!
package it.unibo.utils

object StatisticsUtils {
  import Numeric.Implicits._

  def mean[T: Numeric](xs: Iterable[T]): Double = xs.sum.toDouble / xs.size

  def variance[T: Numeric](xs: Iterable[T]): Double = {
    val avg = mean(xs)
    xs.map(_.toDouble).map(a => math.pow(a - avg, 2)).sum / xs.size
  }

  def stdDev[T: Numeric](xs: Iterable[T]): Double = math.sqrt(variance(xs))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy