Files
@ 4b6c189e4ae4
Branch filter:
Location: AENC/switchchain/cpp/graph_powerlaw.hpp - annotation
4b6c189e4ae4
1.5 KiB
text/x-c++hdr
Add mixing time analysis using exponential fits
c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d c9c22e41130d 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 32a7f1c13790 | #pragma once
#include "graph.hpp"
#include "powerlaw.hpp"
#include <algorithm>
#include <iostream>
template <typename RNG>
void generatePowerlawGraph(int n, float tau, Graph& g, DegreeSequence& ds,
RNG& rng) {
ds.resize(n);
powerlaw_distribution degDist(tau, 1, n);
// Generate a graph
// might require multiple tries
for (int i = 1;; ++i) {
std::generate(ds.begin(), ds.end(),
[°Dist, &rng] { return degDist(rng); });
// First make the sum even
unsigned int sum = std::accumulate(ds.begin(), ds.end(), 0);
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) {
std::cerr << "Warning: could not create graph from "
"degree sequence. Trying again...\n";
}
}
}
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: ??
ds.back()++;
}
if (g.createFromDegreeSequence(ds))
return;
g.reset(n);
std::cerr << "ERROR: Canonical ds is not graphical" << std::endl;
}
|