Changeset - 9c4226491043
[Not reviewed]
0 2 1
Tom Bannink - 8 years ago 2017-05-22 17:08:04
tombannink@gmail.com
Split gcm-initial-triangles notebook
3 files changed with 97 insertions and 10 deletions:
0 comments (0 inline, 0 general)
cpp/switchchain_initialtris.cpp
Show inline comments
 
@@ -223,6 +223,9 @@ int main() {
 
                    }
 
                }
 

	
 
                std::cout << "Running n = " << numVertices << ", tau = " << tau
 
                          << "." << std::flush;
 

	
 
                //
 
                // Test the GCM1 and GCM2 success rate
 
                //
 
@@ -250,9 +253,6 @@ int main() {
 
                    return 1;
 
                }
 

	
 
                std::cout << "Running n = " << numVertices << ", tau = " << tau
 
                          << ". \t" << std::flush;
 

	
 
                int mixingTime = (32.0f - 20.0f * (tau - 2.0f)) * numVertices;
 
                constexpr int measurements = 20;
 
                constexpr int measureSkip = 200;
 
@@ -261,6 +261,8 @@ int main() {
 

	
 
                long long trianglesTotal = 0;
 

	
 
                std::cout << "  .. \t" << std::flush;
 

	
 
                for (int i = 0; i < mixingTime; ++i) {
 
                    if (chain.doMove())
 
                        ++movesDone;
 
@@ -269,7 +271,7 @@ int main() {
 
                    for (int j = 0; j < measureSkip; ++j)
 
                        if (chain.doMove())
 
                            ++movesDone;
 
                    trianglesTotal = chain.g.countTriangles();
 
                    trianglesTotal += chain.g.countTriangles();
 
                }
 

	
 
                std::cout << movesDone << '/' << mixingTime + measurements * measureSkip
triangle_analysis.m
Show inline comments
 
@@ -226,6 +226,7 @@ TableForm[Transpose[histograms],TableHeadings->{nlabels,taulabels}]
 

	
 
 (* Stats for a single run at every (n,tau) *)
 
timeWindow=Round[Length[gdata[[1,1,1,2]]]/10];
 
skipPts=Max[1,Round[timeWindow/100]];
 
getSingleStats[runs_]:=Module[{run,avg,stddev},
 
    run=runs[[1]]; (* Select some run *)
 
    avg=N[Mean[run[[2,-timeWindow;;-1]]]];
 
@@ -234,7 +235,8 @@ getSingleStats[runs_]:=Module[{run,avg,stddev},
 
    stddev/avg,
 
    (run[[2,1]])/avg, (* EG starting point *)
 
    Map[N[#/avg]&,run[[4]]],  (* GCM1 counts *)
 
    Map[N[#/avg]&,run[[5]]] (* GCM2 counts *)
 
    Map[N[#/avg]&,run[[5]]],  (* GCM2 counts *)
 
    (run[[2,-timeWindow;;-1;;skipPts]])/avg  (* counts in uniform distribution *)
 
    }
 
]
 
singleStats=Map[getSingleStats,gdata,{2}];
 
@@ -242,7 +244,8 @@ singleStats=Map[getSingleStats,gdata,{2}];
 

	
 
(* Yellow: GCM1 (take new highest everytime *)
 
(* Blue: GCM2 (finish highest first, more similar to EG) *)
 
histogramsSingle=Map[Histogram[{#[[4]],#[[5]]},PlotRange->{{0,5},Automatic},ImageSize->300,PlotLabel->"ErdosGallai="<>ToString[NumberForm[#[[3]],3]]<>"\[Cross]average. stddev="<>ToString[NumberForm[#[[2]],3]]<>"\[Cross]average"]&,singleStats,{2}];
 
(* Green: Actual uniform distribution *)
 
histogramsSingle=Map[Histogram[{#[[4]],#[[5]],#[[6]]},PlotRange->{{0,3},Automatic},ImageSize->300,PlotLabel->"ErdosGallai="<>ToString[NumberForm[#[[3]],3]]<>"\[Cross]average"]&,singleStats,{2}];
 

	
 

	
 
TableForm[histogramsSingle,TableHeadings->{taulabels,nlabels}]
 
@@ -250,12 +253,13 @@ TableForm[histogramsSingle,TableHeadings->{taulabels,nlabels}]
 

	
 
 (* Consider all runs *)
 
timeWindow=Round[Length[gdata[[1,1,1,2]]]/10];
 
skipPts=Max[1,Round[timeWindow/100]];
 
getAverage[run_]:=Module[{avg,stddev},
 
    avg=N[Mean[run[[2,-timeWindow;;-1]]]];
 
    {
 
    Mean[run[[4]]]/avg,(* GCM1 counts *)
 
    Mean[run[[5]]]/avg, (* GCM2 counts *)
 
    (run[[2,1]])/avg (* EG starting point *)
 
    (run[[2,1]])/avg, (* EG starting point *)
 
    }
 
]
 
getTotalStats[runs_]:=Transpose[Map[getAverage,runs]];
 
@@ -263,15 +267,13 @@ totalStats=Map[getTotalStats,gdata,{2}];
 

	
 

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

	
 

	
 
TableForm[histogramsTotal,TableHeadings->{taulabels,nlabels}]
 

	
 

	
 

	
 

	
 
(* ::Subsection:: *)
 
(*GCM1 vs GCM2 success rates*)
 

	
triangle_gcm_initial_analysis.m
Show inline comments
 
new file 100644
 
(* ::Package:: *)
 

	
 
Needs["ErrorBarPlots`"]
 

	
 

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

	
 

	
 
gsraw=Import[NotebookDirectory[]<>"data/graphdata_initialtris.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 when mixed
 
3: {GCM1 starting triangle counts summed, GCM1 number of successes}
 
4: {GCM2 starting triangle counts summed, GCM2 number of successes}
 
*)
 
nlabels=Map["n = "<>ToString[#]&,gdata[[1,All,1,1,1]]];
 
taulabels=Map["tau = "<>ToString[#]&,gdata[[All,1,1,1,2]]];
 

	
 

	
 
(* ::Section:: *)
 
(*Greedy configuration model*)
 

	
 

	
 
(* ::Subsection:: *)
 
(*Distribution of initial #triangles for GCM1,GCM2,EG compared to average #triangles.*)
 

	
 

	
 
 (* Consider all runs *)
 
getIt[x_,avg_]:=If[x[[2]]>=5, x[[1]]/x[[2]]/avg,-0.5]
 
getAverage[run_]:=Module[{avg},
 
    avg=20*run[[2]];
 
    If[avg>0,
 
    { getIt[run[[3]],avg], getIt[run[[4]],avg] }
 
    , {3,3}]
 
]
 
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) *)
 
histogramsTotal=Map[Histogram[#,{0.05},PlotRange->{{-0.5,2},Automatic},ImageSize->300,AxesOrigin->{0,0}]&,totalStats,{2}];
 

	
 

	
 
TableForm[histogramsTotal,TableHeadings->{taulabels,nlabels}]
 

	
 

	
 
(* ::Subsubsection:: *)
 
(*Exporting plots*)
 

	
 

	
 
tauIndices={2,5,8};
 
nIndices={2};
 
makeHistogram[datasets_,n_,tau_]:=Histogram[datasets,{0.05},PlotRange->{{-0.5,1.5},Automatic},ImageSize->300,AxesOrigin->{0,0}];
 
histogramsTotal=Map[makeHistogram[#,1000,tau]&,totalStats[[tauIndices,nIndices]],{2}];
 
TableForm[histogramsTotal,TableHeadings->{taulabels[[tauIndices]],nlabels[[nIndices]]}]
 

	
 

	
 
(* ::Subsection:: *)
 
(*GCM1 vs GCM2 success rates*)
 

	
 

	
 
(* gdata[[ tau index, n index, run index , {ntau, #tris, ds, greedyTriangles} ]] *)
 
successrates=Map[{#[[3,2]],#[[4,2]]}&,gdata,{3}];
 
successrates=Map[Transpose,successrates,{2}];
 
successratesDelta=Map[#[[3,2]]-#[[4,2]]&,gdata,{3}];
 

	
 
rateHistograms=Map[Histogram[#,{10},PlotRange->{{0,100},Automatic}]&,successrates,{2}];
 
TableForm[rateHistograms,TableHeadings->{taulabels,nlabels}]
 

	
 
rateHistograms=Map[Histogram[#,{10},PlotRange->{{-100,100},Automatic}]&,successratesDelta,{2}];
 
TableForm[rateHistograms,TableHeadings->{taulabels,nlabels}]
 
(*TableForm[Transpose[rateHistograms],TableHeadings->{nlabels,taulabels}]*)
 

	
 

	
 

	
0 comments (0 inline, 0 general)