Changeset - 30d182b86860
[Not reviewed]
0 4 1
Tom Bannink - 8 years ago 2017-08-21 17:49:26
tom.bannink@cwi.nl
Add better construction successrate measurement
5 files changed with 186 insertions and 8 deletions:
0 comments (0 inline, 0 general)
cpp/Makefile
Show inline comments
 
@@ -12,6 +12,7 @@ CXXFLAGS += -Wno-int-in-bool-context
 

	
 
TARGETS += switchchain
 
TARGETS += switchchain_canonical_properties
 
TARGETS += switchchain_ccm_constructionrate
 
TARGETS += switchchain_ccm_cputime
 
TARGETS += switchchain_ccm_initialtris
 
TARGETS += switchchain_ccm_timeevol
cpp/switchchain_ccm_constructionrate.cpp
Show inline comments
 
new file 100644
 
#include "exports.hpp"
 
#include "graph.hpp"
 
#include "graph_ccm.hpp"
 
#include "graph_powerlaw.hpp"
 
#include "switchchain.hpp"
 
#include <algorithm>
 
#include <fstream>
 
#include <iostream>
 
#include <numeric>
 
#include <random>
 
#include <vector>
 

	
 
int main(int argc, char* argv[]) {
 
    // Simulation parameters
 
    const int numVerticesMin = 1000;
 
    const int numVerticesMax = 1000;
 
    const int numVerticesStep = 500;
 

	
 
    //float tauValues[] = {2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f};
 
    float tauValues[] = {2.1f, 2.5f, 2.9f};
 

	
 
    const int totalDegreeSamples = 5000;
 
    const int ccmConstructionAttemps = 200;
 

	
 
    // Output file
 
    std::ofstream outfile;
 
    if (argc >= 2)
 
        outfile.open(argv[1]);
 
    else
 
        outfile.open("graphdata_ccm_constructionrate.m");
 
    if (!outfile.is_open()) {
 
        std::cout << "ERROR: Could not open output file.\n";
 
        return 1;
 
    }
 

	
 
    // Output Mathematica-style comment to indicate file contents
 
    outfile << "(*\n";
 
    outfile << "n from " << numVerticesMin << " to " << numVerticesMax
 
            << " step " << numVerticesStep << std::endl;
 
    outfile << "tauValues: " << tauValues << std::endl;
 
    outfile << "degreeSamples: " << totalDegreeSamples << std::endl;
 
    outfile << "mixingTime: -\n";
 
    outfile << "measurements: -\n";
 
    outfile << "measureSkip: -\n";
 
    outfile << "ccm construction attemps: " << ccmConstructionAttemps << std::endl;
 
    outfile << "data:\n";
 
    outfile << "1: {n,tau}\n";
 
    outfile << "3: CCMdu construction rate \n";
 
    outfile << "4: CCMd construction rate \n";
 
    outfile << "*)" << std::endl;
 
 
 
    // Mathematica does not accept normal scientific notation
 
    outfile << std::fixed;
 
    outfile << '{';
 
    bool outputComma = false;
 

	
 
    std::mt19937 rng(std::random_device{}());
 
    Graph g;
 
    for (int numVertices = numVerticesMin; numVertices <= numVerticesMax;
 
         numVertices += numVerticesStep) {
 
        for (float tau : tauValues) {
 
            // For a single n,tau take samples over several instances of
 
            // the degree distribution.
 
            for (int degreeSample = 0; degreeSample < totalDegreeSamples;
 
                 ++degreeSample) {
 
                DegreeSequence ds;
 
                generatePowerlawGraph(numVertices, tau, g, ds, rng);
 

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

	
 
                //
 
                // Test the GCM1 and GCM2 success rate
 
                //
 
                int successrate1 = 0;
 
                int successrate2 = 0;
 
                for (int i = 0; i < ccmConstructionAttemps; ++i) {
 
                    Graph gtemp;
 
                    // Take new highest degree every time
 
                    if (constrainedConfigurationModel(ds, gtemp, rng, false)) {
 
                        ++successrate1;
 
                    }
 
                    // Finish all pairings of highest degree first
 
                    if (constrainedConfigurationModel(ds, gtemp, rng, true)) {
 
                        ++successrate2;
 
                    }
 
                }
 

	
 
                std::cout << "Done." << std::flush;
 

	
 
                if (outputComma)
 
                    outfile << ',' << '\n';
 
                outputComma = true;
 

	
 
                outfile << '{';
 
                outfile << '{' << numVertices << ',' << tau << '}';
 
                outfile << ',' << float(successrate1)/float(ccmConstructionAttemps);
 
                outfile << ',' << float(successrate2)/float(ccmConstructionAttemps);
 
                outfile << '}' << std::flush;
 

	
 
                std::cout << std::endl;
 
            }
 
        }
 
    }
 
    outfile << '}';
 
    return 0;
 
}
cpp/switchchain_ccm_initialtris.cpp
Show inline comments
 
