Skip to content

Commit

Permalink
Omega index evaluation fixed for the case of a node shared by all clu…
Browse files Browse the repository at this point in the history
…sters
  • Loading branch information
luav committed Dec 27, 2019
1 parent e3d3032 commit 65e7dce
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 45 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ LD = g++
WINDRES = windres

INC = -Iinclude -Iautogen -Ishared
CFLAGS = -Wnon-virtual-dtor -Winit-self -Wcast-align -Wundef -Wfloat-equal -Wunreachable-code -Wmissing-include-dirs -Weffc++ -Wzero-as-null-pointer-constant -std=c++14 -fexceptions -fstack-protector-strong -Wno-float-equal -D_FORTIFY_SOURCE=2
CFLAGS = -Wnon-virtual-dtor -Winit-self -Wcast-align -Wundef -Wfloat-equal -Wunreachable-code -Wmissing-include-dirs -Weffc++ -Wzero-as-null-pointer-constant -Wall -std=c++14 -fexceptions -fstack-protector-strong -fstack-clash-protection -Werror=format-security -Wold-style-cast -Wno-float-equal -D_FORTIFY_SOURCE=2
RESINC =
LIBDIR =
LIB = -lstdc++fs
LDFLAGS =
LDFLAGS = -Wl,-z,defs

INC_DEBUG = $(INC)
CFLAGS_DEBUG = $(CFLAGS) -Wredundant-decls -Winline -Wswitch-default -Wmain -Wall -g -DDEBUG -D_GLIBCXX_DEBUG -DTRACE=2 -DVALIDATE=2
CFLAGS_DEBUG = $(CFLAGS) -Wredundant-decls -Wswitch-default -Wmain -Wextra -Og -g -fasynchronous-unwind-tables -fsanitize=address -fsanitize=leak -DDEBUG -D_GLIBCXX_DEBUG -D_GLIBCXX_ASSERTIONS -DTRACE=2 -DVALIDATE=2
RESINC_DEBUG = $(RESINC)
RCFLAGS_DEBUG = $(RCFLAGS)
LIBDIR_DEBUG = $(LIBDIR)
LIB_DEBUG = $(LIB)
LIB_DEBUG = $(LIB)-lasan
LDFLAGS_DEBUG = $(LDFLAGS)
OBJDIR_DEBUG = obj/Debug
DEP_DEBUG =
OUT_DEBUG = bin/Debug/xmeasures

INC_RELEASE = $(INC)
CFLAGS_RELEASE = $(CFLAGS) -march=core2 -fomit-frame-pointer -O3 -DTRACE=1 -DVALIDATE=1
CFLAGS_RELEASE = $(CFLAGS) -march=core2 -fomit-frame-pointer -O3 -Wfatal-errors -DTRACE=1 -DVALIDATE=1
RESINC_RELEASE = $(RESINC)
RCFLAGS_RELEASE = $(RCFLAGS)
LIBDIR_RELEASE = $(LIBDIR)
LIB_RELEASE = $(LIB)
LDFLAGS_RELEASE = $(LDFLAGS) -s
LDFLAGS_RELEASE = $(LDFLAGS) -s -Wl,-z,relro,-z,now
OBJDIR_RELEASE = obj/Release
DEP_RELEASE =
OUT_RELEASE = bin/Release/xmeasures
Expand Down
98 changes: 61 additions & 37 deletions include/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,34 @@ using std::domain_error;
using namespace daoc;


//! \brief Extended contribution of the node occurrences in the clusters
//!
//! \param eh AccId& - updating expected contribution of the high (top right) part of the matrix
////! \param const Id csize - max mutual co-occurrence
//! \param icount - co-occurrences of the nodes from the first clustering
//! \param jcount - co-occurrences of the nodes from the second clustering
//! \return void
template <bool EXT=true>
inline void xcontrib(AccId& eh, const RawIds& icount, const RawIds& jcount)
{
const Id csize = min(jcount.size(), icount.size());
const RawIds& rcount = icount.size() > csize ? icount : jcount;
const Id rcsize = rcount.size();
for(Id i = csize; i < rcsize; ++i)
eh += rcount[i];
}

template <>
inline void xcontrib<false>(AccId& eh, const RawIds& icount, const RawIds& jcount)
{}

template <bool EXT=false>
Prob omega(const NodeRClusters& ndrcs, const RawClusters& cls1, const RawClusters& cls2)
{
//using AccContrib = conditional_t<EXT, AccProb, AccId>; // Accumulated contribution of the pair to OI
AccId oh = 0; // Observed contribution of the high (top right) part of the matrix
RawIds icount(cls1.size(), 0);
RawIds jcount(cls2.size(), 0);
RawIds icount(cls1.size() + 1, 0); // Note: + 1 to consider none occurrences
RawIds jcount(cls2.size() + 1, 0);
const auto encs = ndrcs.end();
for(auto iincs = ndrcs.begin(); iincs != encs;) {
auto& incs = *iincs;
Expand All @@ -58,6 +79,8 @@ Prob omega(const NodeRClusters& ndrcs, const RawClusters& cls1, const RawCluster
// , i, AccId(icount[i]) * jcount[i], icount[i], jcount[i]);
eh += AccId(icount[i]) * jcount[i];
}
// Consider remained accumulated counts
xcontrib<EXT>(eh, icount, jcount);
// The number of pairs = nodes_num * (nodes_num - 1) / 2
const AccId npairs = ndrcs.size() * (ndrcs.size() - 1) >> 1;
const AccProb enorm = AccProb(eh) / npairs;
Expand All @@ -66,41 +89,42 @@ Prob omega(const NodeRClusters& ndrcs, const RawClusters& cls1, const RawCluster
return (oh - enorm) / (npairs - enorm);
}

template <>
Prob omega<true>(const NodeRClusters& ndrcs, const RawClusters& cls1, const RawClusters& cls2)
{
AccProb oh = 0; // Observed contribution of the high (top right) part of the matrix
RawIds icount(cls1.size(), 0);
RawIds jcount(cls2.size(), 0);
const auto encs = ndrcs.end();
for(auto iincs = ndrcs.begin(); iincs != encs;) {
auto& incs = *iincs;
// Note: diagonal items for ovp always equal to 1 (or contrib_max) and will be added later
for(auto ijncs = ++iincs; ijncs != encs; ++ijncs) {
const Id inum = mutualnum(&incs.second.first, &ijncs->second.first);
const Id jnum = mutualnum(&incs.second.second, &ijncs->second.second);
oh += inum == jnum ? 1 : AccProb(min(inum, jnum)) / max(inum, jnum);
//eh += AccProb(max<Id>(inum, 1)) * max<Id>(jnum, 1);
++icount[inum];
++jcount[jnum];
}
}
AccProb eh = 0; // Expected contribution of the high (top right) part of the matrix
const Id csize = min(jcount.size(), icount.size());
for(Id i = 0; i < csize; ++i)
eh += AccId(icount[i]) * jcount[i];
// Consider remained accumulated counts
RawIds& rcount = icount.size() > csize ? icount : jcount;
const Id rcsize = rcount.size();
for(Id i = csize; i < rcsize; ++i)
eh += rcount[i];
// The number of pairs = nodes_num * (nodes_num - 1) / 2
const AccId npairs = ndrcs.size() * (ndrcs.size() - 1) >> 1;
const AccProb enorm = AccProb(eh) / npairs;
//printf("> omega() observed: %G, expected normalized: %G, %lu nodes\n"
// , oh, enorm, ndrcs.size());
return (oh - enorm) / (npairs - enorm);
}
//template <>
//Prob omega<true>(const NodeRClusters& ndrcs, const RawClusters& cls1, const RawClusters& cls2)
//{
// AccProb oh = 0; // Observed contribution of the high (top right) part of the matrix
// RawIds icount(cls1.size() + 1, 0); // Note: + 1 to consider none occurrences
// RawIds jcount(cls2.size() + 1, 0);
// const auto encs = ndrcs.end();
// for(auto iincs = ndrcs.begin(); iincs != encs;) {
// auto& incs = *iincs;
// // Note: diagonal items for ovp always equal to 1 (or contrib_max) and will be added later
// for(auto ijncs = ++iincs; ijncs != encs; ++ijncs) {
// const Id inum = mutualnum(&incs.second.first, &ijncs->second.first);
// const Id jnum = mutualnum(&incs.second.second, &ijncs->second.second);
// oh += inum == jnum ? 1 : AccProb(min(inum, jnum)) / max(inum, jnum);
// //eh += AccProb(max<Id>(inum, 1)) * max<Id>(jnum, 1);
// ++icount[inum];
// ++jcount[jnum];
// }
// }
// AccProb eh = 0; // Expected contribution of the high (top right) part of the matrix
// const Id csize = min(jcount.size(), icount.size());
// for(Id i = 0; i < csize; ++i)
// eh += AccId(icount[i]) * jcount[i];
// // Consider remained accumulated counts
// //xcontrib<EXT>(eh, csize, icount, jcount);
// const RawIds& rcount = icount.size() > csize ? icount : jcount;
// const Id rcsize = rcount.size();
// for(Id i = csize; i < rcsize; ++i)
// eh += rcount[i];
// // The number of pairs = nodes_num * (nodes_num - 1) / 2
// const AccId npairs = ndrcs.size() * (ndrcs.size() - 1) >> 1;
// const AccProb enorm = AccProb(eh) / npairs;
// //printf("> omega() observed: %G, expected normalized: %G, %lu nodes\n"
// // , oh, enorm, ndrcs.size());
// return (oh - enorm) / (npairs - enorm);
//}

// Cluster definition ----------------------------------------------------------
template <typename Count>
Expand Down
2 changes: 0 additions & 2 deletions xmeasures.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<Add option="-fasynchronous-unwind-tables" />
<Add option="-fsanitize=address" />
<Add option="-fsanitize=leak" />
<Add option="-fsanitize=undefined" />
<Add option="-DDEBUG" />
<Add option="-D_GLIBCXX_DEBUG" />
<Add option="-D_GLIBCXX_ASSERTIONS" />
Expand All @@ -30,7 +29,6 @@
</Compiler>
<Linker>
<Add library="asan" />
<Add library="ubsan" />
</Linker>
</Target>
<Target title="Release">
Expand Down

0 comments on commit 65e7dce

Please sign in to comment.