Ejemplo n.º 1
0
void ALEXHistogramsWidget::plotHistogramS()
{
    // pr histogram
    plot=ui->widPlotHistS;
    JKQTPdatastore* ds=plot->get_plotter()->getDatastore();
    plot->get_plotter()->clearGraphs(true);
    ds->clear();
    plot->get_plotter()->getYAxis()->set_axisLabel("S");
    plot->get_plotter()->getXAxis()->set_axisLabel("frequency");
    int nbins=ui->spinBoxBins->value();
    gsl_histogram * histS=gsl_histogram_calloc_uniform(nbins,ad->rangeALEX.minP,ad->rangeALEX.maxP);
    gsl_histogram * histSFiltered=gsl_histogram_calloc_uniform(nbins,ad->rangeALEX.minP,ad->rangeALEX.maxP);
    for(int i=0;i<ad->burstVectorDual.size();++i) {
        gsl_histogram_increment(histS,ad->burstVectorDual.at(i).stoichiometryRatio);
        if(!ad->burstVectorDual.at(i).isMasked(ad->FRETparams))
            gsl_histogram_increment(histSFiltered,ad->burstVectorDual.at(i).stoichiometryRatio);
    }

    qDebug("plot S histogram");
    unsigned long long nrows=histS->n;
    size_t yColumn=ds->addCopiedColumn(histS->range, nrows, "s"); // adds column and returns column ID
    size_t xColumn=ds->addCopiedColumn(histS->bin, nrows, "all");
    size_t xColumnFiltered=ds->addCopiedColumn(histSFiltered->bin, nrows, "selected");
    gsl_histogram_free(histS);
    gsl_histogram_free(histSFiltered);

    JKQTPbarVerticalGraph* g=new JKQTPbarVerticalGraph(plot->get_plotter()); // g->set_title("S");
    g->set_xColumn(xColumn);
    g->set_yColumn(yColumn);
    g->set_shift(0);
    g->set_width(1);
    g->set_style(Qt::NoPen);
    g->set_fillColor(QColor(DISTRIBUTION_COLOR));
    plot->addGraph(g);

    g=new JKQTPbarVerticalGraph(plot->get_plotter());
    g->set_xColumn(xColumnFiltered);
    g->set_yColumn(yColumn);
    g->set_shift(0);
    g->set_width(1);
    g->set_style(Qt::NoPen);
    g->set_fillColor(QColor(DISTRIBUTION_COLOR_SELECTED));
    plot->addGraph(g);

    plot->get_plotter()->zoomToFit();

//    JKQTPhorizontalRange *gr;
//    gr = new JKQTPhorizontalRange(plot->get_plotter());
//    gr->set_rangeMin(ad->FRETparams.MinS);
//    gr->set_rangeMax(ad->FRETparams.MaxS);
//    gr->set_invertedRange(true);
//    QColor col = QColor(Qt::lightGray);
//    col.setAlpha(ui->spinBoxAlpha->value());
//    gr->set_fillColor(col);
//    gr->set_style(Qt::NoPen);
//    gr->set_plotCenterLine(false);
    //    plot->addGraph(gr);
}
Ejemplo n.º 2
0
int
main (void)
{
  struct data ntuple_row;
  int i;

  gsl_ntuple *ntuple = gsl_ntuple_open ("test.dat", &ntuple_row,
                                        sizeof (ntuple_row));

  gsl_histogram *h = gsl_histogram_calloc_uniform (100, 0., 10.);

  gsl_ntuple_select_fn S;
  gsl_ntuple_value_fn V;

  double scale = 1.5;

  S.function = &sel_func;
  S.params = &scale;

  V.function = &val_func;
  V.params = 0;

  gsl_ntuple_project (h, ntuple, &V, &S);

  gsl_histogram_fprintf (stdout, h, "%f", "%f");

  gsl_histogram_free (h);

  gsl_ntuple_close (ntuple);
}
Ejemplo n.º 3
0
void ALEXHistogramsWidget::plotHistogramPR()
{
    // pr histogram
    plot=ui->widPlotPrHist;
    JKQTPdatastore* ds=plot->get_plotter()->getDatastore();
    plot->get_plotter()->clearGraphs(true);
    ds->clear();
    plot->get_plotter()->getXAxis()->set_axisLabel("P");
    plot->get_plotter()->getYAxis()->set_axisLabel("frequency");
    int nbins=ui->spinBoxBins->value();
    gsl_histogram * histPr=gsl_histogram_calloc_uniform(nbins,ad->rangeALEX.minP,ad->rangeALEX.maxP);
    gsl_histogram * histPrSelected=gsl_histogram_calloc_uniform(nbins,ad->rangeALEX.minP,ad->rangeALEX.maxP);
    for(int i=0;i<ad->burstVectorDual.size();++i) {
        gsl_histogram_increment(histPr,ad->burstVectorDual.at(i).proximityRatio);
        if(!ad->burstVectorDual.at(i).isMasked(ad->FRETparams))
            gsl_histogram_increment(histPrSelected,ad->burstVectorDual.at(i).proximityRatio);
    }

    qDebug("plot PR histogram");
    unsigned long long nrows=histPr->n;
    size_t xColumn=ds->addCopiedColumn(histPr->range, nrows, "P"); // adds column and returns column ID
    size_t yColumn=ds->addCopiedColumn(histPr->bin, nrows, "all");
    size_t yColumnFiltered=ds->addCopiedColumn(histPrSelected->bin, nrows, "selected");
    gsl_histogram_free(histPr);
    gsl_histogram_free(histPrSelected);

    JKQTPbarHorizontalGraph* g=new JKQTPbarHorizontalGraph(plot->get_plotter()); // g->set_title("pr");
    g->set_xColumn(xColumn);
    g->set_yColumn(yColumn);
    g->set_shift(0);
    g->set_width(1);
    g->set_style(Qt::NoPen);
    g->set_fillColor(QColor(DISTRIBUTION_COLOR));
    plot->addGraph(g);

    g=new JKQTPbarHorizontalGraph(plot->get_plotter());
    g->set_xColumn(xColumn);
    g->set_yColumn(yColumnFiltered);
    g->set_shift(0);
    g->set_width(1);
    g->set_style(Qt::NoPen);
    g->set_fillColor(QColor(DISTRIBUTION_COLOR_SELECTED));
    plot->addGraph(g);



//    double area=0;
//    for(int i=0;i<histPrSelected->n;++i) {
//        area+=fabs(histPrSelected->range[i+1]-histPrSelected->range[i])*histPrSelected->bin[i];
//    }
//    QVector<double> gauss,gauss_x;
//    gauss.reserve(nbins);
//    int k=0;
//    double mu=model.getGMM()->getMu(k,0);
//    double sigma=model.getGMM()->getGauss(k).getSigma()(0,0);

//    double norm=area/sqrt(2*M_PI)/sigma;
//    qDebug()<<"plot gauss\nmu="<<mu<<" sigma="<<sigma<<"norm="<<norm<<"area="<<area;
//    double x_min=histPrSelected->range[0];
//    double x_max=histPrSelected->range[histPrSelected->n];
//    int npoints=200;
//    double step=(x_max-x_min)/(npoints-1);
//    for(int i=0;i<npoints;++i) {
//        gauss_x.append(x_min+i*step);
//    }
//    for(int i=0;i<npoints;++i) {
//        gauss.append(norm*exp(-pow((gauss_x.at(i)-mu),2)/sigma/sigma/2));
//    }
//    size_t xColumnGauss=ds->addCopiedColumn(gauss_x.data(), gauss_x.size(), "gauss P");
//    size_t yColumnGauss=ds->addCopiedColumn(gauss.data(), gauss.size(), "gauss fit");

//    JKQTPxyLineGraph* gg=new JKQTPxyLineGraph(plot->get_plotter());
//    gg->set_xColumn(xColumnGauss);
//    gg->set_yColumn(yColumnGauss);
//    gg->set_style(Qt::SolidLine);
//    gg->set_color(QColor("black"));
//    plot->addGraph(gg);

    plot->get_plotter()->zoomToFit();

//    JKQTPverticalRange *gr;
//    gr = new JKQTPverticalRange(plot->get_plotter());
//    gr->set_rangeMin(ad->FRETparams.MinP);
//    gr->set_rangeMax(ad->FRETparams.MaxP);
//    gr->set_invertedRange(true);
//    QColor col = QColor(Qt::lightGray);
//    col.setAlpha(ui->spinBoxAlpha->value());
//    gr->set_fillColor(col);
//    gr->set_style(Qt::NoPen);
//    gr->set_plotCenterLine(false);
//    plot->addGraph(gr);
}
Ejemplo n.º 4
0
void
test1d_resample (void)
{
  size_t i;
  int status = 0;

  gsl_histogram *h;

  gsl_ieee_env_setup ();

  h = gsl_histogram_calloc_uniform (10, 0.0, 1.0);

  gsl_histogram_increment (h, 0.1);
  gsl_histogram_increment (h, 0.2);
  gsl_histogram_increment (h, 0.2);
  gsl_histogram_increment (h, 0.3);

  {
    gsl_histogram_pdf *p = gsl_histogram_pdf_alloc (10);

    gsl_histogram *hh = gsl_histogram_calloc_uniform (100, 0.0, 1.0);

    gsl_histogram_pdf_init (p, h);

    for (i = 0; i < 100000; i++)
      {
        double u = urand();
        double x = gsl_histogram_pdf_sample (p, u);
        gsl_histogram_increment (hh, x);
      }

    for (i = 0; i < 100; i++)
      {
        double y = gsl_histogram_get (hh, i) / 2500;
        double x, xmax;
        size_t k;
        double ya;

        gsl_histogram_get_range (hh, i, &x, &xmax);

        gsl_histogram_find (h, x, &k);
        ya = gsl_histogram_get (h, k);

        if (ya == 0)
          {
            if (y != 0)
              {
                printf ("%d: %g vs %g\n", (int) i, y, ya);
                status = 1;
              }
          }
        else
          {
            double err = 1 / sqrt (gsl_histogram_get (hh, i));
            double sigma = fabs ((y - ya) / (ya * err));
            if (sigma > 3)
              {
                status = 1;
                printf ("%g vs %g err=%g sigma=%g\n", y, ya, err, sigma);
              }
          }
      }

    gsl_histogram_pdf_free (p) ;
    gsl_histogram_free (hh);

    gsl_test (status, "gsl_histogram_pdf_sample within statistical errors");
  }

  gsl_histogram_free (h);
}
Ejemplo n.º 5
0
void
test1d_trap (void)
{
  gsl_histogram *h;
  double result, lower, upper;
  size_t i;

  gsl_set_error_handler (&my_error_handler);

  gsl_ieee_env_setup ();

  status = 0;
  h = gsl_histogram_calloc (0);
  gsl_test (!status, "gsl_histogram_calloc traps zero-length histogram");
  gsl_test (h != 0,
            "gsl_histogram_calloc returns NULL for zero-length histogram");

  status = 0;
  h = gsl_histogram_calloc_uniform (0, 0.0, 1.0);
  gsl_test (!status,
            "gsl_histogram_calloc_uniform traps zero-length histogram");
  gsl_test (h != 0,
     "gsl_histogram_calloc_uniform returns NULL for zero-length histogram");

  status = 0;
  h = gsl_histogram_calloc_uniform (10, 1.0, 1.0);
  gsl_test (!status,
            "gsl_histogram_calloc_uniform traps equal endpoints");
  gsl_test (h != 0,
            "gsl_histogram_calloc_uniform returns NULL for equal endpoints");

  status = 0;
  h = gsl_histogram_calloc_uniform (10, 2.0, 1.0);
  gsl_test (!status,
            "gsl_histogram_calloc_uniform traps invalid range");
  gsl_test (h != 0,
            "gsl_histogram_calloc_uniform returns NULL for invalid range");

  h = gsl_histogram_calloc_uniform (N, 0.0, 1.0);

  status = gsl_histogram_accumulate (h, 1.0, 10.0);
  gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x at xmax");

  status = gsl_histogram_accumulate (h, 2.0, 100.0);
  gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x above xmax");

  status = gsl_histogram_accumulate (h, -1.0, 1000.0);
  gsl_test (status != GSL_EDOM, "gsl_histogram_accumulate traps x below xmin");

  status = gsl_histogram_increment (h, 1.0);
  gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x at xmax");

  status = gsl_histogram_increment (h, 2.0);
  gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x above xmax");

  status = gsl_histogram_increment (h, -1.0);
  gsl_test (status != GSL_EDOM, "gsl_histogram_increment traps x below xmin");


  result = gsl_histogram_get (h, N);
  gsl_test (result != 0, "gsl_histogram_get traps index at n");

  result = gsl_histogram_get (h, N + 1);
  gsl_test (result != 0, "gsl_histogram_get traps index above n");

  status = gsl_histogram_get_range (h, N, &lower, &upper);
  gsl_test (status != GSL_EDOM,
            "gsl_histogram_get_range traps index at n");

  status = gsl_histogram_get_range (h, N + 1, &lower, &upper);
  gsl_test (status != GSL_EDOM,
            "gsl_histogram_get_range traps index above n");


  status = 0;
  gsl_histogram_find (h, -0.01, &i);
  gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x below xmin");

  status = 0;
  gsl_histogram_find (h, 1.0, &i);
  gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x at xmax");

  status = 0;
  gsl_histogram_find (h, 1.1, &i);
  gsl_test (status != GSL_EDOM, "gsl_histogram_find traps x above xmax");

  gsl_histogram_free (h);
}