Changeset - 3e67925ef7ec
[Not reviewed]
0 2 1
Tom Bannink - 8 years ago 2017-08-15 17:57:03
tom.bannink@cwi.nl
Add autocorrelation notebook
3 files changed with 66 insertions and 5 deletions:
0 comments (0 inline, 0 general)
plots/ccm_initialtris.pdf
Show inline comments
 
binary diff not shown
triangle_autocorrelations.m
Show inline comments
 
new file 100644
 
(* ::Package:: *)
 

	
 
(* ::Section:: *)
 
(*Data import*)
 

	
 

	
 
gsraw=Import[NotebookDirectory[]<>"data/graphdata_timeevol.m"];
 
(* gsraw=SortBy[gsraw,{#[[1,1]]&,#[[1,2]]&}]; (* Sort by n and then by tau. The {} forces a *stable* sort because otherwise Mathematica sorts also on triangle count and other things. *) *)
 

	
 

	
 
gdata=GatherBy[gsraw,{#[[1,2]]&,#[[1,1]]&}];
 
(* Data format: *)
 
(* gdata[[ tau index, n index, run index , datatype index ]] *)
 
(* datatype index:
 
1: {n,tau}
 
2: #triangles time sequence
 
3: degree sequence
 
4: GCM1 starting triangle counts
 
5: GCM2 starting triangle counts
 
6: GCM1 time sequence
 
7: GCM2 time sequence
 
*)
 
nlabels=Map["n = "<>ToString[#]&,gdata[[1,All,1,1,1]]];
 
taulabels=Map["tau = "<>ToString[#]&,gdata[[All,1,1,1,2]]];
 

	
 

	
 
(* ::Section:: *)
 
(*Triangle counts autocorrelation*)
 

	
 

	
 
doAutoCorrelate[dataset_,maxlag_]:=Module[{avg,data2,result},
 
avg=Mean[dataset];
 
data2=dataset-avg;
 
result=ParallelTable[Mean[data2[[1+lag;;]]*data2[[;;-1-lag]]],{lag,0,maxlag}];
 
result=result/result[[1]]
 
]
 

	
 

	
 
doPeriodicAutocorrelate[dataset_,maxlag_]:=Module[{f,result},
 
f=Fourier[dataset-Mean[dataset]];
 
result=InverseFourier[f*Conjugate[f]];
 
result=result[[1;;Min[Floor[Length[result]/2],maxlag]]];
 
result=Chop[result];
 
result=result/result[[1]]
 
]
 

	
 

	
 
dataX=gdata[[1,1]][[3,2]];
 
ListPlot[dataX,Joined->True,PlotRange->All]
 
dataX=dataX[[15000;;50000]];
 

	
 

	
 
cor1=doAutoCorrelate[dataX,2000];
 

	
 

	
 
cor2=doPeriodicAutocorrelate[dataX,20000];
 

	
 

	
 
ListPlot[{cor1,cor2},Joined->True,PlotRange->{-0.5,1}]
triangle_gcm_initial_analysis.m
Show inline comments
 
@@ -44,8 +44,8 @@ getTotalStats[runs_]:=Transpose[Map[getAverage,runs]];
 
totalStats=Map[getTotalStats,gdata,{2}];
 

	
 

	
 
(* Yellow: GCM1 (take new highest everytime *)
 
(* Blue: GCM2 (finish highest first, more similar to EG) *)
 
(* Yellow: CCMu (take new highest everytime *)
 
(* Blue: CCMb (finish highest first, more similar to EG) *)
 
histogramsTotal=Map[Histogram[#,{0.05},PlotRange->{{-0.5,2},Automatic},ImageSize->300,AxesOrigin->{0,0}]&,totalStats,{2}];
 

	
 

	
 
@@ -57,10 +57,12 @@ TableForm[histogramsTotal,TableHeadings->{taulabels,nlabels}]
 

	
 

	
 
makeHistogram[datasets_,n_,tau_]:=Histogram[datasets,{0.05},"Probability",
 
PlotRange->{{0,1},{0,0.5}},
 
PlotRange->{{0,1.3},{0,0.5}},
 
ImageSize->300,AxesOrigin->{0,0},
 
AspectRatio->3/5,
 
Frame->True,
 
FrameLabel->{"fraction of average #triangles at CCM start","frequency"},
 
ChartLegends->Placed[{"CCMu   avg = "<>ToString[NumberForm[N[Mean[datasets[[1]]]],2]],"CCMb   avg = "<>ToString[NumberForm[N[Mean[datasets[[2]]]],2]]},Center],
 
(*LabelingFunction->(Placed[NumberForm[#,{2,3}],Above]&),*)
 
(*LabelingFunction\[Rule](Placed[If[#2[[2]]\[Equal]1,NumberForm[#1,{2,3}],""],Above]&),*)
 
PlotLabel->n<>", "<>tau];
 
@@ -68,9 +70,9 @@ histogramsTotal=MapIndexed[makeHistogram[#1,nlabels[[#2[[2]]]],taulabels[[#2[[1]
 

	
 

	
 
tauIndices={1,5,9};
 
nIndices={3};
 
nIndices={1};
 
(* TableForm[histogramsTotal[[tauIndices,nIndices]],TableHeadings->{taulabels[[tauIndices]],nlabels[[nIndices]]}]*)
 
plotgrid1=GraphicsGrid[histogramsTotal[[tauIndices,nIndices]]]
 
plotgrid1=GraphicsGrid[histogramsTotal[[tauIndices,nIndices]],ImageSize->350,ItemAspectRatio->3/5]
 

	
 

	
 
Export[NotebookDirectory[]<>"plots/ccm_initialtris.pdf",plotgrid1]
0 comments (0 inline, 0 general)