Esempio n. 1
0
void usePathWrite::parse(const ST::string & usetext)
  {

  path = "";
  errormessages.clear();
  notext = true;

  if (usetext.length() > 0)
	 {
	 notext = false;
	 int k = usetext.isvalidfile();

	 if (k == 1)
		{
		errormessages.push_back("ERROR: file " + usetext +
		" could not be opened for writing\n");
		alreadyexisting = false;
		}
	 else if (k == 0)
		alreadyexisting = false;
	 else
		alreadyexisting = true;

	 if (errormessages.empty())
		path = usetext;
	 }

  }
Esempio n. 2
0
void FC_nonp_variance_varselection::outresults(ofstream & out_stata,ofstream & out_R,
                                  const ST::string & pathresults)
  {

  if (pathresults.isvalidfile() != 1)
    {

    ST::string pathresults_delta = pathresults.substr(0,pathresults.length()-4) + "_delta.res";
    ST::string pathresults_omega = pathresults.substr(0,pathresults.length()-4) + "_omega.res";

    FC_nonp_variance::outresults(out_stata,out_R,pathresults);

    FC_delta.outresults(out_stata,out_R,"");
    FC_omega.outresults(out_stata,out_R,pathresults_omega);


    optionsp->out("    Inclusion probability: " + ST::doubletostring(FC_delta.betamean(0,0),6)  + "\n");
    optionsp->out("\n");
    optionsp->out("    Results for the inclusion probabilities are also stored in file\n");
    optionsp->out("    " +  pathresults_delta + "\n");
    optionsp->out("\n");
    optionsp->out("\n");

    optionsp->out("    Inclusion probability parameter omega:\n");
    optionsp->out("\n");
    FC_omega.outresults_singleparam(out_stata,out_R,"");
    optionsp->out("    Results for the inclusion probability parameter omega are also stored in file\n");
    optionsp->out("    " +  pathresults_omega + "\n");
    optionsp->out("\n");
    optionsp->out("\n");

    // deltas
    ofstream ou(pathresults_delta.strtochar());

    ou << "pmean" << endl;
    ou << FC_delta.betamean(0,0) << endl;
    }


//  FC_nonp_variance::outresults(out_stata,out_R,pathresults);

  }
