In [1]:
import breeze.linalg._
import breeze.stats.distributions._
import io.github.mandar2812.dynaml.pipes._
import io.github.mandar2812.dynaml.kernels._
import io.github.mandar2812.dynaml.models.bayes.{
    LinearTrendESGPrior,
    LinearTrendGaussianPrior,
    GaussianProcessPrior
}
import io.github.mandar2812.dynaml.modelpipe._
import io.github.mandar2812.dynaml.probability._
import io.github.mandar2812.dynaml.DynaMLPipe._
import io.github.mandar2812.dynaml.graphics.charts.Highcharts._
import io.github.mandar2812.dynaml.analysis.implicits._
import io.github.mandar2812.dynaml.optimization.GPMixtureMachine
import io.github.mandar2812.dynaml.pipes.Encoder
import io.github.mandar2812.dynaml.probability.distributions.UnivariateGaussian
import io.github.mandar2812.dynaml.analysis._
import io.github.mandar2812.dynaml.analysis.implicits._
import spire.implicits._
import io.github.mandar2812.dynaml.graphics.charts.Highcharts._
import io.github.mandar2812.dynaml.tensorflow.dtfdata


Out[1]:
import breeze.linalg._

import breeze.stats.distributions._

import io.github.mandar2812.dynaml.pipes._

import io.github.mandar2812.dynaml.kernels._

import io.github.mandar2812.dynaml.models.bayes.{
    LinearTrendESGPrior,
    LinearTrendGaussianPrior,
    GaussianProcessPrior
}

import io.github.mandar2812.dynaml.modelpipe._

import io.github.mandar2812.dynaml.probability._

import io.github.mandar2812.dynaml.DynaMLPipe._

import io.github.mandar2812.dynaml.graphics.charts.Highcharts._

import io.github.mandar2812.dynaml.analysis.implicits._

import io.github.mandar2812.dynaml.optimization.GPMixtureMachine

import io.github.mandar2812.dynaml.pipes.Encoder

import io.github.mandar2812.dynaml.probability.distributions.UnivariateGaussian

import io.github.mandar2812.dynaml.analysis._

import io.github.mandar2812.dynaml.analysis.implicits._

import spire.implicits._

import io.github.mandar2812.dynaml.graphics.charts.Highcharts._

import io.github.mandar2812.dynaml.tensorflow.dtfdata

In [2]:
//For p order auto-regressive dynamics
  val p                = 3
  val num_sample_paths = 10
  //Simulation time of the time series models.
  val len = 100

  val xs = Seq.tabulate[Double](len)(1d * _)

  implicit val ev = VectorField(p * (p + 1))

  val y0 = RandomVariable(UnivariateGaussian(0.0, 1.0))

  val urv = UniformRV(-1.0, 1.0)

  val coeff_gen =
    (order: Int) =>
      MultGaussianRV(
        DenseVector.tabulate[Double](order * (order + 1))(
          i => if (i == 0) 0d else -0.01d
        ),
        diag(
          DenseVector.tabulate[Double](order * (order + 1))(
            i =>
              if (i < order) 0.01d
              else 0.001
          )
        )
      )

  val w_prior = coeff_gen(p)

  //Draw the AR(p) coefficients from the prior distribution w_prior
  val w = w_prior.draw


