我有一组GSL直方图的,这是用来使一组的概率分布函数,其中根据文件被存储在一个结构,如下所示:用C GNU科学库的概率分布函数
Data Type: gsl_histogram_pdf
size_t n
This is the number of bins used to approximate the probability distribution function.
double * range
The ranges of the bins are stored in an array of n+1 elements pointed to by range.
double * sum
The cumulative probability for the bins is stored in an array of n elements pointed to by sum.
我打算用KS检验来确定,如果数据是相似与否。所以,我试图访问一个给定区间的总和在这种结构中,计算出“距离”,我认为,我应该能够通过访问该值:
((my_type)->pdf->sum+x)
其中x是箱号。
然而,这总是返回0,无论我做什么,没有任何人有任何想法,有什么问题呢?
在此先感谢
---- ----编辑
这里是我的代码片段与PDF /直方图交易:
/* GSL Histogram creation */
for (i = 0; i < chrom->hits; i++) {
if ((chrom+i)->spectra->peaks != 0) {
(chrom+i)->hist = gsl_histogram_alloc(bins);
gsl_histogram_set_ranges_uniform((chrom+i)->hist, low_mz, high_mz);
for (j = 0; j < (chrom+i)->spectra->peaks; j++) {
gsl_histogram_increment((chrom+i)->hist, ((chrom+i)->spectra+j)->mz_value);
}
} else {
printf("0 value encountered!\n");
}
}
/* Histogram probability distribution function creation */
for (i = 0; i < chrom->hits; i++) {
if ((chrom+i)->spectra->peaks != 0) {
(chrom+i)->pdf = gsl_histogram_pdf_alloc(bins);
gsl_histogram_pdf_init((chrom+i)->pdf, (chrom+i)->hist);
} else {
continue;
}
}
/* Kolmogorov-Smirnov */
float D;
for (i = 0; i < chrom->hits-1; i++) {
printf("%f\n",((chrom+i)->pdf->sum+25));
for (j = i+1; j < chrom->hits; j++) {
D = 0;
diff = 0;
/* Determine max distance */
}
}
我也这么认为,但它从来没有包含任何值,并且据我所知,测试PDF是否在首位的唯一方法是使用“gsl_histogram_pdf_sample”函数返回值... – 2012-08-06 10:23:50
你尝试gsl_histogram_pdf_alloc()和访问上述变量之前gsl_histogram_pdf_init()? – askmish 2012-08-06 10:44:23
我做了,我会在原始问题 – 2012-08-06 11:27:15