Commit 930333bc authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

correlations: fix weighted standard deviation

parent 69151d75
......@@ -77,13 +77,14 @@ struct get_avg_correlation
s_sum2.gather();
s_count.gather();
for (size_t i = 0; i < sum.get_array().size(); ++i)
auto& asum = sum.get_array();
auto& asum2 = sum2.get_array();
auto& acount = count.get_array();
for (size_t i = 0; i < asum.size(); ++i)
{
sum.get_array()[i] /= count.get_array()[i];
sum2.get_array()[i] =
sqrt(abs(sum2.get_array()[i]/count.get_array()[i] -
sum.get_array()[i] * sum.get_array()[i])) /
sqrt(count.get_array()[i]);
asum[i] /= acount[i];
asum2[i] = sqrt(abs(asum2[i] / acount[i] -
asum[i] * asum[i])) / sqrt(acount[i]);
}
bins = sum.get_bins();
......
......@@ -46,11 +46,10 @@ public:
typename Hist::point_t k;
typedef typename Hist::point_t::value_type val_t;
k[0] = val_t(deg1(v, g));
typename graph_traits<Graph>::out_edge_iterator e, e_end;
for (tie(e,e_end) = out_edges(v, g); e != e_end; ++e)
for (auto e : out_edges_range(v, g))
{
k[1] = deg2(target(*e,g),g);
hist.put_value(k, get(weight, *e));
k[1] = deg2(target(e, g),g);
hist.put_value(k, get(weight, e));
}
}
......@@ -63,13 +62,13 @@ public:
typename Sum::point_t k1;
k1[0] = deg1(v, g);
typename Sum::count_type k2;
typename graph_traits<Graph>::out_edge_iterator e, e_end;
for (tie(e,e_end) = out_edges(v, g); e != e_end; ++e)
for (auto e : out_edges_range(v, g))
{
k2 = deg2(target(*e,g),g)*get(weight, *e);
sum.put_value(k1, k2);
sum2.put_value(k1, k2*k2);
count.put_value(k1, get(weight, *e));
k2 = deg2(target(e, g), g);
auto w = get(weight, e);
sum.put_value(k1, k2 * w);
sum2.put_value(k1, k2 * k2 * w);
count.put_value(k1, w);
}
}
};
......
Supports Markdown
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