//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** @author John Miller * @version 1.6 * @date Tue Jun 11 14:41:25 EDT 2019 * @see LICENSE (MIT style license file). * * @title Test: Differencing Functions in `forecaster` Package Object */ package scalation.analytics package forecaster import scalation.linalgebra.VectorD import scalation.random.RandomVecD import scalation.util.banner //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DiffTest` is used to test the 'diff' and 'diffinv' differencing functions * in the `forecaster` package object using 'square (k)'. * > runMain scalation.analytics.forecaster.DiffTest */ object DiffTest extends App { val y = VectorD (1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169) // vector of squares val z = RandomVecD (13).gen.asInstanceOf [VectorD] // random vector println (s"y = $y") println (s"z = $z") banner ("Test the 'diff' method") val y1 = y.copy () val z1 = z.copy () diff (y1) diff (z1) println (s"y1 = $y1") println (s"z1 = $z1") val y2 = y.copy () val z2 = z.copy () diff (y2, 2) diff (z2, 2) println (s"y2 = $y2") println (s"z2 = $z2") val y3 = y.copy () val z3 = z.copy () diff (y3, 3) diff (z3, 3) println (s"y3 = $y3") println (s"z3 = $z3") banner ("Test the 'diffinv' method") diffinv (y1) diffinv (z1) println (s"y1 = $y1") println (s"z1 = $z1") assert (y1 == y) assert (z1 == z) diffinv (y2, 2) diffinv (z2, 2) println (s"y2 = $y2") println (s"z2 = $z2") assert (y2 == y) assert (z2 == z) diffinv (y3, 3) diffinv (z3, 3) println (s"y3 = $y3") println (s"z3 = $z3") assert (y3 == y) assert (z3 == z) } // DiffTest object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DiffTest2` is used to test the 'diff' and 'diffinv' differencing functions * in the `forecaster` package object using Fibonacci Numbers 'fib(k)'. * > runMain scalation.analytics.forecaster.DiffTest2 */ object DiffTest2 extends App { val y = VectorD (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233) // vector of fib println (s"y = $y") banner ("Test the 'diff' method") val y1 = y.copy () diff (y1) println (s"y1 = $y1") val y2 = y.copy () diff (y2, 2) println (s"y2 = $y2") val y3 = y.copy () diff (y3, 3) println (s"y3 = $y3") banner ("Test the 'diffinv' method") diffinv (y1) println (s"y1 = $y1") assert (y1 == y) diffinv (y2, 2) println (s"y2 = $y2") assert (y2 == y) diffinv (y3, 3) println (s"y3 = $y3") assert (y3 == y) } // DiffTest2 object //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `DiffTest3` is used to test the 'sdiff' and 'sdiffinv' seasonal differencing * functions in the 'forecaster' package object using 'square (k)'. * > runMain scalation.analytics.forecaster.DiffTest3 */ object DiffTest3 extends App { val y = VectorD (1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169) val s = 2 println (s"y = $y") banner ("Test the 'sdiff' method") val y1 = y.copy () sdiff (y1, s) println (s"y1 = $y1") val y2 = y.copy () sdiff (y2, 2, s) println (s"y2 = $y2") val y3 = y.copy () sdiff (y3, 3, s) println (s"y3 = $y3") banner ("Test the 'sdiffinv' method") sdiffinv (y1, s) println (s"y1 = $y1") assert (y1 == y) sdiffinv (y2, 2, s) println (s"y2 = $y2") assert (y1 == y) sdiffinv (y3, 3, s) println (s"y3 = $y3") assert (y1 == y) } // DiffTest3 object