• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            一般在計算相關系數時都要遍歷4次數據,這在數據比較多,需要讀寫文件時,顯然是費時的。這里給出Single Pass版本的計算方法,但是其中的變化依據還沒有搞懂,希望各位指教:
            偽代碼:

             1 sum_sq_x = 0
             2 sum_sq_y = 0
             3 sum_coproduct = 0
             4 mean_x = x[1]
             5 mean_y = y[1]
             6 for i in 2 to N:
             7     sweep = (i - 1.0/ i
             8     delta_x = x[i] - mean_x
             9     delta_y = y[i] - mean_y
            10     sum_sq_x += delta_x * delta_x * sweep
            11     sum_sq_y += delta_y * delta_y * sweep
            12     sum_coproduct += delta_x * delta_y * sweep
            13     mean_x += delta_x / i
            14     mean_y += delta_y / i 
            15 pop_sd_x = sqrt( sum_sq_x / N )
            16 pop_sd_y = sqrt( sum_sq_y / N )
            17 cov_x_y = sum_coproduct / N
            18 correlation = cov_x_y / (pop_sd_x * pop_sd_y)
            19

            下面是我用C改寫的,這份改寫同時放在了Wiki上面:
             1#include "stdlib.h"
             2#include "math.h"
             3void SinglePassCorrelation(FILE *file,int N)
             4{
             5    double *x=new double[N+1];
             6    double *y=new double[N+1];
             7    int i;
             8    for(i=1;i<=N;i++)
             9    {
            10        fscanf(file,"%lf %lf",&x[i],&y[i]);
            11        printf("%10.6f %10.6f\n",x[i],y[i]);
            12    }

            13    double sum_sq_x=0;
            14    double sum_sq_y=0;
            15    double sum_coproduct=0;
            16    double mean_x=x[1];
            17    double mean_y=y[1];
            18    double sweep=0;
            19    double delta_x;
            20    double delta_y;
            21    double pop_sd_x;
            22    double pop_sd_y;
            23    double cov_x_y;
            24    double correlation;
            25    for(i=2;i<=N;i++)
            26    {
            27        sweep=(i-1.0)/i;
            28        delta_x=x[i]-mean_x;
            29        delta_y=y[i]-mean_y;
            30        sum_sq_x+=delta_x*delta_y*sweep;
            31        sum_sq_y+=delta_y*delta_y*sweep;
            32        sum_coproduct+=delta_x*delta_y*sweep;
            33        mean_x+=delta_x/i;
            34        mean_y+=delta_y/i;
            35    }
            //end for i
            36    pop_sd_x=sqrt(sum_sq_x/N);
            37    pop_sd_y=sqrt(sum_sq_y/N);
            38    cov_x_y=sum_coproduct/N;
            39    correlation=cov_x_y/(pop_sd_x*pop_sd_y);
            40}

            41
            Posted on 2008-11-28 20:13 鄒敏 閱讀(2129) 評論(0)  編輯 收藏 引用
            久久久婷婷五月亚洲97号色| 久久99国产精品尤物| 66精品综合久久久久久久| 国产2021久久精品| 精品久久久无码人妻中文字幕| 亚洲综合伊人久久综合| 国产精品九九久久免费视频| 少妇内射兰兰久久| 免费精品久久久久久中文字幕| 久久精品国产亚洲77777| 无码8090精品久久一区| 久久精品国产亚洲网站| 久久香蕉国产线看观看精品yw| 久久久久久亚洲精品无码| 97久久婷婷五月综合色d啪蜜芽| 久久国产精品国语对白| 久久香蕉国产线看观看99| 久久国产色AV免费观看| 久久精品国产亚洲av麻豆蜜芽| 久久青青草原精品国产不卡| 久久99久久99小草精品免视看| 热re99久久精品国99热| 久久精品国产2020| 久久久久久国产精品无码下载| 久久综合伊人77777| 狠狠色综合久久久久尤物| segui久久国产精品| 久久r热这里有精品视频| 久久久久久久久久久久中文字幕| 久久久国产视频| 久久国语露脸国产精品电影| 久久久午夜精品| 久久中文字幕人妻熟av女| 久久无码AV一区二区三区| 99久久国产亚洲综合精品| 国产成人综合久久精品红| 97精品国产97久久久久久免费| 午夜精品久久久久久99热| 久久久久人妻一区精品色| 77777亚洲午夜久久多喷| 国内精品久久久久久久涩爱|