Vec ArModel::simulate(int n, const Vec &y0) const { if(y0.size() != number_of_lags()){ ostringstream err; err << "Error in ArModel::simulate." << endl << "Initial state value y0 was size " << y0.size() << ", but the model has " << number_of_lags() << " lags." << endl; report_error(err.str()); } const Vec &phi(this->phi()); std::deque<double> lags(y0.rbegin(), y0.rend()); Vec ans; ans.reserve(n); for(int i = 0; i < n; ++i) { double mu = 0; for(int lag = 0; lag < number_of_lags(); ++lag) { mu += phi[lag] * lags[lag]; } double y = rnorm(mu, sigma()); lags.push_front(y); lags.pop_back(); ans.push_back(y); } return ans; }
static int read_data() { int i; int j; int prind; int runlen; unsigned int u; double a; n=0L; run_start=0L; up=-1; sum1=sum2=0.0; if (n_sub) { i_sub=0; sub_sum1=0.0; sub_min=1e30; sub_max=-1e30; for (i=0; i<n_subclass; ++i) { p_mean[i]=p_min[i]=p_max[i]=0; } } if (fr_n) for (i=0; i<fr_n; ++i) fr_f[i]=0L; lagpos=0; for (i=0; i<maxlag; ++i) lagv[i]=lagvv[i]=0.0; for (i=0; i<maxgap; ++i) gap[i]=0L; gaplen=gapmax=0L; if (permlen) { i_perm=0; for (u=0; u<n_perm; ++u) f_perm[u]=0L; } if (poklen) { i_pok=0; for (u=0; u<n_pok; ++u) f_pok[u]=0L; for (u=0; u<poklen; ++u) f1_pok[u]=0; } if (couplen) { init_coup(); for (u=0; u<coup_max; ++u) f_coup[u]=0L; } i=spfind("PRIND"); if (i>=0) prind=atoi(spb[i]); else prind=0; sur_print("\n"); for (j=d.l1; j<=d.l2; ++j) { if (unsuitable(&d,j)) continue; /*********************** if (sur_kbhit()) { sur_getch(); prind=1-prind; } ************************/ if (prind) { sprintf(sbuf,"%d ",j); sur_print(sbuf); } data_load(&d,j,var,&x); if (x==MISSING8) continue; ++n; sum1+=x; sum2+=x*x; if (n_sub) { sub_sum1+=x; if (x<sub_min) sub_min=x; if (x>sub_max) sub_max=x; ++i_sub; if (i_sub==n_sub) { sub_sum1/=(double)n_sub; a=muste_cdf_std(sqrt(12.0*(double)n_sub)*(sub_sum1-0.5)); i=a*(double)n_subclass; ++p_mean[i]; i=pow(1.0-sub_min,(double)n_sub)*(double)n_subclass; ++p_min[i]; i=pow(sub_max,(double)n_sub)*(double)n_subclass; ++p_max[i]; i_sub=0; sub_sum1=0.0; sub_min=1e30; sub_max=-1e30; } } if (fr_n) freq(); runs_updown(); lags(); if (maxgap) gaps(); if (permlen) permtest(); if (poklen) poker(); if (couplen) coupon(); xlag=x; } runlen=n-run_start; if (runlen>MAXRUN) runlen=MAXRUN-1; if (up) ++runs_up[(int)(runlen-1)]; else ++runs_down[(int)(runlen-1)]; if (maxgap) { if (gaplen>gapmax) gapmax=gaplen; if (gaplen>(unsigned int)(maxgap-1)) gaplen=maxgap-1; ++gap[(int)gaplen]; } return(1); }