(* ::Package:: *)

Needs["ErrorBarPlots`"]


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


gsraw=Import[NotebookDirectory[]<>"data/graphdata_properties.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: avgTriangles
3: edges
4: dstn
5: { HH A, HH L, average A, average L }  where for each there is (average of) {lambda1 , lambda1 - lambda2, lambda1/lambda2}
6: switching successrate after mixing
7: initial HH triangles
*)
nlabels=Map["n = "<>ToString[#]&,gdata[[1,All,1,1,1]]];
taulabels=Map["\[Tau] = "<>ToString[#]&,gdata[[All,1,1,1,2]]];
datatypeLabels={"(n,tau)","average number of triangles","edges","DSTN","Eigenvalues","successrate","initial number of triangles"};


(* ::Section:: *)
(*Plot triangle counts vs dsp*)


(* ::Subsection:: *)
(*Plot #trianges vs some degree-sequence-property*)


allPlots=Map[Show[
ListPlot[#[[All,{2,4}]],
AxesOrigin->{0,0},
Frame->True,FrameLabel->{"average number of triangles","degree-sequence-property"},
AspectRatio->Automatic,
ImageSize->Automatic,
PlotLabel->"n = "<>ToString[#[[1,1,1]]]<>" , \[Tau] = "<>ToString[#[[1,1,2]]],
PlotStyle->Black
],Plot[x,{x,1,10000}]]
&,gdata,{2}]


plotgrid=GraphicsRow[{GraphicsColumn[allPlots[[{1,2},1]]],allPlots[[3,1]]},Spacings->0,ImageSize->600]


(* ::Section:: *)
(*DSP, Edges, #triangles, successrate*)


(* datatype index:
1: {n,tau}
2: avgTriangles
3: edges
4: dstn
5: { HH A, HH L, average A, average L }  where for each there is (average of) {lambda1 , lambda1 - lambda2, lambda1/lambda2}
6: switching successrate after mixing
7: initial HH triangles
*)


correlations={4,2};

tauChoices={2,5,8};
nChoice=-1;

combiPlot=Show[
ListLogLogPlot[gdata[[tauChoices,nChoice,All,correlations]],
(*AxesOrigin->{0,0},*)
(*PlotRange\[Rule]{{0,3000},{0,3000}},*)
PlotRange->Automatic,
Frame->True,FrameLabel->datatypeLabels[[correlations]],
AspectRatio->Automatic,
ImageSize->Automatic,
PlotLabel->"n = "<>ToString[gdata[[1,nChoice]][[1,1,1]]],
PlotLegends->taulabels[[tauChoices]]
],Plot[x,{x,1,10000},PlotStyle->Black]]

Map[DensityHistogram[gdata[[#,nChoice,All,correlations]],"Log",
Frame->True,FrameLabel->datatypeLabels[[correlations]],
PlotLabel->taulabels[[#]]
]
&,tauChoices]



