コード例 #1
0
ファイル: clistatstest.cpp プロジェクト: dpmcmlxxvi/clistats
/**
 * Test DataFilters
 */
void test_datafilters()
{

    std::vector<std::string> datas;
    datas.push_back("1");
    datas.push_back("2");
    datas.push_back("3");
    
    DataVector datav;
    datav.push_back(DataPoint(1,true));
    datav.push_back(DataPoint(2,true));
    datav.push_back(DataPoint(3,true));

    DataFilters filters;
    ASSERT(filters.isFiltered(datas), "DataFilters::isFiltered failed on string vector with no filter");
    ASSERT(filters.isFiltered(datav), "DataFilters::isFiltered failed on data vector with no filter");

    filters.addNumericFilter(0,1,1,true);
    ASSERT(filters.isFiltered(datav), "DataFilters::isFiltered failed on data vector with numeric accepting filter on 0");
    
    filters.addNumericFilter(1,4,4,false);
    ASSERT(filters.isFiltered(datav), "DataFilters::isFiltered failed on data vector with numeric rejection filter on 1");

    filters.addStringFilter(0,"1",true,true,true);
    ASSERT(filters.isFiltered(datas), "DataFilters::isFiltered failed on data vector with string accepting filter on 0");
    
    filters.addStringFilter(1,"4",true,true,false);
    ASSERT(filters.isFiltered(datas), "DataFilters::isFiltered failed on data vector with string rejection filter on 1");

}
コード例 #2
0
ファイル: clistatstest.cpp プロジェクト: dpmcmlxxvi/clistats
/**
 * Test DataVector
 */
