aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2012-11-01 13:15:03 +0100
committerJakob Odersky <jodersky@gmail.com>2012-11-01 13:15:03 +0100
commit2228d91e7b7c9e258e669bad03a8c9919c850309 (patch)
tree5fb8f5f41c6a3315c611ff19f2d1e67c6357eff8
parent2dfddf1c5f8f43d32a1a60af4263f5b338c15bd0 (diff)
downloadscalam-2228d91e7b7c9e258e669bad03a8c9919c850309.tar.gz
scalam-2228d91e7b7c9e258e669bad03a8c9919c850309.tar.bz2
scalam-2228d91e7b7c9e258e669bad03a8c9919c850309.zip
documentation
-rw-r--r--src/main/scala/scalam/math/package.scala20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/scala/scalam/math/package.scala b/src/main/scala/scalam/math/package.scala
index 4121b8c..44e6876 100644
--- a/src/main/scala/scalam/math/package.scala
+++ b/src/main/scala/scalam/math/package.scala
@@ -1,10 +1,22 @@
package scalam
-import scala.collection.SeqLike
import scala.collection.generic.CanBuildFrom
+
+/** Contains useful math functions. */
package object math {
- def smooth[Elem, Coll[Elem]](width: Int, passes: Int, collection: Coll[Elem])(implicit fractional: Fractional[Elem], cbf: CanBuildFrom[Coll[Elem], Elem, Coll[Elem]], view: Coll[Elem] => Seq[Elem]): Coll[Elem] = {
+ /**
+ * Smooths a collection of numeric values using the moving-average algorithm.
+ * The algorithm takes a window of width `width` that "slides" along the whole collection.
+ * A new collection is created by taking the average of all points located in each window.
+ *
+ * @param collection the collection to smooth
+ * @param width the window's witdh
+ * @param passes how many times the collection is smoothed (i.e. how often smooth calls itself recursively)
+ * @tparam Elem the type of the elements contained in the collection
+ * @tparam Coll[Elem] the type of the collection to be smoothed
+ */
+ def smooth[Elem, Coll[Elem]](collection: Coll[Elem], width: Int, passes: Int = 1)(implicit fractional: Fractional[Elem], cbf: CanBuildFrom[Coll[Elem], Elem, Coll[Elem]], view: Coll[Elem] => Seq[Elem]): Coll[Elem] = {
def average(xs: Seq[Elem]): Elem = {
import fractional._
xs.sum / fromInt(xs.length)
@@ -14,8 +26,8 @@ package object math {
else {
val b = cbf(collection)
collection.sliding(width).foreach(neighbours => b += average(neighbours))
- smooth(width, passes - 1, b.result())
+ smooth(b.result(), width, passes - 1)
}
}
-
+
} \ No newline at end of file