Esempio n. 3
0
void FC_predict_mult::outresults(ofstream & out_stata, ofstream & out_R,
                            const ST::string & pathresults)
  {

  if (pathresults.isvalidfile() != 1)
    {

    FC::outresults(out_stata,out_R,"");

    FC_deviance.outresults(out_stata,out_R,"");

    optionsp->out("  PREDICTED VALUES: \n",true);
    optionsp->out("\n");

    optionsp->out("    Results for the predictor, mean are stored in file\n");
    optionsp->out("    " +  pathresults + "\n");
    optionsp->out("\n");
    out_R << "predict=" << pathresults << ";" <<  endl;

    ofstream outres(pathresults.strtochar());

    optionsp->out("\n");

    unsigned i,j;

    ST::string l1 = ST::doubletostring(optionsp->lower1,4);
    ST::string l2 = ST::doubletostring(optionsp->lower2,4);
    ST::string u1 = ST::doubletostring(optionsp->upper1,4);
    ST::string u2 = ST::doubletostring(optionsp->upper2,4);
    l1 = l1.replaceallsigns('.','p');
    l2 = l2.replaceallsigns('.','p');
    u1 = u1.replaceallsigns('.','p');
    u2 = u2.replaceallsigns('.','p');

    outres << "intnr" << "   ";

    for (i=0;i<varnames.size();i++)
      outres << varnames[i] << "   ";

      vector<double *> responsep;
      vector<double *> weightpmat;
      vector<double *> workmeanmat;
      vector<datamatrix *>   auxhelp;

     for (j=0;j<likep.size();j++)
       {
       workmeanmat.push_back((betamean.getV()+j));
       responsep.push_back(likep[j]->response.getV());
       weightpmat.push_back(likep[j]->weight.getV());
       auxhelp.push_back(likep[j]->get_auxiliary_parameter());
       }


    if (nosamplessave==false)
      {

      for (i=0;i<likep.size();i++)
        {

        if (likep[i]->outpredictor)
          {
          outres << "pmean_pred_" << likep[i]->predictor_name << "   ";

          if (optionsp->samplesize > 1)
            {
            outres << "pqu"  << l1  << "_pred_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << l2  << "_pred_" << likep[i]->predictor_name << "   ";
            outres << "pmed_pred_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << u1  << "_pred_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << u2  << "_pred_" << likep[i]->predictor_name << "   ";
            }
          }

        }

      for (i=0;i<likep.size();i++)
        {
        if (likep[i]->outexpectation)
          {
          outres << "pmean_E_" << likep[i]->predictor_name << "   ";

          if (optionsp->samplesize > 1)
            {
            outres << "pqu"  << l1  << "_E_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << l2  << "_E_" << likep[i]->predictor_name << "   ";
            outres << "pmed_E_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << u1  << "_E_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << u2  << "_E_" << likep[i]->predictor_name << "   ";
            }
          }
        }


      for (i=0;i<likep.size();i++)
        {

        if (likep[i]->outpredictor)
          {
          outres << "pmean_" << likep[i]->predictor_name << "   ";

          if (optionsp->samplesize > 1)
            {
            outres << "pqu"  << l1  << "_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << l2  << "_" << likep[i]->predictor_name << "   ";
            outres << "pmed_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << u1  << "_" << likep[i]->predictor_name << "   ";
            outres << "pqu"  << u2  << "_" << likep[i]->predictor_name << "   ";
            }
          }

        }

      outres << "quantile_res quadratic_score logarithmic_score spherical_score CRPS";

      outres << endl;

      double * workmean = betamean.getV();
      double * workbetaqu_l1_lower_p = betaqu_l1_lower.getV();
      double * workbetaqu_l2_lower_p = betaqu_l2_lower.getV();
      double * workbetaqu_l1_upper_p = betaqu_l1_upper.getV();
      double * workbetaqu_l2_upper_p = betaqu_l2_upper.getV();
      double * workbetaqu50 = betaqu50.getV();



      for(i=0;i<designmatrix.rows();i++)
        {

        outres << (i+1) << "   ";

        for (j=0;j<designmatrix.cols();j++)
          outres << designmatrix(i,j) << "   ";

        // predictor
        for (j=0;j<likep.size();j++,
            workmean++,
            workbetaqu_l1_lower_p++,
            workbetaqu_l2_lower_p++,
            workbetaqu50++,
            workbetaqu_l1_upper_p++,
            workbetaqu_l2_upper_p++)
          {

          if (likep[j]->outpredictor)
            {

            outres << *workmean << "   ";

            if (optionsp->samplesize > 1)
              {
              outres << *workbetaqu_l1_lower_p << "   ";
              outres << *workbetaqu_l2_lower_p << "   ";
              outres << *workbetaqu50 << "   ";
              outres << *workbetaqu_l2_upper_p << "   ";
              outres << *workbetaqu_l1_upper_p << "   ";
              }
            }
          }
        // end: predictor

        // begin: mu
        for (j=0;j<likep.size();j++,
            workmean++,
            workbetaqu_l1_lower_p++,
            workbetaqu_l2_lower_p++,
            workbetaqu50++,
            workbetaqu_l1_upper_p++,
            workbetaqu_l2_upper_p++)
          {

          if (likep[j]->outexpectation)
            {
            outres << *workmean << "   ";


            if (optionsp->samplesize > 1)
              {
              outres << *workbetaqu_l1_lower_p << "   ";
              outres << *workbetaqu_l2_lower_p << "   ";
              outres << *workbetaqu50 << "   ";
              outres << *workbetaqu_l2_upper_p << "   ";
              outres << *workbetaqu_l1_upper_p << "   ";
              }
            }
          }
        // end: mu

        // parameter
        for (j=0;j<likep.size();j++,
            workmean++,
            workbetaqu_l1_lower_p++,
            workbetaqu_l2_lower_p++,
            workbetaqu50++,
            workbetaqu_l1_upper_p++,
            workbetaqu_l2_upper_p++)


          {

          if (likep[j]->outpredictor)
            {
            outres << *workmean << "   ";
            workmeanmat[j] = workmean;

            if (optionsp->samplesize > 1)
              {
              outres << *workbetaqu_l1_lower_p << "   ";
              outres << *workbetaqu_l2_lower_p << "   ";
              outres << *workbetaqu50 << "   ";
              outres << *workbetaqu_l2_upper_p << "   ";
              outres << *workbetaqu_l1_upper_p << "   ";
              }
            }
          }
        // end: parameter

          outres << likep[likep.size()-1]->compute_quantile_residual_mult(responsep,workmeanmat,weightpmat,auxhelp) << "   ";
          outres << likep[likep.size()-1]->compute_quadr_mult()    << "   ";
          outres << likep[likep.size()-1]->compute_log_mult()    << "   ";
          outres << likep[likep.size()-1]->compute_spherical_mult()    << "   ";
          outres << likep[likep.size()-1]->compute_CRPS_mult()    << "   ";

        if (i < designmatrix.rows()-1)
          {
          for (j=0;j<likep.size();j++)
            {
            weightpmat[j]++;
            responsep[j]++;
            }
          }

          outres << endl;
        }

      } // end: if (nosamplessave==false)
    else
      {

      for (i=0;i<likep.size();i++)
        {
        if (likep[i]->outpredictor)
          outres << "pmean_pred_" << likep[i]->predictor_name << "   ";
        }

      for (i=0;i<likep.size();i++)
        {
        if (likep[i]->outexpectation)
          outres << "pmean_E_" << likep[i]->predictor_name << "   ";
        }

      for (i=0;i<likep.size();i++)
        {
        if (likep[i]->outpredictor)
          outres << "pmean_param_" << likep[i]->predictor_name << "   ";
        }

      outres << "quantile_res quadratic_score logarithmic_score spherical_score CRPS";

      outres << endl;

      double * workmean = betamean.getV();

      for(i=0;i<designmatrix.rows();i++)
        {

        outres << (i+1) << "   ";

        for (j=0;j<designmatrix.cols();j++)
          outres << designmatrix(i,j) << "   ";

        for (j=0;j<likep.size();j++,workmean++)
          {
          if (likep[j]->outpredictor)
            outres << *workmean << "   ";
          }

        for (j=0;j<likep.size();j++,workmean++)
          {
          if (likep[j]->outexpectation)
            outres << *workmean << "   ";
          }

        for (j=0;j<likep.size();j++,workmean++)
          {
          if (likep[j]->outpredictor)
            outres << *workmean << "   ";
            workmeanmat[j] = workmean;
          }


        outres << likep[likep.size()-1]->compute_quantile_residual_mult(responsep,workmeanmat,weightpmat,auxhelp) << "   ";
        outres << likep[likep.size()-1]->compute_quadr_mult()    << "   ";
        outres << likep[likep.size()-1]->compute_log_mult()    << "   ";
        outres << likep[likep.size()-1]->compute_spherical_mult()    << "   ";
        outres << likep[likep.size()-1]->compute_CRPS_mult()    << "   ";

//        std::ofstream out;
//  // helpmat1.prettyPrint(out);
//    out.open ("C:\\tmp\\res.raw", std::ofstream::out | std::ofstream::app);
//    out << *responsep[1] ;
//    out << " " ;
//    out << *responsep[0] ;
//    out << " " ;
//    out << *workmeanmat[1] ;
//    out << " " ;
//    out << *workmeanmat[0] ;
//    out << " " ;
//    out << *weightpmat[1] ;
//    out << " " ;
//    out << *weightpmat[0] ;
//    out << " " ;
//    out << likep[likep.size()-1]->compute_quantile_residual_mult(responsep,workmeanmat,weightpmat,auxhelp) << endl;


        outres << endl;

        if (i < designmatrix.rows()-1)
          {
          for (j=0;j<likep.size();j++)
            {
            weightpmat[j]++;
            responsep[j]++;
            }
          }

        }

      }

     outresults_deviance();
     outresults_DIC(out_stata,out_R,pathresults);


    }   // end if (pathresults.isvalidfile() != 1)

  }