void test_datavector()
{

    DataVector src;
    src.push_back(DataPoint(1,true));
    src.push_back(DataPoint(2,true));
    src.push_back(DataPoint(3,true));

    std::vector<bool> mask(3,true);
    DataVector dst;
    
    dst.copy(src,mask);
    ASSERT_EQUAL(dst.at(0).value, 1, "DataVector::copy value failed on enabled data point at 0");
    ASSERT(dst.at(0).active, "DataVector::copy active failed on enabled data point at 0");
    ASSERT_EQUAL(dst.at(1).value, 2, "DataVector::copy value failed on enabled data point at 1");
    ASSERT(dst.at(1).active, "DataVector::copy active failed on enabled data point at 1");
    ASSERT_EQUAL(dst.at(2).value, 3, "DataVector::copy value failed on enabled data point at 2");
    ASSERT(dst.at(2).active, "DataVector::copy active failed on enabled data point at 2");

    src.deactivate();
    dst.clear();
    dst.copy(src,mask);
    ASSERT_EXCEPTION(dst.at(0), "DataVector::copy failed on disabled data point at 0");
    ASSERT_EXCEPTION(dst.at(1), "DataVector::copy failed on disabled data point at 1");
    ASSERT_EXCEPTION(dst.at(2), "DataVector::copy failed on disabled data point at 2");

}
コード例 #3
0
ファイル: model.cpp プロジェクト: ns-barzakov/math-modeling
SimulResult Model::simulate(double sim_time) {
    int nresults = int(ceil(sim_time / result_step));
    std::vector<DataPoint> result;
    result.reserve(nresults);

    result.push_back(this->initial_cond);

    DataPoint prev = this->initial_cond;
    DataPoint curr = DataPoint();

    while (prev.time < sim_time) {
        double s_to_i = this->infect_prob * prev.S * prev.I;
        double i_to_r = this->recovery_rate * prev.I;

        curr.S = prev.S - s_to_i * sim_step;
        curr.I = prev.I + (s_to_i - i_to_r) * sim_step;
        curr.R = prev.R + i_to_r * sim_step;
        curr.time = prev.time + sim_step;

        curr.S = std::max(curr.S, 0.0);
        curr.I = std::max(curr.I, 0.0);

        if (int(curr.time / result_step) > int(prev.time / result_step)) {
            result.push_back(curr);
        }

        prev = curr;
    }

    return SimulResult(std::move(result));
}
コード例 #4
0
CrossSection calculateRelativeDiff(CrossSection a, CrossSection b)
{
    CrossSection relative; 

    DataSet aData = a.getDataSet();
    DataSet bData = b.getDataSet();

    if(aData.getNumberOfPoints()!=bData.getNumberOfPoints())
    {
        cerr << "Error: can't calculate relative cross section from "
             << "data sets of different sizes. Returning empty cross section."
             << endl;
        return relative;
    }

    DataSet relativeDataSet;

    // for each point, calculate the relative cross section, including error
    for(int i=0; i<aData.getNumberOfPoints(); i++)
    {
        DataPoint aPoint = aData.getPoint(i);
        DataPoint bPoint = bData.getPoint(i);

        double aXValue = aPoint.getXValue();
        double bXValue = bPoint.getXValue();
        
        if(aXValue != bXValue)
        {
            cerr << "Error: can't calculate relative cross section from "
                 << "data points with different x values. Returning cross section."
                 << endl;
            return relative;
        }

        double aYValue = aPoint.getYValue();
        double bYValue = bPoint.getYValue();

        double yValue = (aYValue-bYValue)/(aYValue+bYValue);

        // calculate cross section error
        double aError = getPartialError(aPoint, bPoint, a.getArealDensity());
        double bError = getPartialError(bPoint, aPoint, b.getArealDensity());
        double totalError = pow(pow(aError,2)+pow(bError,2),0.5);

        relativeDataSet.addPoint(
                DataPoint(aXValue, aPoint.getXError(), 100*yValue, 100*totalError, /* convert to % */
                          aPoint.getBlankMonitorCounts()+bPoint.getBlankMonitorCounts(),
                          aPoint.getTargetMonitorCounts()+bPoint.getTargetMonitorCounts(),
                          aPoint.getBlankDetCounts()+bPoint.getBlankDetCounts(),
                          aPoint.getTargetDetCounts()+bPoint.getTargetDetCounts()));
    }

    relative.addDataSet(relativeDataSet);
    return relative;
}
コード例 #5
0
ファイル: dataset.cpp プロジェクト: jelmervdl/vistool
vector<DataPoint> getDataPoints(path p, size_t label, string catname){
  vector<DataPoint> dps;
  directory_iterator end_itr;
  for ( directory_iterator sitr(p); sitr != end_itr; ++sitr){
    if(is_image(sitr->path().extension().string())){
      string filename = (string) sitr->path().filename().c_str();
      string fileurl = (string) sitr->path().string().c_str();
      dps.push_back(DataPoint(label, filename, fileurl, catname));
    }
  }
  return dps;
}
コード例 #6
0
ファイル: dataset.cpp プロジェクト: ketilwright/FnPlot
DataSet::DataSet(double min, double max, double step)
{
    m_numPts = 0;
    double x = min;
    while(x < max)
    {
        m_data.push_back(DataPoint(x, sin(x) / x));

        x += step;
        m_numPts++;
    }
}
コード例 #7
0
ファイル: dataset.cpp プロジェクト: ketilwright/FnPlot
void DataSet::compute(double min, double max, double step, computeFunc f)
{
    m_data.clear();
    m_numPts = 0;
    double x = min;
    while(x < max)
    {
        m_data.push_back(DataPoint(x, f(x)));
        x += step;
        ++m_numPts;
    }
}
コード例 #8
0
ファイル: clistatstest.cpp プロジェクト: dpmcmlxxvi/clistats
/**
 * Test MultivariateTracker
 */
