0

確率分布関数のセットを作成するために使用される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テストを使用して、データが類似しているかどうかを判断するつもりです。したがって、この構造内の特定のビンの合計にアクセスして「距離」を計算しようとしています。次を使用して、その値にアクセスできるはずだと思いました。

((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 */
       }
   } 
4

1 に答える 1

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として表示される可能性があります。

于 2012-08-06T13:52:39.323 に答える