Apr 28, 2020 3:19:37 PM com.github.fommil.jni.JniLoader liberalLoad
INFO: successfully loaded /tmp/jniloader6702601265569287600netlib-native_system-linux-x86_64.so
Apr 28, 2020 3:19:37 PM com.github.fommil.jni.JniLoader load
INFO: already loaded netlib-native_system-linux-x86_64.so
Out[2]:
p: Int = 3
num_sample_paths: Int = 10
len: Int = 100
xs: Seq[Double] = List(
  0.0,
  1.0,
  2.0,
  3.0,
  4.0,
  5.0,
  6.0,
  7.0,
  8.0,
  9.0,
  10.0,
  11.0,
  12.0,
  13.0,
  14.0,
  15.0,
  16.0,
  17.0,
  18.0,
  19.0,
  20.0,
  21.0,
  22.0,
  23.0,
  24.0,
  25.0,
  26.0,
  27.0,
  28.0,
  29.0,
  30.0,
  31.0,
  32.0,
  33.0,
  34.0,
  35.0,
  36.0,
  37.0,
...
ev: VectorField = io.github.mandar2812.dynaml.analysis.VectorField@61820694
y0: ContinuousRVWithDistr[Double, ContinuousDistr[Double]] = io.github.mandar2812.dynaml.probability.RandomVariable$$anon$19@50553f33
urv: UniformRV = UniformRV(-1.0, 1.0)
coeff_gen: Int => MultGaussianRV = ammonite.$sess.cmd1$Helper$$Lambda$2109/1623719933@6765ffb1
w_prior: MultGaussianRV = MultGaussianRV(
  DenseVector(0.0, -0.01, -0.01, -0.01, -0.01, -0.01, -0.01, -0.01, -0.01, -0.01, -0.01, -0.01),
  0.01  0.0   0.0   0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    
0.0   0.01  0.0   0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    
0.0   0.0   0.01  0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    
0.0   0.0   0.0   0.001  0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    
0.0   0.0   0.0   0.0    0.001  0.0    0.0    0.0    0.0    0.0    0.0    0.0    
0.0   0.0   0.0   0.0    0.0    0.001  0.0    0.0    0.0    0.0    0.0    0.0    
0.0   0.0   0.0   0.0    0.0    0.0    0.001  0.0    0.0    0.0    0.0    0.0    
0.0   0.0   0.0   0.0    0.0    0.0    0.0    0.001  0.0    0.0    0.0    0.0    
0.0   0.0   0.0   0.0    0.0    0.0    0.0    0.0    0.001  0.0    0.0    0.0    
0.0   0.0   0.0   0.0    0.0    0.0    0.0    0.0    0.0    0.001  0.0    0.0    
0.0   0.0   0.0   0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.001  0.0    
0.0   0.0   0.0   0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.0    0.001  
)
w: DenseVector[Double] = DenseVector(0.15409306956021254, 0.06674858045795375, -0.035887550444526246, -0.01507775179178111, -0.040164881931504456, -0.0025290703011450737, -0.0021662875876474353, 0.005649865173463149, -0.02108229516145496, 0.006536905438604005, -0.03460080942252051, -0.011344317621617247)

In [3]:
//Define some kernels for use later.
  val rbfc      = new SEKernel(1d, 2.0)
  val mlpKernel = new MLPKernel(1d, 0.5d)
  val fbm       = new FBMCovFunction(0.5)
  val stKernel  = new TStudentKernel(0.5)

  val perKernel = new PeriodicCovFunc(2d, 1.5d, 0.1d)
  val arpKernel = new GenericMaternKernel[Double](2.5, p)
  val n         = new MAKernel(1.0)
  val noise     = new DiracKernel(0.5d)

  val gsmKernel = GaussianSpectralKernel(
    DenseVector.zeros[Double](p),
    DenseVector.ones[Double](p),
    GaussianSpectralKernel.getEncoderforBreezeDV(p)
  )


Out[3]:
rbfc: SEKernel = io.github.mandar2812.dynaml.kernels.SEKernel@3d9b6fac
mlpKernel: MLPKernel = io.github.mandar2812.dynaml.kernels.MLPKernel@e79c6f0
fbm: FBMCovFunction = io.github.mandar2812.dynaml.kernels.FBMCovFunction@12f19590
stKernel: TStudentKernel = io.github.mandar2812.dynaml.kernels.TStudentKernel@2e739e54
perKernel: PeriodicCovFunc = io.github.mandar2812.dynaml.kernels.PeriodicCovFunc@34b96543
arpKernel: GenericMaternKernel[Double] = io.github.mandar2812.dynaml.kernels.GenericMaternKernel@535f111d
n: MAKernel = io.github.mandar2812.dynaml.kernels.MAKernel@5dddc50a
noise: DiracKernel = io.github.mandar2812.dynaml.kernels.DiracKernel@2a6ba5b4
gsmKernel: GaussianSpectralKernel[DenseVector[Double]] = io.github.mandar2812.dynaml.kernels.GaussianSpectralKernel@19616a98

In [4]:
val linear_coeff    = (0d, 0d)
  val quadratic_coeff = (-0.01d, -0.75d, 0d)

  //Define the trend functions. One a linear trend
  //and the other a parabola.

  val linear_vec_trend = MetaPipe(
    (p: DenseVector[Double]) =>
      (x: DenseVector[Double]) => {
        p dot x
      }
  )

  val basis_func_mapping = DataPipe(
    (x: DenseVector[Double]) =>
      (x * DenseVector.vertcat(DenseVector(1d), x).t).toDenseVector
  )

  val quadratic_vec_trend = MetaPipe(
    (p: DenseVector[Double]) =>
      (x: DenseVector[Double]) => {
        p dot basis_func_mapping(x)
      }
  )

  val linear_trend_mean = MetaPipe(
    (p: (Double, Double)) =>
      (x: Double) => {
        (p._1 * x) + p._2
      }
  )

  val quadratic_trend_mean = MetaPipe(
    (p: (Double, Double, Double)) =>
      (x: Double) => {
        (p._1 * x * x) + (p._2 * x) + p._3
      }
  )

  //Determine how the trend coefficients map to key-value pairs
  val linear_trend_encoder = Encoder(
    (cs: (Double, Double)) => Map("slope" -> cs._1, "intercept" -> cs._2),
    (conf: Map[String, Double]) => (conf("slope"), conf("intercept"))
  )

  val linear_vec_trend_encoder = Encoder(
    (cs: DenseVector[Double]) => {
      cs.toArray.zipWithIndex.map(cp => (s"w_${cp._2}", cp._1)).toMap
    },
    (conf: Map[String, Double]) =>
      DenseVector(conf.toSeq.sortBy(_._1).map(_._2).toArray)
  )

  val quadratic_trend_encoder = Encoder(
    (cs: (Double, Double, Double)) =>
      Map("a" -> cs._1, "b" -> cs._2, "d" -> cs._3),
    (conf: Map[String, Double]) => (conf("a"), conf("b"), conf("d"))
  )


Out[4]:
linear_coeff: (Double, Double) = (0.0, 0.0)
quadratic_coeff: (Double, Double, Double) = (-0.01, -0.75, 0.0)
linear_vec_trend: MetaPipe[DenseVector[Double], DenseVector[Double], Double] = io.github.mandar2812.dynaml.pipes.MetaPipe$$anon$2@1ee7bc89
basis_func_mapping: DataPipe[DenseVector[Double], DenseVector[Double]] = io.github.mandar2812.dynaml.pipes.DataPipe$$anon$2@160a649c
quadratic_vec_trend: MetaPipe[DenseVector[Double], DenseVector[Double], Double] = io.github.mandar2812.dynaml.pipes.MetaPipe$$anon$2@6e8a25cc
linear_trend_mean: MetaPipe[(Double, Double), Double, Double] = io.github.mandar2812.dynaml.pipes.MetaPipe$$anon$2@63da6fa6
quadratic_trend_mean: MetaPipe[(Double, Double, Double), Double, Double] = io.github.mandar2812.dynaml.pipes.MetaPipe$$anon$2@3bcf29e7
linear_trend_encoder: Encoder[(Double, Double), Map[String, Double]] = io.github.mandar2812.dynaml.pipes.Encoder$$anon$1@20fd73b2
linear_vec_trend_encoder: Encoder[DenseVector[Double], Map[String, Double]] = io.github.mandar2812.dynaml.pipes.Encoder$$anon$1@b0039e3
quadratic_trend_encoder: Encoder[(Double, Double, Double), Map[String, Double]] = io.github.mandar2812.dynaml.pipes.Encoder$$anon$1@579766d4

In [5]:
//Define a Matern(p + 1/2) covariance based gaussian process
  val gp_explicit = GaussianProcessPrior[Double, (Double, Double)](
    arpKernel,
    new MAKernel(0.5d),
    linear_trend_mean,
    linear_trend_encoder,
    linear_coeff
  )

  //Define a gaussian process for GP Time Series models.
  val gp_prior = GaussianProcessPrior[DenseVector[Double], DenseVector[Double]](
    rbfc,
    noise,
    linear_vec_trend,
    linear_vec_trend_encoder,
    w(0 until p)
  )

  val gpModelPipe =
    new GPBasisFuncRegressionPipe[Seq[(DenseVector[Double], Double)], DenseVector[
      Double
    ]](
      identityPipe[Seq[(DenseVector[Double], Double)]],
      rbfc,
      noise,
      identityPipe[DenseVector[Double]],
      w_prior(0 until p)
    )


Out[5]:
gp_explicit: GaussianProcessPrior[Double, (Double, Double)] = io.github.mandar2812.dynaml.models.bayes.GaussianProcessPrior$$anon$1@c0bb52e
gp_prior: GaussianProcessPrior[DenseVector[Double], DenseVector[Double]] = io.github.mandar2812.dynaml.models.bayes.GaussianProcessPrior$$anon$1@189f373b
gpModelPipe: GPBasisFuncRegressionPipe[Seq[(DenseVector[Double], Double)], DenseVector[Double]] = io.github.mandar2812.dynaml.modelpipe.GPBasisFuncRegressionPipe@c12cd89

In [6]:
val y_explicit: MultGaussianPRV = gp_explicit.priorDistribution(xs)

  //Generate samples for GP process on explicit time. Matern(p + 1/2)
  val samples_gp_explicit =
    y_explicit.iid(10).draw.map(s => s.toBreezeVector.toArray.toSeq).toSeq

  //Generate samples for GP-NAR process in a recursive manner
  val ys_ar_rec = RandomVariable[Seq[Double]](() => {
    // Generate y0 and y1
    val u0: DenseVector[Double] = DenseVector.tabulate(p)(_ => y0.draw)
    val u1: Double              = gp_prior.priorDistribution(Seq(u0)).draw.toStream.head
    val d                       = Seq((u0, u1))
    val (_, xsamples) =
      (1 to xs.length - p - 1)
        .scanLeft((d, DenseVector(Array(u1) ++ u0(0 to -2).toArray)))(
          (dc, _) => {

            val (data, x) = dc
            val gpModel   = gpModelPipe(data)
            val y         = gpModel.predictiveDistribution(Seq(x)).draw.toStream.head
            (data :+ (x, y), DenseVector(Array(y) ++ x(0 to -2).toArray))
          }
        )
        .unzip

    u0.toArray.toSeq ++ xsamples.map(_(0))
  })

  //Generate samples from a conventional AR(p) process
  //with coefficients given by w
  val markov_process = (n: Int) =>
    RandomVariable[Seq[Double]](() => {
      val u0 = DenseVector.tabulate(p)(_ => y0.draw)
      val xs_tail = (1 to n - p - 1)
        .scanLeft(
          u0
        )((y: DenseVector[Double], _) => {
          val y_new: Double = quadratic_vec_trend(w)(y) + y0.draw
          DenseVector(Array(y_new) ++ y(0 to -2).toArray)
        })
        .toSeq
        .map(_(0))

      u0.toArray.toSeq ++ xs_tail
    })

  val samples_ar_rec = ys_ar_rec.iid(10).draw.toSeq

  val samples_markov = markov_process(xs.length).iid(10).draw.toSeq


Out[6]:
y_explicit: MultGaussianPRV = MultGaussianPRV(
  io.github.mandar2812.dynaml.algebra.PartitionedVector@4bc0f48c,
  io.github.mandar2812.dynaml.algebra.PartitionedPSDMatrix@7c5c70fe
)
samples_gp_explicit: collection.immutable.Seq[Seq[Double]] = Stream(
  WrappedArray(
    0.1629444962719716,
    0.8241632177493847,
    -0.47015250748219467,
    0.7467483514359702,
    1.1374129903633636,
    0.9786814092389757,
    0.0657343046793386,
    -1.6207913298155512,
    -1.2795169592901643,
    -2.469232063180355,
    -0.6403631504769587,
    -1.0383734333106216,
    -0.32622104805137986,
    -1.2073837234085956,
    -0.27412266956447773,
    -0.2566966954773496,
    -0.16327764900854816,
    -1.9235383238618664,
    -0.7309674942239188,
    0.7764204472892756,
    1.445819442664622,
    1.7305920226878018,
    3.387817607036443,
    1.746628718714702,
    0.44205878317120817,
    -1.1943739368366753,
    0.04007530327206499,
    -0.014463434293722377,
    -2.2204757370160793,
    -1.8992006529978385,
    -2.1941042202170746,
    0.6524823735934546,
    0.627918491692513,
    1.0574905382589046,
    0.436839587450802,
    0.7866094063194313,
    0.6037023130585367,
...
ys_ar_rec: RandomVariable[Seq[Double]] = io.github.mandar2812.dynaml.probability.RandomVariable$$anon$17@2df873c5
markov_process: Int => RandomVariable[Seq[Double]] = ammonite.$sess.cmd5$Helper$$Lambda$2685/2064091285@25f0ac8
samples_ar_rec: collection.immutable.Seq[Seq[Double]] = Stream(
  ArrayBuffer(
    -0.03696523048064158,
    -2.1256426418954573,
    0.2820103177178188,
    3.6629781276471918,
    -5.6335881990476695,
    -0.7793385520503001,
    3.2599185228928134,
    -1.5850260112447843,
    -1.1622922027222424,
    1.3932119206844524,
    -0.8487122648638695,
    -0.37557642077681663,
    4.026765547345398,
    -0.36983486724607273,
    0.17440222703465758,
    0.7842236092776063,
    -0.48100135700671187,
    -2.6742096302516645,
    -1.5109738975157847,
    -3.0109757078817183,
    1.1770643432686392,
    2.1910775139485392,
    -1.4868175785260092,
    -1.2644994625265626,
    4.107631238269208,
    2.120423606294751,
    -0.6500544463745567,
    -0.9325191282319775,
    3.3825604054671,
    0.9516848676736149,
    0.22396974649693008,
    2.347170700705393,
    -0.35687609322275693,
    0.2909794111237789,
    1.2463137452367112,
    -0.197156612309703,
    -2.369683384202487,
...
samples_markov: collection.immutable.Seq[Seq[Double]] = Stream(
  ArrayBuffer(
    2.0661407541404424,
    -0.20279635893745562,
    2.0118829440923975,
    2.0661407541404424,
    -0.7668105130011957,
    -0.5506978934362262,
    0.3259708389782872,
    0.7550958981227435,
    0.24667640048362177,
    0.36204346569998375,
    0.5915722688138524,
    0.6932176202171723,
    0.7861619749847729,
    0.6823027547053315,
    1.5148898666329573,
    -1.7103351094654018,
    -0.3261593937461385,
    -1.7700909245481486,
    0.20082466165254687,
    -1.9933270130562681,
    -1.926345691383111,
    1.8459166290160602,
    -1.218740489452355,
    0.28459635602781436,
    0.7166564133035342,
    -1.5076764366708415,
    0.23340051122886576,
    -1.8071980087295354,
    -1.852702605304878,
    -2.588991017869229,
    -0.2263352172924218,
    0.36731003883770413,
    -0.078109602362965,
    -0.7034250593297158,
    0.10847474421188891,
    1.416662630232223,
    -1.4437411886548073,
...

In [7]:
deleteAll()
val plot_legend_labels =
    (1 to num_sample_paths).map(i => s"Path $i").toSeq

spline(xs, samples_gp_explicit.head)
hold()
samples_gp_explicit.tail.foreach((s: Seq[Double]) => spline(xs, s))
unhold()
title(
    s"""GP Explicit Time AR($p): ${gp_explicit.covariance.toString
      .split("\\.")
      .last}"""
)
legend(plot_legend_labels)


serving resources from: file:/home/mandar/Development/examples/notebooks/index-1588080017394.html
SLF4J: Class path contains multiple SLF4J providers.
SLF4J: Found provider [org.slf4j.log4j12.Log4j12ServiceProvider@6b0abeff]
SLF4J: Found provider [org.slf4j.helpers.NOPServiceProvider@59e4c690]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual provider is of type [org.slf4j.log4j12.Log4j12ServiceProvider@6b0abeff]
Server started: http://tail-box:42715/index-1588080017394.html
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Out[7]:
plot_legend_labels: collection.immutable.Seq[String] = Vector(
  "Path 1",
  "Path 2",
  "Path 3",
  "Path 4",
  "Path 5",
  "Path 6",
  "Path 7",
  "Path 8",
  "Path 9",
  "Path 10"
)
res6_2: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 0.1629444962719716, None, None),
        DataPair(1.0, 0.8241632177493847, None, None),
        DataPair(2.0, -0.47015250748219467, None, None),
        DataPair(3.0, 0.7467483514359702, None, None),
        DataPair(4.0, 1.1374129903633636, None, None),
        DataPair(5.0, 0.9786814092389757, None, None),
        DataPair(6.0, 0.0657343046793386, None, None),
        DataPair(7.0, -1.6207913298155512, None, None),
        DataPair(8.0, -1.2795169592901643, None, None),
        DataPair(9.0, -2.469232063180355, None, None),
        DataPair(10.0, -0.6403631504769587, None, None),
        DataPair(11.0, -1.0383734333106216, None, None),
        DataPair(12.0, -0.32622104805137986, None, None),
        DataPair(13.0, -1.2073837234085956, None, None),
        DataPair(14.0, -0.27412266956447773, None, None),
        DataPair(15.0, -0.2566966954773496, None, None),
        DataPair(16.0, -0.16327764900854816, None, None),
        DataPair(17.0, -1.9235383238618664, None, None),
        DataPair(18.0, -0.7309674942239188, None, None),
        DataPair(19.0, 0.7764204472892756, None, None),
        DataPair(20.0, 1.445819442664622, None, None),
        DataPair(21.0, 1.7305920226878018, None, None),
        DataPair(22.0, 3.387817607036443, None, None),
        DataPair(23.0, 1.746628718714702, None, None),
        DataPair(24.0, 0.44205878317120817, None, None),
        DataPair(25.0, -1.1943739368366753, None, None),
        DataPair(26.0, 0.04007530327206499, None, None),
        DataPair(27.0, -0.014463434293722377, None, None),
        DataPair(28.0, -2.2204757370160793, None, None),
        DataPair(29.0, -1.8992006529978385, None, None),
        DataPair(30.0, -2.1941042202170746, None, None),
        DataPair(31.0, 0.6524823735934546, None, None),
        DataPair(32.0, 0.627918491692513, None, None),
        DataPair(33.0, 1.0574905382589046, None, None),
        DataPair(34.0, 0.436839587450802, None, None),
...
res6_6: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 0.1629444962719716, None, None),
        DataPair(1.0, 0.8241632177493847, None, None),
        DataPair(2.0, -0.47015250748219467, None, None),
        DataPair(3.0, 0.7467483514359702, None, None),
        DataPair(4.0, 1.1374129903633636, None, None),
        DataPair(5.0, 0.9786814092389757, None, None),
        DataPair(6.0, 0.0657343046793386, None, None),
        DataPair(7.0, -1.6207913298155512, None, None),
        DataPair(8.0, -1.2795169592901643, None, None),
        DataPair(9.0, -2.469232063180355, None, None),
        DataPair(10.0, -0.6403631504769587, None, None),
        DataPair(11.0, -1.0383734333106216, None, None),
        DataPair(12.0, -0.32622104805137986, None, None),
        DataPair(13.0, -1.2073837234085956, None, None),
        DataPair(14.0, -0.27412266956447773, None, None),
        DataPair(15.0, -0.2566966954773496, None, None),
        DataPair(16.0, -0.16327764900854816, None, None),
        DataPair(17.0, -1.9235383238618664, None, None),
        DataPair(18.0, -0.7309674942239188, None, None),
        DataPair(19.0, 0.7764204472892756, None, None),
        DataPair(20.0, 1.445819442664622, None, None),
        DataPair(21.0, 1.7305920226878018, None, None),
        DataPair(22.0, 3.387817607036443, None, None),
        DataPair(23.0, 1.746628718714702, None, None),
        DataPair(24.0, 0.44205878317120817, None, None),
        DataPair(25.0, -1.1943739368366753, None, None),
        DataPair(26.0, 0.04007530327206499, None, None),
        DataPair(27.0, -0.014463434293722377, None, None),
        DataPair(28.0, -2.2204757370160793, None, None),
        DataPair(29.0, -1.8992006529978385, None, None),
        DataPair(30.0, -2.1941042202170746, None, None),
        DataPair(31.0, 0.6524823735934546, None, None),
        DataPair(32.0, 0.627918491692513, None, None),
        DataPair(33.0, 1.0574905382589046, None, None),
        DataPair(34.0, 0.436839587450802, None, None),
...
res6_7: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 0.1629444962719716, None, None),
        DataPair(1.0, 0.8241632177493847, None, None),
        DataPair(2.0, -0.47015250748219467, None, None),
        DataPair(3.0, 0.7467483514359702, None, None),
        DataPair(4.0, 1.1374129903633636, None, None),
        DataPair(5.0, 0.9786814092389757, None, None),
        DataPair(6.0, 0.0657343046793386, None, None),
        DataPair(7.0, -1.6207913298155512, None, None),
        DataPair(8.0, -1.2795169592901643, None, None),
        DataPair(9.0, -2.469232063180355, None, None),
        DataPair(10.0, -0.6403631504769587, None, None),
        DataPair(11.0, -1.0383734333106216, None, None),
        DataPair(12.0, -0.32622104805137986, None, None),
        DataPair(13.0, -1.2073837234085956, None, None),
        DataPair(14.0, -0.27412266956447773, None, None),
        DataPair(15.0, -0.2566966954773496, None, None),
        DataPair(16.0, -0.16327764900854816, None, None),
        DataPair(17.0, -1.9235383238618664, None, None),
        DataPair(18.0, -0.7309674942239188, None, None),
        DataPair(19.0, 0.7764204472892756, None, None),
        DataPair(20.0, 1.445819442664622, None, None),
        DataPair(21.0, 1.7305920226878018, None, None),
        DataPair(22.0, 3.387817607036443, None, None),
        DataPair(23.0, 1.746628718714702, None, None),
        DataPair(24.0, 0.44205878317120817, None, None),
        DataPair(25.0, -1.1943739368366753, None, None),
        DataPair(26.0, 0.04007530327206499, None, None),
        DataPair(27.0, -0.014463434293722377, None, None),
        DataPair(28.0, -2.2204757370160793, None, None),
        DataPair(29.0, -1.8992006529978385, None, None),
        DataPair(30.0, -2.1941042202170746, None, None),
        DataPair(31.0, 0.6524823735934546, None, None),
        DataPair(32.0, 0.627918491692513, None, None),
        DataPair(33.0, 1.0574905382589046, None, None),
        DataPair(34.0, 0.436839587450802, None, None),
...

In [8]:
val tuple_encoder =
    TupleIntegerEncoder(List(p, p + 1))

val markov_formula = w.toArray.toSeq
    .zipWithIndex
    .map(
        cp => {
            val indices = tuple_encoder.i(cp._2)

            if (cp._2 < p) {
              if (cp._1 >= 0d && cp._2 != 0) f"+${cp._1}%3.2f*y(t-${cp._2 + 1})"
              else f"${cp._1}%3.2f*y(t-${cp._2 + 1})"
            } else if (cp._1 >= 0d)
            f"+${cp._1}%3.2f*y(t-${indices.head + 1})*y(t-${indices.last})"
            else f"${cp._1}%3.2f*y(t-${indices.head + 1})*y(t-${indices.last})"
        }
    )
    .reduceLeft(_ ++ _)

spline(xs, samples_markov.head)
hold()
samples_markov.tail.foreach((s: Seq[Double]) => spline(xs, s))
unhold()
title(
    s"""AR($p): y(t) = ${markov_formula} + noise"""
)
legend(plot_legend_labels)

spline(xs, samples_ar_rec.head)
hold()
samples_ar_rec.tail.foreach((s: Seq[Double]) => spline(xs, s))
unhold()
title(
    s"""GP-AR Recurrent: ${gpModelPipe.covariance.toString.split("\\.").last}"""
)
legend(plot_legend_labels)

println(s"Linear coefficients: ${w.toArray.toSeq}")


Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Linear coefficients: WrappedArray(0.15409306956021254, 0.06674858045795375, -0.035887550444526246, -0.01507775179178111, -0.040164881931504456, -0.0025290703011450737, -0.0021662875876474353, 0.005649865173463149, -0.02108229516145496, 0.006536905438604005, -0.03460080942252051, -0.011344317621617247)
Out[8]:
tuple_encoder: TupleIntegerEncoder = TupleIntegerEncoder(List(3, 4))
markov_formula: String = "0.15*y(t-1)+0.07*y(t-2)-0.04*y(t-3)-0.02*y(t-1)*y(t-1)-0.04*y(t-2)*y(t-1)-0.00*y(t-3)*y(t-1)-0.00*y(t-1)*y(t-2)+0.01*y(t-2)*y(t-2)-0.02*y(t-3)*y(t-2)+0.01*y(t-1)*y(t-3)-0.03*y(t-2)*y(t-3)-0.01*y(t-3)*y(t-3)"
res7_2: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res7_6: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res7_7: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res7_8: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, -0.03696523048064158, None, None),
        DataPair(1.0, -2.1256426418954573, None, None),
        DataPair(2.0, 0.2820103177178188, None, None),
        DataPair(3.0, 3.6629781276471918, None, None),
        DataPair(4.0, -5.6335881990476695, None, None),
        DataPair(5.0, -0.7793385520503001, None, None),
        DataPair(6.0, 3.2599185228928134, None, None),
        DataPair(7.0, -1.5850260112447843, None, None),
        DataPair(8.0, -1.1622922027222424, None, None),
        DataPair(9.0, 1.3932119206844524, None, None),
        DataPair(10.0, -0.8487122648638695, None, None),
        DataPair(11.0, -0.37557642077681663, None, None),
        DataPair(12.0, 4.026765547345398, None, None),
        DataPair(13.0, -0.36983486724607273, None, None),
        DataPair(14.0, 0.17440222703465758, None, None),
        DataPair(15.0, 0.7842236092776063, None, None),
        DataPair(16.0, -0.48100135700671187, None, None),
        DataPair(17.0, -2.6742096302516645, None, None),
        DataPair(18.0, -1.5109738975157847, None, None),
        DataPair(19.0, -3.0109757078817183, None, None),
        DataPair(20.0, 1.1770643432686392, None, None),
        DataPair(21.0, 2.1910775139485392, None, None),
        DataPair(22.0, -1.4868175785260092, None, None),
        DataPair(23.0, -1.2644994625265626, None, None),
        DataPair(24.0, 4.107631238269208, None, None),
        DataPair(25.0, 2.120423606294751, None, None),
        DataPair(26.0, -0.6500544463745567, None, None),
        DataPair(27.0, -0.9325191282319775, None, None),
        DataPair(28.0, 3.3825604054671, None, None),
        DataPair(29.0, 0.9516848676736149, None, None),
        DataPair(30.0, 0.22396974649693008, None, None),
        DataPair(31.0, 2.347170700705393, None, None),
        DataPair(32.0, -0.35687609322275693, None, None),
        DataPair(33.0, 0.2909794111237789, None, None),
        DataPair(34.0, 1.2463137452367112, None, None),
...
res7_12: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, -0.03696523048064158, None, None),
        DataPair(1.0, -2.1256426418954573, None, None),
        DataPair(2.0, 0.2820103177178188, None, None),
        DataPair(3.0, 3.6629781276471918, None, None),
        DataPair(4.0, -5.6335881990476695, None, None),
        DataPair(5.0, -0.7793385520503001, None, None),
        DataPair(6.0, 3.2599185228928134, None, None),
        DataPair(7.0, -1.5850260112447843, None, None),
        DataPair(8.0, -1.1622922027222424, None, None),
        DataPair(9.0, 1.3932119206844524, None, None),
        DataPair(10.0, -0.8487122648638695, None, None),
        DataPair(11.0, -0.37557642077681663, None, None),
        DataPair(12.0, 4.026765547345398, None, None),
        DataPair(13.0, -0.36983486724607273, None, None),
        DataPair(14.0, 0.17440222703465758, None, None),
        DataPair(15.0, 0.7842236092776063, None, None),
        DataPair(16.0, -0.48100135700671187, None, None),
        DataPair(17.0, -2.6742096302516645, None, None),
        DataPair(18.0, -1.5109738975157847, None, None),
        DataPair(19.0, -3.0109757078817183, None, None),
        DataPair(20.0, 1.1770643432686392, None, None),
        DataPair(21.0, 2.1910775139485392, None, None),
        DataPair(22.0, -1.4868175785260092, None, None),
        DataPair(23.0, -1.2644994625265626, None, None),
        DataPair(24.0, 4.107631238269208, None, None),
        DataPair(25.0, 2.120423606294751, None, None),
        DataPair(26.0, -0.6500544463745567, None, None),
        DataPair(27.0, -0.9325191282319775, None, None),
        DataPair(28.0, 3.3825604054671, None, None),
        DataPair(29.0, 0.9516848676736149, None, None),
        DataPair(30.0, 0.22396974649693008, None, None),
        DataPair(31.0, 2.347170700705393, None, None),
        DataPair(32.0, -0.35687609322275693, None, None),
        DataPair(33.0, 0.2909794111237789, None, None),
        DataPair(34.0, 1.2463137452367112, None, None),
...
res7_13: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, -0.03696523048064158, None, None),
        DataPair(1.0, -2.1256426418954573, None, None),
        DataPair(2.0, 0.2820103177178188, None, None),
        DataPair(3.0, 3.6629781276471918, None, None),
        DataPair(4.0, -5.6335881990476695, None, None),
        DataPair(5.0, -0.7793385520503001, None, None),
        DataPair(6.0, 3.2599185228928134, None, None),
        DataPair(7.0, -1.5850260112447843, None, None),
        DataPair(8.0, -1.1622922027222424, None, None),
        DataPair(9.0, 1.3932119206844524, None, None),
        DataPair(10.0, -0.8487122648638695, None, None),
        DataPair(11.0, -0.37557642077681663, None, None),
        DataPair(12.0, 4.026765547345398, None, None),
        DataPair(13.0, -0.36983486724607273, None, None),
        DataPair(14.0, 0.17440222703465758, None, None),
        DataPair(15.0, 0.7842236092776063, None, None),
        DataPair(16.0, -0.48100135700671187, None, None),
        DataPair(17.0, -2.6742096302516645, None, None),
        DataPair(18.0, -1.5109738975157847, None, None),
        DataPair(19.0, -3.0109757078817183, None, None),
        DataPair(20.0, 1.1770643432686392, None, None),
        DataPair(21.0, 2.1910775139485392, None, None),
        DataPair(22.0, -1.4868175785260092, None, None),
        DataPair(23.0, -1.2644994625265626, None, None),
        DataPair(24.0, 4.107631238269208, None, None),
        DataPair(25.0, 2.120423606294751, None, None),
        DataPair(26.0, -0.6500544463745567, None, None),
        DataPair(27.0, -0.9325191282319775, None, None),
        DataPair(28.0, 3.3825604054671, None, None),
        DataPair(29.0, 0.9516848676736149, None, None),
        DataPair(30.0, 0.22396974649693008, None, None),
        DataPair(31.0, 2.347170700705393, None, None),
        DataPair(32.0, -0.35687609322275693, None, None),
        DataPair(33.0, 0.2909794111237789, None, None),
        DataPair(34.0, 1.2463137452367112, None, None),
...

In [9]:
//Now train a GP-AR model based on the non-linear time series data.
val train_split = 0.4

val markov_chain_train_data = dtfdata
    .dataset(samples_markov.tail.flatMap(_.sliding(p + 1).toSeq))
    .map(h => (DenseVector(h.take(p).toArray), h.last))
    .to_supervised(identityPipe[(DenseVector[Double], Double)])

val markov_chain_first_sample = dtfdata
    .dataset(samples_markov.head.sliding(p + 1).toSeq)
    .map(h => (DenseVector(h.take(p).toArray), h.last))
    .to_supervised(identityPipe[(DenseVector[Double], Double)])
    .partition(train_split)

val markov_chain_samples = dtfdata.tf_dataset(
    markov_chain_train_data.concatenate(
        markov_chain_first_sample.training_dataset
    ),
    markov_chain_first_sample.test_dataset
)

val test_split_size = markov_chain_samples.test_dataset.size

val hyper_prior = Map(
    "bandwidth" -> UniformRV(0.1, 5d),
    "amplitude" -> UniformRV(0.1, 5d),
    "noiseLevel" -> UniformRV(0.1, 5d)
)

gp_prior.hyperPrior_(
     hyper_prior
)

gp_prior.globalOptConfig_(
    Map(
        "gridStep"  -> "0.15",
        "gridSize"  -> "5",
        "globalOpt" -> "GS",
        "policy"    -> "GS",
        "maxIt"     -> "2"
    )
)

val gp_nar_model = gp_prior.posteriorModel(
    markov_chain_samples.training_dataset.data.toSeq
)

val (test_preds, lower_bar, upper_bar) = gp_nar_model
    .predictionWithErrorBars(
        markov_chain_samples.test_dataset
            .map(tup2_1[DenseVector[Double], Double])
            .data
            .toSeq,
        3
    )
    .map(pattern => (pattern._2, pattern._3, pattern._4))
    .unzip3


-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Grid Search 
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

15 / 15 [=======================================================] 100.00 % 1/s  
Optimum value of energy is: 1243.2673431236565
Configuration: 
Map(
  "bandwidth" -> 2.260910792943165,
  "amplitude" -> 0.5413270114642186,
  "noiseLevel" -> 1.836224856766493
)
Out[9]:
train_split: Double = 0.4
markov_chain_train_data: io.github.mandar2812.dynaml.tensorflow.data.SupervisedDataSet[DenseVector[Double], Double] = SupervisedDataSet(
  io.github.mandar2812.dynaml.tensorflow.data.DataSet@1a44cb53,
  io.github.mandar2812.dynaml.tensorflow.data.DataSet@23713795
)
markov_chain_first_sample: io.github.mandar2812.dynaml.tensorflow.data.TFDataSet[(DenseVector[Double], Double)] = TFDataSet(
  io.github.mandar2812.dynaml.tensorflow.data.DataSet@31a72273,
  io.github.mandar2812.dynaml.tensorflow.data.DataSet@23c13bf2
)
markov_chain_samples: io.github.mandar2812.dynaml.tensorflow.data.TFDataSet[(DenseVector[Double], Double)] = TFDataSet(
  io.github.mandar2812.dynaml.tensorflow.data.DataSet@49526391,
  io.github.mandar2812.dynaml.tensorflow.data.DataSet@23c13bf2
)
test_split_size: Int = 59
hyper_prior: Map[String, UniformRV] = Map(
  "bandwidth" -> UniformRV(0.1, 5.0),
  "amplitude" -> UniformRV(0.1, 5.0),
  "noiseLevel" -> UniformRV(0.1, 5.0)
)
gp_nar_model: gp_prior.GPModel = io.github.mandar2812.dynaml.models.gp.AbstractGPRegressionModel$$anon$1@79d03888
test_preds: Seq[Double] = Stream(
  0.08132801960130803,
  -0.04773789020346621,
  -0.04235590279941907,
  0.09508538275015009,
  -0.07676839820588932,
  0.07300188795812475,
  0.022646651264104523,
  -0.08037130067773575,
  -0.03058066469887087,
  0.034825022879929404,
  -0.18334145691546777,
  -0.209906031071957,
  0.02646649419557695,
  -0.30056411197944766,
  -0.14058589878030828,
  0.11374602633599151,
  -0.12742119262639134,
  0.15792153389456642,
  -0.06548294688947326,
  0.19876326915043102,
  0.07175442007953813,
  0.026026581320903075,
  0.24314167846735385,
  -0.09684429794241409,
  0.012001567169281038,
  -0.14680835566798678,
  0.19110555392511158,
  0.03822710113026253,
  0.16049623355088977,
  -0.16591518281785228,
  -0.006826892881712357,
  -0.2404389328045518,
  -0.1438763422400595,
  0.14875206171113403,
  -0.06157737885068092,
  0.029625459061742798,
  -0.16443705186625368,
  -0.24131851192791337,
...
lower_bar: Seq[Double] = Stream(
  -0.2732266224267819,
  -0.3976473625389879,
  -0.3220243467322554,
  -0.39836429013860886,
  -0.5568645840632286,
  -0.38784319261402234,
  -0.5504707324925212,
  -0.4948827351667738,
  -0.39622204328665867,
  -0.5376283546602362,
  -0.5685907638635391,
  -0.2943449194507884,
  -0.31558087200349194,
  -0.7521057299629306,
  -0.3163602936519001,
  -0.39746747540394445,
  -0.42043368455322,
  -0.1601599606167266,
  -0.41505723678684325,
  -0.41794114708234026,
  -0.3290000461694273,
  -0.5102465156563056,
  -0.5046195347528257,
  -0.9665818779692051,
  -0.2243816101267574,
  -0.26318813844942845,
  -0.40458003757046784,
  -0.2816941074130104,
  -0.19247569254209773,
  -0.6566325383617553,
  -0.3941371316253305,
  -0.7584916049037058,
  -0.49314632369382383,
  -0.04150898674961853,
  -0.3156877606616462,
  0.004022177708271523,
  -0.7095007307026951,
  -0.8011975925257264,
...
upper_bar: Seq[Double] = Stream(
  0.435882661629398,
  0.3021715821320555,
  0.2373125411334172,
  0.5885350556389091,
  0.40332778765144994,
  0.5338469685302718,
  0.5957640350207302,
  0.3341401338113023,
  0.3350607138889169,
  0.607278400420095,
  0.2019078500326036,
  -0.1254671426931256,
  0.36851386039464584,
  0.1509775060040352,
  0.03518849609128358,
  0.6249595280759275,
  0.1655912993004373,
  0.47600302840585945,
  0.28409134300789673,
  0.8154676853832024,
  0.4725088863285036,
  0.5622996782981118,
  0.9909028916875335,
  0.7728932820843769,
  0.24838474446531944,
  -0.03042857288654509,
  0.7867911454206911,
  0.3581483096735354,
  0.5134681596438773,
  0.32480217272605066,
  0.3804833458619058,
  0.27761373929460215,
  0.20539363921370482,
  0.3390131101718866,
  0.19253300296028436,
  0.05522874041521407,
  0.3806266269701878,
  0.3185605686698996,
...

In [10]:
val last_train_sample_index = 
    (train_split * 
         samples_markov.head
            .sliding(p + 1)
            .toSeq
            .length
    ) - 1

spline(xs.zip(samples_markov.head))
hold()
spline(xs.takeRight(test_split_size).zip(test_preds))
spline(xs.takeRight(test_split_size).zip(lower_bar))
spline(xs.takeRight(test_split_size).zip(upper_bar))
unhold()
title("Time Series Prediction")
legend(
    Seq("Time Series", "MAP Prediction", "Lower Error Bar", "Upper Error Bar")
)


Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Output written to http://tail-box:42715 (CMD + Click link in Mac OSX).
Out[10]:
last_train_sample_index: Double = 37.800000000000004
res9_1: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res9_3: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res9_4: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res9_5: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res9_7: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...
res9_8: io.github.mandar2812.dynaml.graphics.charts.highcharts.Highchart = Highchart(
  List(
    Series(
      List(
        DataPair(0.0, 2.0661407541404424, None, None),
        DataPair(1.0, -0.20279635893745562, None, None),
        DataPair(2.0, 2.0118829440923975, None, None),
        DataPair(3.0, 2.0661407541404424, None, None),
        DataPair(4.0, -0.7668105130011957, None, None),
        DataPair(5.0, -0.5506978934362262, None, None),
        DataPair(6.0, 0.3259708389782872, None, None),
        DataPair(7.0, 0.7550958981227435, None, None),
        DataPair(8.0, 0.24667640048362177, None, None),
        DataPair(9.0, 0.36204346569998375, None, None),
        DataPair(10.0, 0.5915722688138524, None, None),
        DataPair(11.0, 0.6932176202171723, None, None),
        DataPair(12.0, 0.7861619749847729, None, None),
        DataPair(13.0, 0.6823027547053315, None, None),
        DataPair(14.0, 1.5148898666329573, None, None),
        DataPair(15.0, -1.7103351094654018, None, None),
        DataPair(16.0, -0.3261593937461385, None, None),
        DataPair(17.0, -1.7700909245481486, None, None),
        DataPair(18.0, 0.20082466165254687, None, None),
        DataPair(19.0, -1.9933270130562681, None, None),
        DataPair(20.0, -1.926345691383111, None, None),
        DataPair(21.0, 1.8459166290160602, None, None),
        DataPair(22.0, -1.218740489452355, None, None),
        DataPair(23.0, 0.28459635602781436, None, None),
        DataPair(24.0, 0.7166564133035342, None, None),
        DataPair(25.0, -1.5076764366708415, None, None),
        DataPair(26.0, 0.23340051122886576, None, None),
        DataPair(27.0, -1.8071980087295354, None, None),
        DataPair(28.0, -1.852702605304878, None, None),
        DataPair(29.0, -2.588991017869229, None, None),
        DataPair(30.0, -0.2263352172924218, None, None),
        DataPair(31.0, 0.36731003883770413, None, None),
        DataPair(32.0, -0.078109602362965, None, None),
        DataPair(33.0, -0.7034250593297158, None, None),
        DataPair(34.0, 0.10847474421188891, None, None),
...