예제 #1
0
inline
void
subview_field<oT>::operator= (const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  subview_field<oT>& t = *this;
  
  arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols) || (t.n_slices != x.n_slices), "incompatible field dimensions");
  
  if(t.n_slices == 1)
    {
    for(uword col=0; col < t.n_cols; ++col)
    for(uword row=0; row < t.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
  else
    {
    for(uword slice=0; slice < t.n_slices; ++slice)
    for(uword col=0;   col   < t.n_cols;   ++col  )
    for(uword row=0;   row   < t.n_rows;   ++row  )
      {
      t.at(row,col,slice) = x.at(row,col,slice);
      }
    }
  }
예제 #2
0
arma::vec log_longF_svft(const field<vec>& y, const field<vec>& eta,
                         const CharacterVector& fams, const CharacterVector& links,
                         const List& sigmas, const field<uvec>& id, const int& n) {
    int n_outcomes = y.size();
    vec out(n, fill::zeros);
    for (int i = 0; i < n_outcomes; ++i) {
        uvec id_i = id.at(i);
        vec y_i = y.at(i);
        vec eta_i = eta.at(i);
        if (fams[i] == "gaussian") {
            double sigma_i = as<double>(sigmas[i]);
            vec log_dens = - 0.5 * pow((y_i - eta_i) / sigma_i, 2);
            out += rowsum_svft(log_dens, id_i);
        } else if (fams[i] == "binomial") {
            if (links[i] == "logit") {
                vec pr = exp(eta_i) / (1 + exp(eta_i));
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            } else if (links[i] == "probit") {
                vec pr = Vpnorm_svft(eta_i);
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            } else if (links[i] == "cloglog") {
                vec pr = - exp(- exp(eta_i)) + 1;
                vec log_dens = y_i % log(pr) + (1 - y_i) % log(1 - pr);
                out += rowsum_svft(log_dens, id_i);
            }
        } else if (fams[i] == "poisson") {
            vec mu = exp(eta_i);
            vec log_dens = y_i % log(mu) - mu;
            out += rowsum_svft(log_dens, id_i);
        }
    }
    return(out);
}
예제 #3
0
arma::field<arma::vec> lin_predF_svft(const field<vec>& Xbetas, const field<mat>& Z,
                                      const mat& b, const field<uvec>& RE_inds,
                                      const field<uvec>& id) {
    signed int n_field = Xbetas.size();
    field<vec> out(n_field);
    for (int i = 0; i < n_field; ++i) {
        mat bb = b.cols(RE_inds.at(i));
        vec Zb = sum(Z.at(i) % bb.rows(id.at(i)), 1);
        out.at(i) = Xbetas.at(i) + Zb;
    }
    return(out);
}
inline
void
subview_field<oT>::operator= (const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  subview_field<oT>& t = *this;
  
  arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
  
  for(u32 col=0; col<t.n_cols; ++col)
    {
    for(u32 row=0; row<t.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
  }
예제 #5
0
파일: field_meat.hpp 프로젝트: iirob/wire
inline
void
field<oT>::init(const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  if(this != &x)
    {
    init(x.n_rows, x.n_cols);
    
    field& t = *this;
    
    for(uword col=0; col<x.n_cols; ++col)
    for(uword row=0; row<x.n_rows; ++row)
      {
      t.at(row,col) = x.at(row,col);
      }
    }
  
  }
inline
void
field<oT>::init(const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  if(this != &x)
    {
    const uword x_n_rows = x.n_rows;
    const uword x_n_cols = x.n_cols;
    
    init(x_n_rows, x_n_cols);
    
    field& t = *this;
    
    for(uword ucol=0; ucol < x_n_cols; ++ucol)
    for(uword urow=0; urow < x_n_rows; ++urow)
      {
      t.at(urow,ucol) = x.at(urow,ucol);
      }
    }
  
  }
inline
void
arma_ostream::print(std::ostream& o, const field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  const arma_ostream_state stream_state(o);
  
  const std::streamsize cell_width = o.width();
  
  const uword x_n_rows = x.n_rows;
  const uword x_n_cols = x.n_cols;
  
  if(x.is_empty() == false)
    {
    for(uword col=0; col<x_n_cols; ++col)
      {
      o << "[field column " << col << ']' << '\n'; 
      
      for(uword row=0; row<x_n_rows; ++row)
        {
        o.width(cell_width);
        o << x.at(row,col) << '\n';
        }
      
      o << '\n';
      }
    }
  else
    {
    o << "[field size: " << x_n_rows << 'x' << x_n_cols <<  "]\n";
    }
  
  o.flush();
  stream_state.restore(o);
  }
예제 #8
0
arma::mat lin_pred_matF_svft(const field<vec>& Xbetas, const field<mat>& Z,
                             const mat& b, const field<mat>& U,
                             const field<uvec>& RE_inds, const field<uvec>& id,
                             const field<uvec>& col_inds, const uvec& row_inds,
                             const int& nrows, const int& ncols,
                             const CharacterVector& trans_Funs) {
    int n_field = Xbetas.size();
    mat out = mat(nrows, ncols, fill::zeros);
    for (int i = 0; i < n_field; ++i) {
        mat bb = b.cols(RE_inds.at(i));
        vec Zb = sum(Z.at(i) % bb.rows(id.at(i)), 1);
        if (trans_Funs[i] == "identity") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % (Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "expit") {
            vec exp_eta = exp(Xbetas.at(i) + Zb);
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % (exp_eta / (1 + exp_eta));
        } else if (trans_Funs[i] == "exp") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % exp(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log2") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log2(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "log10") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % log10(Xbetas.at(i) + Zb);
        } else if (trans_Funs[i] == "sqrt") {
            out.submat(row_inds, col_inds.at(i)) = U.at(i).each_col() % sqrt(Xbetas.at(i) + Zb);
        }
    }
    return(out);
}