示例#1
0
 Vec MVTR::simulate_fake_x()const{
   uint p = xdim();
   Vec x(p);
   x[0] = 1.0;
   for(uint i=0; i<p; ++i) x[i] = rnorm();
   return x;
 }
 double MvReg::loglike(const Vector &beta_siginv) const {
   Matrix Beta(xdim(), ydim());
   Vector::const_iterator it = beta_siginv.cbegin();
   std::copy(it, it + Beta.size(), Beta.begin());
   it += Beta.size();
   SpdMatrix siginv(ydim());
   siginv.unvectorize(it, true);
   return log_likelihood_ivar(Beta, siginv);
 }
示例#3
0
double GridMapping::dx() const{
    if (xdim() != 0) {
        double x1,x0,y,z;
        indexToWorld(0, 0, 0, x0, y, z);
        indexToWorld(1, 0, 0, x1, y, z);
        return fabs(x1-x0);
    }
    return 0;
}
示例#4
0
bool GridMapping::operator== (const GridMapping & other){
    
    
    return (other.xdim() == xdim() &&
            other.ydim() == ydim() &&
            other.zdim() == zdim() &&
            other._trans == _trans &&
            other._itrans == _itrans &&
            other.size() == size());
}
 void RM::make_X_y(Matrix &X, Vector &Y)const{
   uint p = xdim();
   uint n = dat().size();
   X = Matrix(n,p);
   Y = Vector(n);
   for(uint i=0; i<n; ++i){
     Ptr<RegressionData> rdp = dat()[i];
     const Vector &x(rdp->x());
     assert(x.size()==p);
     X.set_row(i,x);
     Y[i] = rdp->y();
   }
 }
 Matrix MvRegSuf::conditional_beta_hat(const SelectorMatrix &included) const {
   Matrix ans(xdim(), ydim());
   std::map<Selector, Cholesky> chol_map;
   for (int i = 0; i < ydim(); ++i) {
     const Selector &inc(included.col(i));
     auto it = chol_map.find(inc);
     if (it == chol_map.end()) {
       chol_map[it->first] = Cholesky(inc.select(xtx()));
       it = chol_map.find(inc);
     } 
     ans.col(i) = inc.expand(it->second.solve(inc.select(xty_.col(i))));
   }
   return ans;
 }
示例#7
0
  double LRM::log_likelihood(const Vector & beta, Vector *g, Matrix *h,
                             bool initialize_derivs)const{
    const LRM::DatasetType &data(dat());
    if(initialize_derivs){
      if(g){
        g->resize(beta.size());
        *g=0;
        if(h){
          h->resize(beta.size(), beta.size());
          *h=0;}}}

    double ans = 0;
    int n = data.size();
    bool all_coefficients_included = coef().nvars() == xdim();
    const Selector &inc(coef().inc());
    for(int i = 0; i < n; ++i){
      bool y = data[i]->y();
      const Vector & x(data[i]->x());
      double eta = predict(x) + log_alpha_;
      double loglike = plogis(eta, 0, 1, y, true);
      ans += loglike;
      if(g){
        double logp = y ? loglike : plogis(eta, 0, 1, true, true);
        double p = exp(logp);
        if (all_coefficients_included) {
          *g += (y-p) * x;
          if(h){
            h->add_outer(x,x, -p*(1-p));
          }
        } else {
          Vector reduced_x = inc.select(x);
          *g += (y - p) * reduced_x;
          if (h) {
            h->add_outer(reduced_x, reduced_x, -p * (1 - p));
          }
        }
      }
    }
    return ans;
  }
示例#8
0
文件: Glm.cpp 项目: cran/Boom
 void GlmModel::drop_all() {
   for (int i = 0; i < xdim(); ++i) drop(i);
 }
示例#9
0
void GridMapping::localToUpperLeftIndex(const double l_x,const double l_y,const double l_z, int &i,int &j,int &k) const{
	i = (int)floor(l_x*double(xdim()-1));
    j = (int)floor(l_y*double(ydim()-1));
    k = (int)floor(l_z*double(zdim()-1));
}
示例#10
0
bool GridField<T>::isUndefined(int i,int j,int k) const{
	return i < 0 || i >= xdim() || j < 0 || j >= ydim() || k < 0 || k >= zdim();
}
示例#11
0
文件: Glm.cpp 项目: cran/Boom
 void GlmModel::add_all() {
   for (int i = 0; i < xdim(); ++i) add(i);
 }
 Vector MvReg::simulate_fake_x(RNG &rng) const {
   uint p = xdim();
   Vector x(p, 1.0);
   for (uint i = 1; i < p; ++i) x[i] = rnorm_mt(rng);
   return x;
 }
示例#13
0
//Local dim
double GridMapping::local_dx() const{
    return 1.0/double(xdim()-1);
}
示例#14
0
//Funktioner
//Index to index
 int GridMapping::indexAt(int i, int j, int k) const{
    return i+(xdim())*j+(xdim()*ydim()*k);
}
示例#15
0
void GridMapping::indexAt(int index, int &i, int &j, int &k) const{
    k = index /(xdim()*ydim());
    j = (index-(k*xdim()*ydim()))/(xdim());
    i = (index-j*xdim()-k*xdim()*ydim());
}
示例#16
0
bool GridMapping::isValid(int i, int j, int k) const{
    return (   i >= 0 && i < xdim()
            && j >= 0 && j < ydim()
            && k >= 0 && k < zdim());
}
示例#17
0
//Local to...
void GridMapping::localToIndex(double l_x, double l_y,double l_z,int &i,int &j,int &k) const{
    i = (int)round(l_x*double(xdim()-1));
    j = (int)round(l_y*double(ydim()-1));
    k = (int)round(l_z*double(zdim()-1));
}
示例#18
0
void GridMapping::indexToLocal(int i,int j,int k, double &l_x, double &l_y,double &l_z) const{
    l_x = double(i)/double(xdim()-1);
    l_y = double(j)/double(ydim()-1);
    l_z = double(k)/double(zdim()-1);//TODO om zdim = 1 så funkar inte detta, en ifsats kan lösa detta
}