Ejemplo n.º 1
0
const char *memcached_load(const char *library_name){
	if(!memcached_linked){
		memcached_linked=true;
		memcached_status=dlink(library_name);
	}

	return memcached_status;
}
Ejemplo n.º 2
0
   void _check_prerequisits()
   {
      _check_prereqs_xplatform();

      uid_t euid = geteuid();
      if (euid == 0)
         fatal("Please run as a standard user, not as root.");

#if defined(__APPLE__)
      // Docker Community Edition application on Mac does not require groups as below
#else
      std::string user = getUSER();
      if (0 != bashcommand("groups $USER | grep docker"))
         fatal("Please add the current user to the docker group. As root: " + utils::kCODE_S + "adduser " + user + " docker" + utils::kCODE_E);

      if (0 != bashcommand("groups | grep docker"))
         fatal(user + " hasn't picked up group docker yet. Log out then in again, or run " + utils::kCODE_S + "exec su -l " + user + utils::kCODE_E);
#endif

      if (!commandexists("docker"))
         fatal("Please install Docker before using dRunner.\n(e.g. use  https://raw.githubusercontent.com/j842/scripts/master/install_docker.sh )");

      if (!commandexists("curl"))
         fatal("Please install curl before using dRunner.");

      // check ~/.drunner/bin is in ~/.profile.
      _ensure_line(Poco::Path::home() + ".profile", "PATH=\"$HOME/.drunner/bin:$PATH\"");

      // check symbolic link
      std::string ddir = Poco::Path::home() + ".drunner";
      Poco::File dlink(ddir);
      if (dlink.exists())
      {
         if (dlink.isLink())
            dlink.remove();
         else
            dlink.renameTo(ddir + "09");
      }
      drunner_assert(!dlink.exists(), ".drunner folder still exists. :/ \n" + ddir);
      int r = symlink((ddir + getVersionNice()).c_str(), ddir.c_str());
      if (r != 0)
         fatal("Failed to create symlink at " + ddir);
   }
Ejemplo n.º 3
0
int glm_fit(int family, int link, int N, int M, int S,
	    const double *y, const double *prior, const double * offset, const double *X, 
	    const int *stratum, int maxit, double conv, int init, 
	    int *rank, double *Xb, 
	    double *fitted, double *resid, double *weights, 
	    double *scale, int *df_resid, double theta) {
  const double eta = 1.e-8;       /* Singularity threshold */
  int i = 0, j=0;
  int Nu, dfr, irls;
  int empty = 0;


//TO DO
//need to add condition to ensure theta>0
//trim code, remove unneeded if statements
//add way to handle intercept only models well in R entry

  /* Is iteration necessary? */


  
  irls =  ( ((offset) || (M>0)) && !((family==GAUSSIAN) && (link==IDENTITY)));
//    if (family == BINOMIAL) cout<<"M  "<<M<<endl;
  //  for (int i = 0; i != 1000; i++) {cout<<i<<"\t"<<prior[i]<<endl;}

    if (!init || !irls) {
    /* Fit intercept and/or strata part of model */
        empty = wcenter(y, N, prior, stratum, S, 0, fitted);    
  }

  Nu = 0;
  int invalid = 0;
  for (i=0; i<N; i++) {
    double mu = fitted[i];
    double ri, wi;
    double pi = prior? prior[i] : 1.0;
     if (!muvalid(family, mu, theta)) {
       invalid = 1;
       pi = 0.0;
    }
    if (!(pi)) {wi = ri = 0.0;}
    else {
      Nu ++;
      double Vmu = varfun(family, mu, theta);
      if (link == family) {
	ri = (y[i] - mu)/Vmu;
	wi = pi*Vmu;
      }
      else {
	double D = dlink(link, mu);
	ri = D*(y[i] - mu);
	wi = pi/(D*D*Vmu);
      }
    }
    weights[i] = wi;
    resid[i] = ri;

    if (weights[i] <= 0.) weights[i] = 0.;
  }
	
  /* If M>0, include covariates */
  int x_rank = 0, convg = 0, iter = 0;
  if ((M == 0) && !offset) convg = 1;
  if (M> 0 || offset) {   //maybe also where there is an offset?
    convg = 0;
    double wss_last = 0.0;
    if (irls) {
      
      /* IRLS algorithm */
      double *yw = (double *) Calloc(N, double);  //working y
      while(iter<maxit && !convg) {
	for (i=0; i<N; i++) {
	  yw[i] = resid[i] + linkfun(link, fitted[i]);   //current estimate of eta + (y-mu)/gradient
	}

	if (offset) {for (i=0; i<N; i++) {yw[i] -= offset[i];}}
	empty = wcenter(yw, N, weights, stratum, S, 1, resid);    //removes the mean from yw

	//////////// now it tries to fit the regression line (no intercept) to the residuals
	const double *xi = X;
	double *xbi = Xb;
	x_rank = 0;

	for (i=0; i<M; i++, xi+=N) {
	  double ssx = wssq(xi, N, weights);
	  wcenter(xi, N, weights, stratum, S, 1, xbi);
	  double *xbj = Xb;
	  for (j=0; j<x_rank; j++, xbj+=N) wresid(xbi, N, weights, xbj, xbi);
	  double ssr = wssq(xbi, N, weights);
	  if (ssr/ssx > eta) {
	    wresid(resid, N, weights, xbi, resid);   //takes the residuals after fitting the regression line (no intercept) to the mean value per stratum
	    x_rank++;
	    xbi+=N;
	  }
	}


	double wss=0.0;
	Nu = 0;
	for (i=0; i<N; i++) {
	  double D, Vmu, ri, wi;
	  double mu = invlink(link, yw[i] - resid[i]);   //ie. (yw - (yw - mean(yw))) = mean(yw)
	  if (offset) {mu = invlink(link, yw[i] + offset[i] - resid[i]);}

	  fitted[i] = mu;

	  double pi = prior? prior[i] : 1.0;
	  if (!(pi && (weights[i]>0.0))) {wi = ri = 0.0;} else {
	    
	    if (!(muvalid(family, mu, theta))) {
	      if ((family == 4) && (mu > 5.0)) {mu = fitted[i] = 5.0;}
	      if ((family == 4) && (mu < 0.001)) {mu = fitted[i] = 0.001;}
	    }
	    
	    Vmu = varfun(family, mu, theta);
	    Nu ++;
	    if (link == family) {
	      ri = (y[i] - mu)/Vmu;
	      wi = pi*Vmu;
	    }
	    else {
	      D = dlink(link, mu);
	      ri = D*(y[i] - mu);
	      wi = pi/(D*D*Vmu);
	    }
	    wss += wi*ri*ri;
	    
	      
	    weights[i] = wi;
	    resid[i] = ri;
	    if (weights[i] <= 0.) weights[i] = 0.;
	  }
	}
	convg =/* (family==2) ||*/ (Nu<=0) || (iter && (fabs(wss-wss_last)/wss_last < conv));
	wss_last = wss;
	iter ++;
      }
      Free(yw);
    } else {