MCPcopy Create free account
hub / github.com/apache/madlib / run

Method run

src/modules/tsa/arima.cpp:48–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46// ----------------------------------------------------------------------
47
48AnyType arima_residual::run (AnyType & args)
49{
50 int32_t distid = args[0].getAs<int32_t>();
51 ArrayHandle<double> tvals = args[1].getAs<ArrayHandle<double> >();
52 int p = args[2].getAs<int>();
53 int d = args[3].getAs<int>();
54 int q = args[4].getAs<int>();
55 ArrayHandle<double> phi(NULL);
56 if(p > 0)
57 phi = args[5].getAs<ArrayHandle<double> >();
58 ArrayHandle<double> theta(NULL);
59 if(q > 0)
60 theta = args[6].getAs<ArrayHandle<double> >();
61 double mean = 0.0;
62 if(!args[7].isNull())
63 mean = args[7].getAs<double>();
64 ArrayHandle<double> prez(NULL);
65 if(q > 0)
66 prez = args[8].getAs<ArrayHandle<double> >();
67
68 int ret_size = static_cast<int>((distid == 1) ? \
69 (tvals.size()+d) : (tvals.size()-p));
70 MutableArrayHandle<double> res(
71 madlib_construct_array(
72 NULL, ret_size, FLOAT8TI.oid,
73 FLOAT8TI.len, FLOAT8TI.byval, FLOAT8TI.align));
74
75 if (q < 1) {
76 // compute the errors
77 for(size_t i = p; i < tvals.size(); i++){
78 double err = tvals[i] - mean;
79 for(int j = 0; j < p; j++)
80 err -= phi[j] * (tvals[i - j - 1] - mean);
81 // note that for distid = 1, the first p residuals
82 // will always be 0
83 res[(distid == 1) ? i+d : (i - p)] = err;
84 }
85 return res;
86 } else {
87 // in this way we don't need to update prez explicitly
88 double * errs = new double[ret_size + q];
89 memset(errs, 0, sizeof(double) * (ret_size+q));
90 // how to judge ArrayHandle is Null?
91 if(distid != 1)
92 for(int i = 0; i < q; i++) errs[i] = prez[i];
93
94 // compute the errors
95 for(size_t t = p; t < tvals.size(); t++){
96 double err = tvals[t] - mean;
97
98 for(int j = 0; j < p; j++)
99 err -= phi[j] * (tvals[t - j - 1] - mean);
100
101 for(int j = 0; j < q; j++)
102 if(distid == 1)
103 err -= theta[j] * errs[t+q+d-j-1];
104 else
105 err -= theta[j] * errs[t-p+q-j-1];

Callers

nothing calls this directly

Calls 8

diff_coefFunction · 0.85
errorFunction · 0.85
update_prezFunction · 0.85
madlib_construct_arrayFunction · 0.50
isNullMethod · 0.45
sizeMethod · 0.45
ptrMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected