2016-11-28 24 views
1

以下是我的問題通過我的老師給出開始,共方差函數的曲線應該從0移

  1. 生成具有分佈的隨機變量的N = 1000個獨立觀測的序列:(c)參數λ= 1的指數,採用 反演方法。目前圖形獲得的序列(除了在點e中產生的序列),例如, (a)i。繪製座標(obs。, 值)ii。在i = 1,2,3的座標中繪製(obs no n,obs。no n + i)iii。爲某些 值繪製所謂的協方差函數。即,平均爲:

enter image description here

我寫了下面的代碼,

(*****************************************************************) 
(*Task 01(c) and 02(a)*) 
(*****************************************************************) 
n = 1000; 

taskC = Table[-Log[RandomReal[]], {n}]; 

ListPlot[taskC, AxesLabel->{"No. obs", "value of the obs"}] 

i = 1; 
ListPlot[Table[ 
    {taskC[[k]], taskC[[k+i]]}, 
    {k, 1, n-i,1}], 
AxesLabel->{"obs.no.n", "obs.no.n+1"}] 

i++; 
ListPlot[Table[ 
    {taskC[[k]], taskC[[k+i]]}, 
    {k, 1, n-i,1}], 
AxesLabel-> {"obs.no.n", "obs.no.n+2"}] 

i++; 
ListPlot[Table[ 
    {taskC[[k]], taskC[[k+i]]}, 
    {k,1,n-i,1}], 
AxesLabel->{"obs.no.n", "obs.no.n+3"}] 

avg = (1/n)*Sum[taskC[[i]], {i,n}]; 

ListPlot[Table[1/(n-tau) * Sum[(taskC[[i]]-avg)*(taskC[[i+tau]] - avg), n], {tau, 1,100}], 
    Joined->True, 
    AxesLabel->"Covariance Function"] 

enter image description here

他評論說,

協方差函數的圖應該從0移位開始。注意 ,對於大於0的移位,你估計的是 之間的獨立觀測值之間的協方差爲零,而對於0移動,你是 估計大的觀測方差。因此,這兩種情況之間的對比清楚地表明觀察 是不相關的。

我做錯了什麼?

如何更正我的代碼?

回答

1

零漂移意味着計算tau = 0的協方差,它只是方差。

Labeled[ListPlot[Table[{tau, 
    1/(n - tau)*Sum[(taskC[[i]] - avg)*(taskC[[i + tau]] - avg), {i, n - tau}]}, 
    {tau, 0, 5}], Filling -> Axis, FillingStyle -> Thick, PlotRange -> All, 
    Frame -> True, PlotRangePadding -> 0.2, AspectRatio -> 1], 
{"Covariance Function K(n)", "n"}, {{Top, Left}, Bottom}] 

enter image description here

Variance[taskC] 

0.93484

Covariance[taskC, taskC] 

0.93484

(* n = 1 *) 
Covariance[Most[taskC], Rest[taskC]] 

0.00926913

+0

能否請你推薦一本書使用Mathematica隨機過程編程? – anonymous

+0

[隨機微分方程](https://books.google.co.uk/books?id=ERYzXjt3iYkC&pg=PA25)? –

+0

謝謝!任何其他書?越多越好! – anonymous