Esempio n. 4
0
void FC_nonp_variance::outresults(ofstream & out_stata,ofstream & out_R,
                                  const ST::string & pathresults)
  {

  FC::outresults(out_stata,out_R,"");

  ST::string l1 = ST::doubletostring(optionsp->lower1,4);
  ST::string l2 = ST::doubletostring(optionsp->lower2,4);
  ST::string u1 = ST::doubletostring(optionsp->upper1,4);
  ST::string u2 = ST::doubletostring(optionsp->upper2,4);

  ST::string nl1 = ST::doubletostring(optionsp->lower1,4);
  ST::string nl2 = ST::doubletostring(optionsp->lower2,4);
  ST::string nu1 = ST::doubletostring(optionsp->upper1,4);
  ST::string nu2 = ST::doubletostring(optionsp->upper2,4);
  nl1 = nl1.replaceallsigns('.','p');
  nl2 = nl2.replaceallsigns('.','p');
  nu1 = nu1.replaceallsigns('.','p');
  nu2 = nu2.replaceallsigns('.','p');

  ST::string vstr;


  if (optionsp->samplesize > 1)
    {

    vstr = "    Mean:         ";
    optionsp->out(vstr + ST::string(' ',20-vstr.length()) +
    ST::doubletostring(betamean(0,0),6) + "\n");

    vstr = "    Std. dev.:    ";

    optionsp->out(vstr + ST::string(' ',20-vstr.length()) +
    ST::doubletostring(sqrt(betavar(0,0)),6) + "\n");

    vstr = "    " + l1 + "% Quantile: ";
    optionsp->out(vstr + ST::string(' ',20-vstr.length()) +
    ST::doubletostring(betaqu_l1_lower(0,0),6) + "\n");

    vstr = "    " + l2 + "% Quantile: ";
    optionsp->out(vstr + ST::string(' ',20-vstr.length()) +
    ST::doubletostring(betaqu_l2_lower(0,0),6) + "\n");

    vstr = "    50% Quantile: ";
    optionsp->out(vstr + ST::string(' ',20-vstr.length()) +
    ST::doubletostring(betaqu50(0,0),6) + "\n");

    vstr = "    " + u1 + "% Quantile: ";
    optionsp->out(vstr + ST::string(' ',20-vstr.length()) +
    ST::doubletostring(betaqu_l2_upper(0,0),6) + "\n");

    vstr = "    " + u2 + "% Quantile: ";
    optionsp->out(vstr + ST::string(' ',20-vstr.length()) +
    ST::doubletostring(betaqu_l1_upper(0,0),6) + "\n");

    optionsp->out("\n");

    }
  else
    {
    optionsp->out("    Smoothing parameter: " +
    ST::doubletostring(betamean(0,1),6) + "\n");

    optionsp->out("\n");
    }

//  out_R << "term=" << title <<  ";" << endl;

  if (pathresults.isvalidfile() != 1)
    {

    optionsp->out("    Results for the variance component are also stored in file\n");
    optionsp->out("    " +  pathresults + "\n");
    optionsp->out("\n");

    ST::string paths = pathresults.substr(0,pathresults.length()-4) +
                                 "_sample.raw";

    out_R << "pathvarsample=" << paths << endl; 
//    out_R << "filetype=param; path=" << pathresults << ";" <<  endl;

    ofstream ou(pathresults.strtochar());

    if (optionsp->samplesize > 1)
      {
      ou << "pmean  pstd  pqu"  << nl1 << "   pqu" << nl2 << "  pmed pqu" <<
      nu1 << "   pqu" << nu2 << endl;
      }
    else
      {
      ou << "pmean" << endl;
      }

    ou << betamean(0,0) << "  ";
    if (optionsp->samplesize > 1)
      {
      if (betavar(0,0) < 0.0000000000001)
        ou << 0 << "  ";
      else
        ou << sqrt(betavar(0,0)) << "  ";
      ou << betaqu_l1_lower(0,0) << "  ";
      ou << betaqu_l2_lower(0,0) << "  ";
      ou << betaqu50(0,0) << "  ";
      ou << betaqu_l2_upper(0,0) << "  ";
      ou << betaqu_l1_upper(0,0) << "  " << endl;
      }

    optionsp->out("\n");
    }

  }
