File: calcTBATS.cpp

package info (click to toggle)
r-cran-forecast 8.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,248 kB
  • sloc: cpp: 975; ansic: 648; sh: 13; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "calcBATS.h"

using namespace Rcpp ;

SEXP calcTBATSFaster(SEXP ys, SEXP yHats, SEXP wTransposes, SEXP Fs, SEXP xs, SEXP gs, SEXP es, SEXP xNought_s) {
	BEGIN_RCPP


	NumericMatrix yr(ys);
	NumericMatrix yHatr(yHats);
	NumericMatrix wTransposer(wTransposes);
	NumericMatrix Fr(Fs);
	NumericMatrix xr(xs);
	NumericMatrix gr(gs);
	NumericMatrix er(es);
	NumericMatrix xNought_r(xNought_s);


	arma::mat y(yr.begin(), yr.nrow(), yr.ncol(), false);
	arma::mat yHat(yHatr.begin(), yHatr.nrow(), yHatr.ncol(), false);
	arma::mat wTranspose(wTransposer.begin(), wTransposer.nrow(), wTransposer.ncol(), false);
	arma::mat F(Fr.begin(), Fr.nrow(), Fr.ncol(), false);
	arma::mat x(xr.begin(), xr.nrow(), xr.ncol(), false);
	arma::mat g(gr.begin(), gr.nrow(), gr.ncol(), false);
	arma::mat e(er.begin(), er.nrow(), er.ncol(), false);
	arma::mat xNought(xNought_r.begin(), xNought_r.nrow(), xNought_r.ncol(), false);





	yHat.col(0) = wTranspose * xNought;
	e(0,0) = y(0, 0) - yHat(0, 0);
	x.col(0) = F * xNought + g * e(0,0);

	for(int t = 1; t < yr.ncol(); t++) {
		yHat.col(t) = wTranspose * x.col((t-1));
		e(0,t) = y(0, t) - yHat(0, t);
		x.col(t) = F * x.col((t-1)) + g * e(0,t);
	}


	return R_NilValue;

	END_RCPP
}