2012-08-06 31 views
0

我有一组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 */ 
     } 
    } 
+0

我也这么认为,但它从来没有包含任何值,并且据我所知,测试PDF是否在首位的唯一方法是使用“gsl_histogram_pdf_sample”函数返回值... – 2012-08-06 10:23:50

+0

你尝试gsl_histogram_pdf_alloc()和访问上述变量之前gsl_histogram_pdf_init()? – askmish 2012-08-06 10:44:23

+0

我做了,我会在原始问题 – 2012-08-06 11:27:15

回答

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,因为它可能表示一个相当小的浮点数,具体取决于内存虚拟布局。

+0

Mvg中发布我现在的整个片段,感谢您的时间第一次;)*((chrom + i) - > pdf-> sum + 25)notation'但我也注意到(chrom + i) - > pdf-> sum [25]确实有效,我不确定为什么,因为我不明白其中的区别:( – 2012-08-06 14:23:38

+0

@BasJansen,我是很惊讶,因为这两者应该导致相同的代码,看到一个最小的自包含示例并查看两种替代方案的汇编代码将是有益的,但只要有一个工作版本,使用它应该没问题。 – MvG 2012-08-06 15:27:58