Esempio n. 5
0
void FC_cv::outresults(ofstream & out_stata, ofstream & out_R,
                            const ST::string & pathresults)
  {


  if (pathresults.isvalidfile() != 1)
    {

    FC::outresults(out_stata,out_R,pathresults);

    optionsp->out("  Marshall-Spiegelhalter Cross Validation: \n",true);
    optionsp->out("\n");

    optionsp->out("    Estimated individual observation samples are stored in\n");
    optionsp->out("    " +  pathresults + "\n");
    optionsp->out("\n");


    ST::string pathresults_like = pathresults.substr(0,pathresults.length()-4)+
                                  "_like.res";

    FC_sampled_l.outresults(out_stata,out_R,pathresults_like);

    optionsp->out("    Estimated individual observation likelihoods are stored in\n");
    optionsp->out("    " +  pathresults_like + "\n");
    optionsp->out("\n");



//    unsigned nrobs = sampled_etas.rows();
    unsigned i;

    /*
    ofstream outres(pathresults.strtochar());

    for(j=0;j<sampled_etas.cols();j++)
      outres << "s_eta_" << (j+1) << "  ";

    for(j=0;j<sampled_etas.cols();j++)
      outres << "s_resp_" << (j+1) << "  ";

    outres << endl;

    for (i=0;i<nrobs;i++)
      {

      for(j=0;j<sampled_etas.cols();j++)
        outres << sampled_etas(i,j) << "  ";

      for(j=0;j<sampled_responses.cols();j++)
        outres << sampled_responses(i,j) << "  ";

      outres << endl;

      }
     */

    // Energy score

    double es = compute_energyscore();


    ST::string pathresults_e = pathresults.substr(0,pathresults.length()-4)+
                               "_energy.res";


    ofstream out2(pathresults_e.strtochar());
    out2 << "id   score" << endl;

    for (i=0;i<e_score.rows();i++)
      out2 << effectvalues[i] << "  " << e_score(i,0) << endl;

    // Log-score


    double ls = compute_logscore();

    ST::string pathresults_l = pathresults.substr(0,pathresults.length()-4)+
                               "_logscore.res";

    ofstream out3(pathresults_l.strtochar());
    out3 << "id   score" << endl;

    for (i=0;i<e_score.rows();i++)
      out3 << effectvalues[i] << "  " << log_score(i,0) << endl;

    optionsp->out("    Estimated energy scores are stored in\n");
    optionsp->out("    " +  pathresults_e + "\n");
    optionsp->out("\n");

    optionsp->out("    Estimated log-scores are stored in\n");
    optionsp->out("    " +  pathresults_l + "\n");
    optionsp->out("\n");

    optionsp->out("    Mean energy score: " + ST::doubletostring(es,8) + "\n");
    optionsp->out("    Mean log score: " + ST::doubletostring(ls,8) + "\n");


    }   // end if (pathresults.isvalidfile() != 1)


  }