Changeset - a410aaa16af7
[Not reviewed]
0 3 0
Tom Bannink - 8 years ago 2017-07-03 14:37:10
tombannink@gmail.com
Remove spectrum computation from canonical switchchain
3 files changed with 28 insertions and 28 deletions:
0 comments (0 inline, 0 general)
cpp/graph_powerlaw.hpp
Show inline comments
 
@@ -12,19 +12,16 @@ void generatePowerlawGraph(int n, float tau, Graph& g, DegreeSequence& ds,
 

	
 
    // Generate a graph
 
    // might require multiple tries
 
    for (int i = 1;; ++i) {
 
        std::generate(ds.begin(), ds.end(),
 
                      [&degDist, &rng] { return degDist(rng); });
 
        // First make the sum even
 
        // First check if the sum is even
 
        unsigned int sum = std::accumulate(ds.begin(), ds.end(), 0);
 
        if (sum % 2) {
 
        if (sum % 2)
 
            continue;
 
            // Can we do this: ??
 
            ds.back()++;
 
        }
 

	
 
        if (g.createFromDegreeSequence(ds))
 
            break;
 

	
 
        // When 10 tries have not worked, output a warning
 
        if (i % 10 == 0) {
 
@@ -38,16 +35,14 @@ void generateCanonicalPowerlawGraph(int n, float tau, Graph &g,
 
                                    DegreeSequence &ds) {
 
    ds.resize(n);
 
    powerlaw_distribution degDist(tau, 1, n);
 
    degDist.getFixedDistribution(n, ds.begin());
 

	
 
    unsigned int sum = std::accumulate(ds.begin(), ds.end(), 0);
 
    if (sum % 2) {
 
        //TODO: Can we do this: ??
 
    if (sum % 2)
 
        ds.back()++;
 
    }
 

	
 
    if (g.createFromDegreeSequence(ds))
 
        return;
 
    g.reset(n);
 
    std::cerr << "ERROR: Canonical ds is not graphical" << std::endl;
 
}
cpp/switchchain_canonical_properties.cpp
Show inline comments
 
@@ -75,13 +75,14 @@ int main(int argc, char* argv[]) {
 
    outfile << "mixingTime: 50 * (50 - 30 (tau - 2)) n\n";
 
    outfile << "data:\n";
 
    outfile << "1: {n,tau}\n";
 
    outfile << "2: avgTriangles\n";
 
    outfile << "3: edges\n";
 
    outfile << "4: dstn\n";
 
    outfile << "5: { HH A, HH L, average A, average L }  where for each there is (average of) {lambda1 , lambda1 - lambda2, lambda1/lambda2}\n";
 
    //outfile << "5: { HH A, HH L, average A, average L }  where for each there is (average of) {lambda1 , lambda1 - lambda2, lambda1/lambda2}\n";
 
    outfile << "5: empty\n";
 
    outfile << "6: switching successrate after mixing\n";
 
    outfile << "7: initial HH triangles\n";
 
    outfile << "*)" << std::endl;
 

	
 
    // Mathematica does not accept normal scientific notation
 
    outfile << std::fixed;
 
@@ -124,56 +125,59 @@ int main(int argc, char* argv[]) {
 
                return {l1, l1 - l2, l1 / l2};
 
            };
 

	
 
            GraphSpectrum gs_start(g);
 
            GraphSpectrum gs(chain.g);
 

	
 
            HHAspectrum =
 
                getSpectralValues(gs_start.computeAdjacencySpectrum());
 
            HHLspectrum =
 
                getSpectralValues(gs_start.computeLaplacianSpectrum());
 
            HHAspectrum.fill(0);
 
            HHLspectrum.fill(0);
 
            //HHAspectrum =
 
            //    getSpectralValues(gs_start.computeAdjacencySpectrum());
 
            //HHLspectrum =
 
            //    getSpectralValues(gs_start.computeLaplacianSpectrum());
 

	
 
            long long trianglesTotal = 0;
 
            int movesDone = 0;
 
            avgAspectrum.fill(0);
 
            avgLspectrum.fill(0);
 
            for (int i = 0; i < measurements; ++i) {
 
                for (int j = 0; j < measureSkip; ++j)
 
                    if (chain.doMove())
 
                        ++movesDone;
 
                trianglesTotal += chain.g.countTriangles();
 
                auto sA = getSpectralValues(gs.computeAdjacencySpectrum());
 
                auto sL = getSpectralValues(gs.computeLaplacianSpectrum());
 
                for (auto i = 0u; i < 3; ++i) {
 
                    avgAspectrum[i] += sA[i];
 
                    avgLspectrum[i] += sL[i];
 
                }
 
                //auto sA = getSpectralValues(gs.computeAdjacencySpectrum());
 
                //auto sL = getSpectralValues(gs.computeLaplacianSpectrum());
 
                //for (auto i = 0u; i < 3; ++i) {
 
                //    avgAspectrum[i] += sA[i];
 
                //    avgLspectrum[i] += sL[i];
 
                //}
 
            }
 
            float avgTriangles = float(trianglesTotal) / float(measurements);
 
            float successrate =
 
                float(movesDone) / float(measurements * measureSkip);
 
            for (auto &f : avgAspectrum)
 
                f /= float(measurements);
 
            for (auto &f : avgLspectrum)
 
                f /= float(measurements);
 

	
 
            std::cout << "Measuring done." << std::flush;
 
            std::cout << "Measuring done. " << std::flush;
 

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

	
 
            outfile << '{' << '{' << numVertices << ',' << tau << '}';
 
            outfile << ',' << avgTriangles;
 
            outfile << ',' << g.edgeCount();
 
            outfile << ',' << getDSTN(ds);
 
            outfile << ',' << '{' << HHAspectrum;
 
            outfile << ',' << HHLspectrum;
 
            outfile << ',' << avgAspectrum;
 
            outfile << ',' << avgLspectrum;
 
            outfile << '}';
 
            outfile << ",{}";
 
            //outfile << ',' << '{' << HHAspectrum;
 
            //outfile << ',' << HHLspectrum;
 
            //outfile << ',' << avgAspectrum;
 
            //outfile << ',' << avgLspectrum;
 
            //outfile << '}';
 
            outfile << ',' << successrate;
 
            outfile << ',' << g.countTriangles();
 
            outfile << '}' << std::flush;
 

	
 
            std::cout << "Output done." << std::endl;
 
        }
triangle_exponent_plots.m
Show inline comments
 
@@ -85,15 +85,16 @@ Show[ListPlot[{averagesExponents,mediansExponents},Joined->True,PlotMarkers->Aut
 

	
 

	
 
(* ::Subsection:: *)
 
(*T(\[Tau]) including error bars*)
 

	
 

	
 
(* For visual, shift the tau values slightly left or right to distinguish the two datasets *)
 
tauValues=averagesGrouped[[All,1,1,1,2]];
 
averagesExponentsErrorBars=Map[{{#[[1]],#[[2]]["BestFitParameters"][[2]]},ErrorBar[#[[2]]["ParameterConfidenceIntervals"][[2]]-#[[2]]["BestFitParameters"][[2]]]}&,
 
Transpose[{tauValues,averagesFitsExtra}]];
 
Transpose[{tauValues-0.005,averagesFitsExtra}]];
 
mediansExponentsErrorBars=Map[{{#[[1]],#[[2]]["BestFitParameters"][[2]]},ErrorBar[#[[2]]["ParameterConfidenceIntervals"][[2]]-#[[2]]["BestFitParameters"][[2]]]}&,
 
Transpose[{tauValues+0.01,mediansFitsExtra}]];
 
plot2=Show[ErrorListPlot[{averagesExponentsErrorBars,mediansExponentsErrorBars},Joined->True,PlotMarkers->Automatic,Frame->True,FrameLabel->{"tau","triangle exponent"},PlotRange->{{2,3},{0,1.6}},ImageSize->300],Plot[3/2(3-tau),{tau,2,3},PlotStyle->{Dashed}]]
 
Transpose[{tauValues+0.005,mediansFitsExtra}]];
 
plot4=Show[ErrorListPlot[{averagesExponentsErrorBars,mediansExponentsErrorBars},Joined->True,PlotMarkers->Automatic,Frame->True,FrameLabel->{"tau","triangle exponent"},PlotRange->{{2,3},{0,1.6}},ImageSize->300],Plot[3/2(3-tau),{tau,2,3},PlotStyle->{Dashed}]]
 

	
 

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