void test_multivariatetracker()
{

    DataVector data1, data2, data3;
    data1.push_back(DataPoint(1,true));
    data1.push_back(DataPoint(3,true));
    data2.push_back(DataPoint(2,true));
    data2.push_back(DataPoint(2,true));
    data3.push_back(DataPoint(3,true));
    data3.push_back(DataPoint(1,true));

    StatisticsTrackerOptions options;
    options.doCov = options.doMax = options.doMean = options.doMin = options.doVar = true;
    MultivariateTracker tracker(2, options);

    tracker.update(data1);
    tracker.update(data2);
    tracker.update(data3);

    double cov = 2.0/3.0;
    ASSERT_EQUAL(tracker.getCovariance(0,0), cov, "StatisticsTracker::getCovariance failed on (0,0)");
    ASSERT_EQUAL(tracker.getCovariance(0,1), -cov, "StatisticsTracker::getCovariance failed on (0,1)");
    ASSERT_EQUAL(tracker.getCovariance(1,0), -cov, "StatisticsTracker::getCovariance failed on (1,0)");
    ASSERT_EQUAL(tracker.getCovariance(1,1), cov, "StatisticsTracker::getCovariance failed on (1,1)");

}
コード例 #9
0
ファイル: reporter.cpp プロジェクト: syershov/omim
void Reporter::AddLocation(location::GpsInfo const & info)
{
  lock_guard<mutex> lg(m_mutex);

  if (info.m_horizontalAccuracy > kRequiredHorizontalAccuracy)
    return;

  if (info.m_timestamp < m_lastGpsTime + kMinDelaySeconds)
    return;

  m_lastGpsTime = info.m_timestamp;
  m_input.push_back(DataPoint(info.m_timestamp, ms::LatLon(info.m_latitude, info.m_longitude)));
}
コード例 #10
0
ファイル: Communications.cpp プロジェクト: 9mlb2/490
//you will need to change
Communication::Communication(string comPort): q(),file("C:\\Users\\Megan Gardner\\GitHub\\490\\logOutput.log",ios::out){
    mutex = false;
    file<<"begin"<<endl;
    io = new io_service();
    port = new serial_port(*io,comPort);
    //port->set_option(serial_port_base::baud_rate(9600));
    port->set_option(serial_port_base::baud_rate(57600)); //to match baud rate of acc/gyro

    data = new vector<DataPoint>();
    data->push_back(DataPoint(QPoint(99,65),0)); //remove these when you have actual data
    data->push_back(DataPoint(QPoint(115,117),0));
    data->push_back(DataPoint(QPoint(35,158),0)); //remove these when you have actual data
    data->push_back(DataPoint(QPoint(93,214),0));
    data->push_back(DataPoint(QPoint(47,244),0)); //remove these when you have actual data
    data->push_back(DataPoint(QPoint(85,324),0));

    if(port->is_open())
        cout<<"Opened "<<comPort<<endl;
}
コード例 #11
0
ファイル: datatable.cpp プロジェクト: bgrimstad/splinter
void DataTable::addSample(std::vector<double> x, double y)
{
    addSample(DataPoint(x, y));
}
コード例 #12
0
ファイル: datatable.cpp プロジェクト: bgrimstad/splinter
void DataTable::addSample(double x, double y)
{
    addSample(DataPoint(x, y));
}
コード例 #13
0
//Default constructor
Headings::Headings()
{
	DataPoint();
}
コード例 #14
0
void BayesUnfoldingExample641()
{

#ifdef __CINT__ // Avoid CINT badness
  Printf("Please compile this script (root BayesUnfoldingExample641.C+) "
         "or use ROOT 6.");
  gSystem->Exit(0);
#endif

  if (!gROOT->IsBatch())
  {
    Printf("Several canvases coming...adding -b flag.");
    gROOT->SetBatch();
  }

  gStyle->SetOptStat(0);
  gStyle->SetPaintTextFormat(".2f");

  if (gSystem->Getenv("TMPDIR"))
    gSystem->SetBuildDir(gSystem->Getenv("TMPDIR"));

  TRandom3 ran;
  TStopwatch watch; // Watch starts here. A call to Start() would reset it.

  TObjArray *cList = new TObjArray(); // List of drawn canvases --> PDF file

  // Set up the problem
  double bins[Nt+1] = {0};
  for (int j=0; j<=Nt; j++)
    bins[j] = 500*TMath::Exp(0.15*j);

  TestProblem testprob = AtlasDiJetMass(Nt, Nr, bins, bins,
                                        apar, bpar, nevts, evtWeight);
  TH2D *hM   = testprob.Response;
  TH1D *hT   = testprob.xTruth;
  TH1D *hTmc = testprob.xTruthEst;
  TH1D *hMt  = testprob.xIni;
  TH1D *hD   = testprob.bNoisy;
  TH1D *heff = testprob.eff;
  SetHistProps(hT,kRed+2,kNone,kRed+2);
  SetHistProps(hTmc,kRed,kNone,kRed);
  SetHistProps(hD,kBlack,kNone,kBlack,kFullCircle,1.5);

  TMatrixD M   = MatrixUtils::Hist2Matrix(hM);
  TVectorD T   = MatrixUtils::Hist2Vec(hT);   // \hat{T}
  TVectorD Tmc = MatrixUtils::Hist2Vec(hTmc); // \tilde{T}
  TVectorD D   = MatrixUtils::Hist2Vec(hD);
  TVectorD eff = MatrixUtils::Hist2Vec(heff);
  TVectorD Pt  = MatrixUtils::ElemDiv(MatrixUtils::Hist2Vec(hMt), eff); // P(t)
  TMatrixD Prt = MatrixUtils::DivRowsByVector(M, Pt);  // P(r|t)

  // Compute initial sampling volume and do MCMC sampling
  TGraphAsymmErrors *box = HyperBox(hTmc);
  SetGraphProps(box, kGreen+2, kNone, kSpring, kFullSquare, 1.0);

  // Likelihood functor
  LogPoissonLikeFn llfunc(Prt, D);

  // Curvature regularization.
  // Note that this is not directly penalizing curvature of the solution.
  // Instead it smooths the solution divided by the trial spectrum.
  std::vector<double> regpars;
  regpars.push_back(alpha);  // Regularization strength
  for (int i=0; i<box->GetN(); i++)
    regpars.push_back(box->GetY()[i]);

  CurvatureRegFn regfunc(regpars);

  TTree *tmcmc = SampleMH(nMcmcSamples, 1e4, 0.01, box, llfunc, regfunc);

  // Create marginal prob. distributions from MCMC
  std::cout << Form("Marginalizing parameters from Markov chain...")
            << std::flush;

  TH1D *hMCMC[Nt];
  for (int t=0; t<Nt; t++)
  {
    double tlo = box->GetY()[t] - box->GetEYlow()[t];
    double thi = box->GetY()[t] + box->GetEYhigh()[t];
    hMCMC[t] = new TH1D(Form("hMCMC%d",t),"",nMcmcBins, tlo, thi);
    hMCMC[t]->SetTitle(Form("MCMC - point %d;"
                            "entries;"
                            "Marginal posterior probability",t));

    // Marginalize with unit weight when using MCMC, weight by
    // likelihood if sampling was uniform.
    tmcmc->Draw(Form("T%d >> hMCMC%d",t,t), "", "goff");
    hMCMC[t]->Scale(1./hMCMC[t]->Integral(1, nMcmcBins));
    SetHistProps(hMCMC[t], kBlack, kYellow, kBlack, kFullCircle, 1.0);
    hMCMC[t]->GetYaxis()->SetTitleOffset(1.5);
  }
  Printf("Done marginalizing MCMC.");

  // Now compute reduced sampling volume, and do uniform sampling
  TGraphAsymmErrors *rbox = ReducedSamplingVolume(hMCMC, box);
  SetGraphProps(rbox, kBlack, kNone, kNone, kFullSquare, 1.0);
  TH1D *hFlat[Nt];
  if (doUniformSampling)
  {
    TTree *tflat = SampleUniform(nFlatSamples, D, Prt, rbox);
    std::cout << Form("Marginalizing parameters from uniform volume...")
              << std::flush;

    for (int t=0; t<Nt; t++)
    {
      double tlo = rbox->GetY()[t] - rbox->GetEYlow()[t];
      double thi = rbox->GetY()[t] + rbox->GetEYhigh()[t];
      hFlat[t] = new TH1D(Form("hFlat%d",t),"",nFlatBins, tlo, thi);
      hFlat[t]->SetTitle(Form("Uniform sampling - point %d;"
                              "dijet mass (GeV/c^{2});"
                              "Marginal posterior probability",t));

      tflat->Draw(Form("T%d >> hFlat%d",t,t), "L", "goff");
      hFlat[t]->Scale(1./hFlat[t]->Integral(1,nFlatBins));
      SetHistProps(hFlat[t], kBlack, kOrange, kBlack, kFullCircle, 1.0);
    }
    Printf("Done marginalizing uniform volume.");
  }

  // Unfolded spectrum from MCMC
  TGraphErrors *unf1 = new TGraphErrors();
  SetGraphProps(unf1, kBlue, kNone, kBlue, kOpenSquare, 1.5);
  unf1->SetLineWidth(2);
  for (int t=0; t<Nt; t++)
  {
    MaxDensityInterval mdi = GetMDI(hMCMC[t], 0.68);
    unf1->SetPoint(t, hD->GetBinCenter(t+1), mdi.u);
    unf1->SetPointError(t, 0.48*hD->GetBinWidth(t+1), mdi.du);
  }

  // Unfolded spectrum from uniform sampling after volume reduction
  TGraphErrors *unf2 = 0;
  if (doUniformSampling)
  {
    unf2 = new TGraphErrors();
    SetGraphProps(unf2, kRed, kNone, kRed, kOpenSquare, 1.5);
    unf2->SetLineWidth(2);

    for (int t=0; t<Nt; t++)
    {
      MaxDensityInterval mdi = GetMDI(hFlat[t], 0.68);
      unf2->SetPoint(t, hD->GetBinCenter(t+1), mdi.u);
      unf2->SetPointError(t, 0.47*hD->GetBinWidth(t+1), mdi.du);
    }
  }

  Printf("Drawing results...");
  DrawObject(hM, "colz", "matrix", cList, 550, 500);
  gPad->SetLogx();  gPad->SetLogy();  gPad->SetLogz();
  gPad->SetRightMargin(0.15);

  DrawObject(heff, "", "efficiency", cList);

  // Draw marginal dists. from MCMC
  for (int t=0; t<Nt; t++)
  {
    DrawObject(hMCMC[t], "", Form("post_%d", t), cList);
    gPad->SetLeftMargin(0.15);

    if (doUniformSampling)
    {
      hFlat[t]->Scale(1./hFlat[t]->Integral(1, nFlatBins,"width"));
      hFlat[t]->Draw("same");
    }

    double ymin = hMCMC[t]->GetMinimum();
    double ymax = hMCMC[t]->GetMaximum();
    double yDraw = 0.25*(ymax-ymin);
    DataPoint(hD, hMCMC[t], t, 0.75*yDraw)->Draw("ep same");
    TruePoint(hT, hMCMC[t], t, yDraw)->Draw("p same");
    MD68Point(hMCMC[t], yDraw)->Draw("ep same");
  }

  // Result!
  hT->GetYaxis()->SetRangeUser(0.002, 101*nevts*evtWeight);
  DrawObject(hT, "ep", "result", cList);
  gPad->SetLogy();
  box->Draw("e5 same");
  if (doUniformSampling || drawReducedVolume)
    rbox->Draw("e5 same");
  hT->Draw("same");
  hD->Draw("ep same");
  unf1->Draw("ep same");
  if (unf2)
    unf2->Draw("ep same");

  if (printPDFs)
  {
    PrintPDFs(cList, "pdfs"); // Print individuals into ./pdfs dir
    PrintPDF(cList, "pdfs/mcmc_unfold_example"); // Multipage PDF
  }

  Printf("All done.");
  watch.Stop();
  watch.Print();

  return;
}
コード例 #15
0
ファイル: DataPoint.cpp プロジェクト: tttyy/Active-Learning
DataPoint DataPoint::clone()
{
    return DataPoint(*this);
}
コード例 #16
0
ファイル: datatable.cpp プロジェクト: bgrimstad/splinter
void DataTable::addSample(DenseVector x, double y)
{
    addSample(DataPoint(x, y));
}
コード例 #17
0
void Profile::loadDefaultProfile() {

  QString defaultName = "default.json";

  // Check if default profile exists on disk
  QFile file(defaultName);

  if(file.exists()) {
    loadProfile(defaultName, false);
    return;
  }

  // Default profile does not exist, we need to create one
  profileName = "Default lead free";

//  dataPoints.append(DataPoint(0,25));      // Starting temp
//  dataPoints.append(DataPoint(90,150));    // Pre Heat
//  dataPoints.append(DataPoint(180,217));   // End of soak
//  dataPoints.append(DataPoint(225,245));   // Peak temp
//  dataPoints.append(DataPoint(270,217));   // End of reflow zone
//  dataPoints.append(DataPoint(337.5,25));  // End of profile

  dataPoints.append(DataPoint(0,25));      // Starting temp
  dataPoints.append(DataPoint(90,150));    // Pre Heat
  dataPoints.append(DataPoint(112.5,200)); // End of soak
  dataPoints.append(DataPoint(121.4,217)); // Ramp to 217


  dataPoints.append(DataPoint(159.4,255)); // Ramp to 255
  dataPoints.append(DataPoint(166.6,260)); // Peak
  dataPoints.append(DataPoint(178.6,260)); // End of peak
  dataPoints.append(DataPoint(185.8,255)); // Ramp down to 255


  dataPoints.append(DataPoint(205,217));   // End of reflow zone
  dataPoints.append(DataPoint(234.1,150)); // End of profile
  dataPoints.append(DataPoint(290,25));    // Cool down

  // Save the new default profiel
  saveProfile(defaultName);
}
コード例 #18
0
ファイル: DataPoint.cpp プロジェクト: 9mlb2/490
DataPoint::DataPoint(int x, int y, qint16 v){
    DataPoint(QPoint(x,y),v);
}