コード例 #1
0
ファイル: LogitSampler.cpp プロジェクト: Hkey1/boom
 void LS::impute_latent_data(){
   double log_alpha = mod_->log_alpha();
   const std::vector<Ptr<BRD> > & dat(mod_->dat());
   uint n = dat.size();
   suf_->clear();
   Vec beta(mod_->beta());
   for(uint i=0; i<n; ++i){
     Ptr<BRD> dp = dat[i];
     const Vec &x(dp->x());
     double eta = mod_->predict(x) + log_alpha;
     double z = draw_z(dp->y(), eta);
     double lam = draw_lambda(fabs(z- eta));
     suf_->add_data(x,z, 1.0/lam);
   }
 }
コード例 #2
0
void integration(TDirectory *d)
{
    TCanvas *cl = new TCanvas("cl", "Lambda Integrations", 800, 600);
    draw_axis_lambda();

    TCanvas *ct = new TCanvas("ct", "TOF Integrations", 800, 600);
    draw_axis_tof();

    gStyle->SetTextColor(kBlue);
    gStyle->SetTextSize(0.04);

    TLegend *llambda = new TLegend(LEGEND_X1, LEGEND_Y1, LEGEND_X2, LEGEND_Y2);
    TLegend *ltof = new TLegend(LEGEND_X1, LEGEND_Y1, LEGEND_X2, LEGEND_Y2);

    TList *l = d->GetListOfKeys();
    const Int_t size = l->GetSize();
    Int_t count = 0;
    Double_t intgl = 0, lambda = 0, sum_intgl = 0., sum_lambda = 0.;
    Double_t intgt = 0, tof = 0, sum_intgt = 0., sum_tof = 0.;
    for(Int_t i = 1; i < size-2; i++)
    {
        TKey *k = l->At(i);
        TString run = k->GetName();
        if(run.BeginsWith("run"))
        {
            cout << run << endl;
            TDirectory *dd = d->Get(run);

            cl->cd();
            TGraph *gl = draw_lambda(dd, "psame", &intgl, &lambda);
            sum_intgl += intgl;
            sum_lambda += lambda;
            llambda->AddEntry(gl, run);

            ct->cd();
            TGraph *gt = draw_tof(dd, "psame", &intgt, &tof);
            sum_intgt += intgt;
            sum_tof += tof;
            ltof->AddEntry(gt, run);

            count ++;
        }
    }
    
    const Double_t ave_intgl = sum_intgl / count;
    const Double_t ave_lambda = sum_lambda / count;

    const Double_t ave_intgt = sum_intgt / count;
    const Double_t ave_tof = sum_tof / count;
    cout << "Average" << endl;
    cout << "  L "
         << TString::Format("%10.2f", ave_lambda) << " "
         << TString::Format("%10.2f", ave_intgl) << endl;
    cout << "  T "
         << TString::Format("%10.2f", ave_tof) << " "
         << TString::Format("%10.2f", ave_intgt) << endl;

    const Int_t ave_n = 1;

    cl->cd();
    Double_t ave_xxl[] = { ave_lambda };
    Double_t ave_yyl[] = { ave_intgl };
    Double_t ave_xxel[] = { ave_lambda * 0.1 };
    Double_t ave_yyel[] = { ave_intgl * 0.1 };
    TGraphErrors *glave = new TGraphErrors(ave_n, ave_xxl, ave_yyl, ave_xxel, ave_yyel);
    glave->Draw("psame");
    llambda->AddEntry(glave, "Average");
    llambda->Draw();

    ct->cd();
    Double_t ave_xxt[] = { ave_tof };
    Double_t ave_yyt[] = { ave_intgt };
    Double_t ave_xxet[] = { ave_tof * 0.1 };
    Double_t ave_yyet[] = { ave_intgt * 0.1 };
    TGraphErrors *gtave = new TGraphErrors(ave_n, ave_xxt, ave_yyt, ave_xxet, ave_yyet);
    gtave->Draw("psame");
    ltof->AddEntry(gtave, "Average");
    ltof->Draw();
}