Commit 479e4da0 authored by Tiago Peixoto's avatar Tiago Peixoto

* fix clustering and add jackknife variance

* fix history temp file handling buglet


git-svn-id: https://svn.forked.de/graph-tool/trunk@10 d4600afd-f417-0410-95de-beed9576f240
parent 3412e2df
......@@ -333,7 +333,9 @@ def parse_option(opt, just_file=False):
elif opt.name == "global-clustering-coefficient":
if just_file:
return opt.value
return (graph.GetGlobalClustering(), opt.value)
(avg, dev) = graph.GetGlobalClustering()
ret = "%f\t%f" % (avg, dev)
return (ret, opt.value)
elif opt.name == "set-local-clustering-to-property":
if just_file:
return None
......@@ -499,7 +501,7 @@ class HistoryFile:
self.file_name = os.path.expanduser(file_name)
self.prefixes = set()
self.file = None
self.time = time.clock()
self.time = clock()
self.temp = self.file_name + "___temp"
if self.file_name.endswith(".bz2"):
self.temp = self.file_name.rstrip(".bz2") + "___temp.bz2"
......@@ -561,10 +563,10 @@ class HistoryFile:
def write(self, data, prefix):
write_data(data, self.file, prefix)
if time.clock() - self.time > self.rate:
if clock() - self.time > self.rate:
self.file.close()
self.refresh()
self.time = time.clock()
self.time = clock()
# signal handling
graph.InitSignalHandling()
......@@ -596,7 +598,7 @@ try:
history_files = dict() # open history files
variables = dict() # template variables
exec values[0] in variables #init
exec "___continue = %s" % values[2] in variables # condition
exec "___continue = %s" % values[1] in variables # condition
count = 0
while variables["___continue"]:
for opt in histories:
......@@ -620,9 +622,10 @@ try:
else:
parse_option(new_opt)
exec values[1] in variables # step
exec "___continue = %s" % values[2] in variables # condition
exec values[2] in variables # step
exec "___continue = %s" % values[1] in variables # condition
count += 1
del history_files
except (OptionError, HistoryException), e:
print "graph-tool:", e
......
......@@ -82,7 +82,7 @@ public:
//clustering
void SetLocalClusteringToProperty(std::string property);
double GetGlobalClustering() const;
std::pair<double,double> GetGlobalClustering();
// other
hist_t GetComponentSizeHistogram() const;
......
......@@ -99,7 +99,7 @@ pair<int,int> get_triangles(typename graph_traits<Graph>::vertex_descriptor v, c
struct get_global_clustering
{
template <class Graph>
void operator()(const Graph &g, double &c) const
void operator()(const Graph &g, double &c, double &c_err) const
{
size_t triangles = 0, n = 0;
pair<size_t, size_t> temp;
......@@ -111,17 +111,30 @@ struct get_global_clustering
triangles += temp.first;
n += temp.second;
}
c = double(triangles)/(3*n);
c = double(triangles)/n;
// "jackknife" variance
c_err = 0.0;
for(v = v_begin; v != v_end; ++v)
{
temp = get_triangles(*v, g);
double cl = double(triangles - temp.first)/(n - temp.second);
c_err = (c - cl)*(c - cl);
}
c_err = sqrt(c_err);
}
};
double
GraphInterface::GetGlobalClustering() const
pair<double,double>
GraphInterface::GetGlobalClustering()
{
double c;
check_filter(*this, bind<void>(get_global_clustering(), _1, var(c)), reverse_check(), directed_check());
return c;
double c, c_err;
bool directed = _directed;
_directed = false;
check_filter(*this, bind<void>(get_global_clustering(), _1, var(c), var(c_err)), reverse_check(), always_undirected());
_directed = directed;
return make_pair(c,c_err);
}
//==============================================================================
......@@ -166,7 +179,10 @@ void GraphInterface::SetLocalClusteringToProperty(string property)
typedef associative_property_map<map_t> clust_map_t;
clust_map_t clust_map(vertex_to_clust);
check_filter(*this, bind<void>(set_clustering_to_property(), _1, var(clust_map)), reverse_check(), directed_check());
bool directed = _directed;
_directed = false;
check_filter(*this, bind<void>(set_clustering_to_property(), _1, var(clust_map)), reverse_check(), always_undirected());
_directed = directed;
try
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment