double WP::loglike(const Vector &lam0_delta_weekday_weekend)const{
    const Mat &exposure(suf()->exposure());
    const Mat & count(suf()->count());

    double lambda0 = lam0_delta_weekday_weekend[0];
    Vector delta(7, 0.0);
    int pos = 1;
    VectorView(delta, 0, 6) = ConstVectorView(lam0_delta_weekday_weekend, pos, 6);
    delta[6] = 7.0 - sum(delta);
    pos += 6;

    Vector eta_weekday(24, 0.0);
    VectorView(eta_weekday, 0, 23) =
        ConstVectorView(lam0_delta_weekday_weekend, pos, 23);
    eta_weekday[23] = 24.0 - sum(eta_weekday);
    pos += 23;

    Vector eta_weekend(24, 0.0);
    VectorView(eta_weekend, 0, 23) =
        ConstVectorView(lam0_delta_weekday_weekend, pos, 23);
    eta_weekend[23] = 24.0 - sum(eta_weekend);

    double ans = 0;
    for(int d = 0; d < 7; ++d){
      const Vec &eta( (d==Sat || d==Sun) ? eta_weekend : eta_weekday);
      for(int h = 0; h < 24; ++h){
        double lam = lambda0 * delta[d] * eta[h] * exposure(d, h);
        ans += dpois(count(d, h), lam, true);
      }
    }
    return ans;
  }
Example #2
0
 ConstVectorView ToBoomVectorView(SEXP v) {
   if (!Rf_isNumeric(v)) {
     report_error("ToBoomVectorView called with a non-numeric argument.");
   }
   PROTECT(v = Rf_coerceVector(v, REALSXP));
   int n = Rf_length(v);
   double *data = REAL(v);
   UNPROTECT(1);
   return ConstVectorView(data, n, 1);
 }
//----------------------------------------------------------------------
Vec AccumulatorTransitionMatrix::Tmult(const Vec &v)const {
    int state_dim = transition_matrix_->ncol();
    if(v.size() != state_dim + 2) {
        report_multiplication_error(
            transition_matrix_, observation_vector_, contains_end_,
            fraction_in_initial_period_, v);
    }

    double w = v[state_dim];
    double W = v[state_dim + 1];
    Vec ans(v.size());

    VectorView state_component(ans, 0, state_dim);
    Vec arg = (observation_vector_.dense() * w) +
              ConstVectorView(v, 0, state_dim);
    state_component = transition_matrix_->Tmult(arg);
    ans[state_dim] = (1 - fraction_in_initial_period_ * contains_end_) * W;
    ans[state_dim+1] = (1 - contains_end_) * W;
    return ans;
}
  double RM::Loglike(const Vector &sigsq_beta,
                     Vector &g, Matrix &h, uint nd)const{
    const double log2pi = 1.83787706640935;
    const double sigsq = sigsq_beta[0];
    const Vector b(ConstVectorView(sigsq_beta, 1));
    double n = suf()->n();
    if(b.size()==0) return empty_loglike(g, h, nd);

    double SSE = yty() - 2*b.dot(xty()) + xtx().Mdist(b);
    double ans =  -.5*(n * log2pi  + n *log(sigsq)+ SSE/sigsq);

    if(nd>0){  // sigsq derivs come first in CP2 vectorization
      SpdMatrix xtx = this->xtx();
      Vector gbeta = (xty() - xtx*b)/sigsq;
      double sig4 = sigsq*sigsq;
      double gsigsq = -n/(2*sigsq) + SSE/(2*sig4);
      g = concat(gsigsq, gbeta);
      if(nd>1){
        double h11 = .5*n/sig4 - SSE/(sig4*sigsq);
        h = unpartition(h11, (-1/sigsq)*gbeta, (-1/sigsq)*xtx);}}
    return ans;
  }
Example #5
0
 // Given a seasonal pattern, convert it to state by subtracting the mean,
 // removing the first element, and reversing the time order.
 Vector pattern_to_state(const Vector &pattern) {
   Vector tmp = pattern - mean(pattern);
   return rev(ConstVectorView(tmp, 1));
 }
Example #6
0
 ComparePredictionsOutput compare_predictions(const Vector &truth,
                                              const Vector &pred) {
   return compare_predictions(ConstVectorView(truth), ConstVectorView(pred));
 }
 void NeRegSuf::add_mixture_data(double y, const Vector &x, double prob){
   this->add_mixture_data(y, ConstVectorView(x), prob);
 }
Example #8
0
     ConstVectorView subvector(const VEC &v, uint start, uint stop){
   assert(start<=stop && start <v.size());
   uint size = 1+stop-start;
   return ConstVectorView(v.data()+ start, size, v.stride());
 }
Example #9
0
     ConstVectorView subvector(const VEC &v, uint start){
   return ConstVectorView(v.data()+ start, v.size()-start, v.stride());
 }