我有一套GSL直方图,用于制作一组概率分布函数,根据文档存储在结构中,如下所示:
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测试来确定。所以,我试图访问这个结构中给定bin的总和,来计算'距离',我认为,我应该能够通过使用:
来访问该值((my_type)->pdf->sum+x)
X是bin编号。
然而无论我做什么,这总是会返回0,有没有人有任何想法,出了什么问题?
提前致谢
----编辑----
以下是我的代码片段,用于处理pdf / histogram:
/* 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 */
}
}
答案 0 :(得分:2)
您计算指针到您想要访问的值。
更改当前指针计算
printf("%f\n",((chrom+i)->pdf->sum+25));
要么是正常的数组下标
printf("%f\n",(chrom+i)->pdf->sum[25]);
或指针计算后跟解除引用
printf("%f\n",*((chrom+i)->pdf->sum+25));
查看是否可以解决您的问题。该值也不应该为0,但它可能会显示为0,因为它可能代表一个相当小的浮点数,具体取决于内存虚拟布局。