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

dererXII.scalashogi_2.13.5.0.2.source-code.DecayingStats.scala Maven / Gradle / Ivy

There is a newer version: 12.1.1
Show newest version
package shogi

trait DecayingRecorder {
  def record(value: Float): DecayingStats
}

final case class DecayingStats(
    mean: Float,
    deviation: Float,
    decay: Float
) extends DecayingRecorder {
  def record(value: Float): DecayingStats = {
    val delta = mean - value

    copy(
      mean = value + decay * delta,
      deviation = decay * deviation + (1 - decay) * math.abs(delta)
    )
  }

  def record[T](values: Iterable[T])(implicit n: Numeric[T]): DecayingStats =
    values.foldLeft(this) { (s, v) =>
      s record n.toFloat(v)
    }
}

final case class EmptyDecayingStats(
    deviation: Float,
    decay: Float
) extends DecayingRecorder {
  def record(value: Float) =
    DecayingStats(
      mean = value,
      deviation = deviation,
      decay = decay
    )
}

object DecayingStats {
  val empty = EmptyDecayingStats
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy