Skip to content

Added example_ILITest11 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 52 additions & 43 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main/scala/scalation/modeling/forecasting/ARX.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ARX (x: MatrixD, y: VectorD, hh: Int, n_exo: Int, fname: Array [String],
tForms: TransformMap = Map ("tForm_y" -> null))
extends Forecaster_Reg (x, y, hh, fname, tRng, hparam, bakcast):

private val debug = debugf ("ARX", true) // debug function
private val debug = debugf ("ARX", false) // debug function
protected val p = hparam("p").toInt // use the last p endogenous values (p lags)
protected val q = hparam("q").toInt // use the last q exogenous values (q lags)
protected val spec = hparam("spec").toInt // trend terms: 0 - none, 1 - constant, 2 - linear, 3 - quadratic
Expand Down
107 changes: 105 additions & 2 deletions src/main/scala/scalation/modeling/forecasting/Example_ILI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ end example_ILITest9
*/
@main def example_ILITest10 (): Unit =

import AR.hp
import MakeMatrix4TS.hp

val exo_vars = Array ("%WEIGHTED ILI", "%UNWEIGHTED ILI")
val (xe, y) = loadData (exo_vars, response)
Expand All @@ -325,7 +325,6 @@ end example_ILITest9
val pp = 1.5
hp("p") = p // endo lags
hp("q") = q // exo lags
hp("pp") = pp // power to raise lags to
hp("spec") = 1 // trend specification: 0, 1, 2, 3, 5
hp("lwave") = 20 // wavelength (distance between peaks)
hp("cross") = 1
Expand Down Expand Up @@ -364,3 +363,107 @@ end example_ILITest9

end example_ILITest10

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
/** The `example_ILITest10` main function test the `Example_ILI` object.
* This test compares the several models for several values of p and q.
* > runMain scalation.modeling.forecasting.example_ILITest11
*/
@main def example_ILITest11 (): Unit =

import MakeMatrix4TS.hp

// val exo_vars = Array ("%WEIGHTED ILI", "%UNWEIGHTED ILI")
val exo_vars = Array("OT")

val (xe, y) = loadData (exo_vars, response)
println (s"xe.dims = ${xe.dims}, y.dim = ${y.dim}")

val hh = 6 // maximum forecasting horizon
val p = 6
val q = 6
hp("p") = p // endo lags
hp("q") = q // exo lags
hp("spec") = 1 // trend specification: 0, 1, 2, 3, 5
hp("lwave") = 20 // wavelength (distance between peaks)
hp("cross") = 0
hp("lambda") = 1.0


banner("RandomWalkS")
val mod1 = RandomWalkS(y, hh) // create model for time series data
banner(s"In-ST Forecasts: ${mod1.modelName} on ILI Dataset")
mod1.trainNtest()() // train and test on full dataset
mod1.forecastAll() // forecast h-steps ahead (h = 1 to hh) for all y
mod1.diagnoseAll(mod1.getY, mod1.getYf)

println("rollValidate")
mod1.setSkip(0)
mod1.rollValidate() // TnT with Rolling Validation
mod1.diagnoseAll(mod1.getY, mod1.getYf, Forecaster.teRng(y.dim), 0)


banner("AR")
val mod2 = AR(y, hh) // create model for time series data
banner(s"In-ST Forecasts: ${mod2.modelName} on ILI Dataset")
mod2.trainNtest()() // train and test on full dataset
mod2.forecastAll() // forecast h-steps ahead (h = 1 to hh) for all y
mod2.diagnoseAll(mod2.getY, mod2.getYf)

println("rollValidate")
mod2.setSkip(0)
mod2.rollValidate() // TnT with Rolling Validation
mod2.diagnoseAll(mod2.getY, mod2.getYf, Forecaster.teRng(y.dim), 0)


banner("ARX")
val mod3 = ARX(xe, y, hh) // create model for time series data
banner(s"In-ST Forecasts: ${mod3.modelName} on ILI Dataset")
mod3.trainNtest_x()() // train and test on full dataset
mod3.forecastAll() // forecast h-steps ahead (h = 1 to hh) for all y
mod3.diagnoseAll(mod3.getY, mod3.getYf)

println("rollValidate")
mod3.setSkip(0)
mod3.rollValidate() // TnT with Rolling Validation
mod3.diagnoseAll(mod3.getY, mod3.getYf, Forecaster.teRng(y.dim), 0)


banner("ARX_D")
val mod4 = ARX_D(xe, y, hh) // create model for time series data
banner(s"In-ST Forecasts: ${mod4.modelName} on ILI Dataset")
mod4.trainNtest_x()() // train and test on full dataset
mod4.forecastAll() // forecast h-steps ahead (h = 1 to hh) for all y
mod4.diagnoseAll(mod4.getY, mod4.getYf)

println("rollValidate")
mod4.setSkip(0)
mod4.rollValidate() // TnT with Rolling Validation
mod4.diagnoseAll(mod4.getY, mod4.getYf, Forecaster.teRng(y.dim), 0)


banner("ARX_Quad")
val mod5 = ARX_Quad(xe, y, hh) // create model for time series data
banner(s"In-ST Forecasts: ${mod5.modelName} on ILI Dataset")
mod5.trainNtest_x()() // train and test on full dataset
mod5.forecastAll() // forecast h-steps ahead (h = 1 to hh) for all y
mod5.diagnoseAll(mod5.getY, mod5.getYf)

println("rollValidate")
mod5.setSkip(0)
mod5.rollValidate() // TnT with Rolling Validation
mod5.diagnoseAll(mod5.getY, mod5.getYf, Forecaster.teRng(y.dim), 0)


banner("ARX_Quad_D")
val mod6 = ARX_Quad_D(xe, y, hh) // create model for time series data
banner(s"In-ST Forecasts: ${mod6.modelName} on ILI Dataset")
mod6.trainNtest_x()() // train and test on full dataset
mod6.forecastAll() // forecast h-steps ahead (h = 1 to hh) for all y
mod6.diagnoseAll(mod6.getY, mod6.getYf)

println("rollValidate")
mod6.setSkip(0)
mod6.rollValidate() // TnT with Rolling Validation
mod6.diagnoseAll(mod6.getY, mod6.getYf, Forecaster.teRng(y.dim), 0)

end example_ILITest11
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class Forecaster_Reg (x: MatrixD, y: VectorD, hh: Int, fname: Array [St
extends Forecaster (y, hh, tRng, hparam, bakcast)
with FeatureSelection:

private val debug = debugf ("Forecaster_Reg", true) // debug function
private val debug = debugf ("Forecaster_Reg", false) // debug function
private val flaw = flawf ("Forecaster_Reg") // debug function
protected val reg = new REGRESSION (x, y, fname, hparam) // delegate training to regression
protected val nneg = hparam("nneg").toInt == 1 // 0 => unrestricted, 1 => predictions must be non-negative
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.