【问题标题】:GNU Scientific Library probability distribution functions in CC中的GNU科学图书馆概率分布函数
【发布时间】:2012-08-03 07:05:33
【问题描述】:

我有一组 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 / 直方图的代码的 sn-p:

   /* 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”函数。 ..
  • 在访问上述变量之前,您是否尝试过 gsl_histogram_pdf_alloc() 和 gsl_histogram_pdf_init()?
  • 我做了,我会在原始问题中发布我现在拥有的整个 sn-p

标签: c histogram structure gsl


【解决方案1】:

您计算一个 指针 指向您打算访问的值。

改变你当前的指针计算

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

【讨论】:

  • Mvg,感谢您的第一时间;) *((chrom+i)->pdf->sum+25) 符号不起作用,但我也注意到 (chrom+i )->pdf->sum[25] 确实有效,我不确定为什么,因为我不太了解其中的区别:(
  • @BasJansen,我很惊讶,因为两者应该产生相同的代码。看到一个最小的独立示例并查看两种替代方案的汇编代码会很有趣。但只要有一个工作版本,使用它应该没问题。
猜你喜欢
  • 2023-03-31
  • 2013-10-31
  • 2023-03-06
  • 2014-12-17
  • 2023-03-29
  • 2011-10-27
  • 2016-07-09
  • 2014-07-04
  • 1970-01-01
相关资源
最近更新 更多