@@ -16,8 +16,8 @@ int main(int argc, char* argv[]) {
 
    const int numVerticesMax = 1000;
 
    const int numVerticesStep = 500;
 

	
 
    float tauValues[] = {2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f};
 
    //float tauValues[] = {2.1f, 2.3f, 2.5f, 2.7f, 2.9f};
 
    //float tauValues[] = {2.1f, 2.2f, 2.3f, 2.4f, 2.5f, 2.6f, 2.7f, 2.8f, 2.9f};
 
    float tauValues[] = {2.1f, 2.5f, 2.9f};
 

	
 
    const int totalDegreeSamples = 200;
 

	
triangle_creation_frequency_plots.m
Show inline comments
 
@@ -77,3 +77,28 @@ hcol=GraphicsGrid[Transpose[{{h1,h2,h3},{h1zoomed,h2zoomed,h3zoomed}}]]
 

	
 

	
 
Export[NotebookDirectory[]<>"plots/triangle_creation_frequencies_log.pdf",hcol]
 

	
 

	
 
(* ::Subsection:: *)
 
(*Test with 'Callout' labels*)
 

	
 

	
 
createCalloutPlot[data_]:=Module[{h,hl,bcdata,llp},
 
h=Histogram[data,{-20.5,20.5,1},{"Log","Probability"},PlotRange->All,ImageSize->280];
 
hl=HistogramList[data,{-20.5,20.5,1},"Probability"];
 
bcdata=Map[If[#>=0.01,Callout[#,NumberForm[#,{2,3}]],Clip[#,{10^-5,2}]]&,hl[[2]]];
 
llp=ListLogPlot[bcdata,PlotStyle->None,DataRange->{-20,20}];
 
Show[h,llp]
 
]
 
histograms3=Map[createCalloutPlot[Flatten[#]]&,differences,{2}];
 

	
 

	
 
(* TODO: Somehow the values of these histograms do not match the ones above!!! ????? *)
 

	
 

	
 
Show[histograms3[[2]],PlotLabel->"n=1000, \[Tau]=2.2"]
 
Show[histograms3[[5]],PlotLabel->"n=1000, \[Tau]=2.5"]
 
Show[histograms3[[8]],PlotLabel->"n=1000, \[Tau]=2.8"]
 

	
 

	
 

	
triangle_gcm_initial_analysis.m
Show inline comments
 
@@ -24,6 +24,24 @@ nlabels=Map["n = "<>ToString[#]&,gdata[[1,All,1,1,1]]];
 
taulabels=Map["\[Tau] = "<>ToString[#]&,gdata[[All,1,1,1,2]]];
 

	
 

	
 
(* ::Subsection:: *)
 
(*New data format import*)
 

	
 

	
 
gsraw=Import[NotebookDirectory[]<>"data/graphdata_ccm_constructionrate.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. *) *)
 

	
 

	
 
gdata2=GatherBy[gsraw,{#[[1,2]]&,#[[1,1]]&}];
 
(* Data format: *)
 
(* gdata[[ tau index, n index, run index , datatype index ]] *)
 
(* datatype index:
 
1: {n,tau}
 
3: CCMdu construction rate <-- CCMdu: get new highest degree vertex every time
 
4: CCMd  construction rate <-- CCMd: finish vertex completely
 
*)
 

	
 

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

	
 
@@ -125,29 +143,56 @@ Export[NotebookDirectory[]<>"plots/ccm_construction_successrate9.pdf",plot3]
 

	
 

	
 
successrates=Map[#[[3,2]]/100&,gdata,{3}];
 
successrates[[1,1]]=gdata2[[1,1,All,2]]; (* New datafile test *)
 
successrates=Map[Clip[#,{0,0.99999}]&,successrates,{3}];
 
legends=Map["\[Tau] = "<>ToString[#[[1,1,2]]]<>" ; avg = "<>ToString[NumberForm[N[Mean[#[[All,3,2]]/100]],3]]&,gdata,{2}];
 

	
 
datasets={successrates[[1,1]], successrates[[5,1]], successrates[[9,1]]};
 
selectedLegends={legends[[1,1]],legends[[5,1]],legends[[9,1]]};
 

	
 
SmoothHistogram[datasets,{0.06,"Gaussian"},"PDF",
 
plot1=Histogram[datasets,{-0.025,1.025,0.05},"Probability",
 
PlotRange->{{0,1},{0,1}},
 
ChartStyle->Directive[FaceForm[Opacity[0.8]],EdgeForm[Thickness[0.001]]],
 
ImageSize->300,AxesOrigin->{0,0},
 
Frame->True,
 
FrameLabel->{"successrate of CCMdu construction\n(distribution over sampled degree sequences)","Probability"},
 
ChartLegends->Placed[selectedLegends,Center],
 
PlotLabel->"n = 1000"]
 

	
 
histogramlist = Map[Last[HistogramList[#,{-0.05,1.05,0.1},"Probability"]]&,datasets];
 
histogramlist = Transpose[histogramlist];
 
(* labels=ConstantArray["",Ceiling[1/0.05]];
 
labels[[2;;-1;;2]]=Map[ToString,Range[0.1,1,0.1]]; *)
 
labels=Map[ToString,Range[0,1,0.1]];
 
plot2=BarChart[histogramlist,
 
PlotRange->{All,{0,1}},
 
BarSpacing->{None,Medium},
 
ChartLabels->{labels,None},
 
ImageSize->300,AxesOrigin->{0,0},
 
Frame->True,
 
FrameLabel->{"successrate of CCMdu construction\n(distribution over sampled degree sequences)","Probability"},
 
ChartLegends->Placed[selectedLegends,Center],
 
PlotLabel->"n = 1000"]
 

	
 
plot3=SmoothHistogram[datasets,{0.01,"Gaussian"},"PDF",
 
PlotRange->{{0,1},All},
 
(*ChartStyle\[Rule]Directive[FaceForm[Opacity[0.5]],EdgeForm[Thickness[0.007]]],*)
 
ImageSize->300,AxesOrigin->{0,0},
 
Frame->True,
 
FrameLabel->{"successrate of CCMdu construction\n over sampled degree sequences","PDF"},
 
FrameLabel->{"successrate of CCMdu construction\n(distribution over sampled degree sequences)","PDF"},
 
PlotLegends->Placed[selectedLegends,Center],
 
PlotLabel->"n = 1000"]
 

	
 
(*
 
Table[
 
SmoothHistogram[datasets,{0.06,weightKernel},"PDF",
 
SmoothHistogram[datasets,{0.01,weightKernel},"PDF",
 
PlotRange->{{0,1},All},
 
(*ChartStyle\[Rule]Directive[FaceForm[Opacity[0.5]],EdgeForm[Thickness[0.007]]],*)
 
ImageSize->300,AxesOrigin->{0,0},
 
Frame->True,
 
FrameLabel->{"successrate of CCMdu construction\n over sampled degree sequences","PDF"},
 
FrameLabel->{"successrate of CCMdu construction\n over sampled degree sequences","CDF"},
 
PlotLegends->Placed[selectedLegends,Center],
 
PlotLabel->"n = 1000"],{weightKernel,{"Biweight","Gaussian","Rectangular","Cosine","SemiCircle"}}]
 
*)
 

	
 

	
 

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