yquetzal / onmi Goto Github PK
View Code? Open in Web Editor NEWoverlapping nmi
overlapping nmi
I found that if I passed two list parameters to the onmi method,it will cause an error
as "unsupported operand type(s) for -: 'set' and 'list' ".It happened in funciton __com_pair_conditional_entropy,in line
a =len((allNodes - cl) - clKnown)/nbNodes
b = len(clKnown-cl)/nbNodes
c = len(cl-clKnown)/nbNodes
d = len(cl & clKnown)/nbNodes
So I turned the variable allNodes to list at first,to solve the "set and list" problem,but it still was an error."unsupported operand type(s) for -: 'list' and 'list'".I guessed it was the operator error.
Finally,I fixed this bug ,codes are followed.
def __com_pair_conditional_entropy(cl, clKnown, allNodes): #cl1,cl2, snapshot_communities (set of nodes)
#H(Xi|Yj ) =H(Xi, Yj ) − H(Yj )
# h(a,n) + h(b,n) + h(c,n) + h(d,n)
# −h(b + d, n)−h(a + c, n)
#a: count agreeing on not belonging
#b: count disagreeing : not in 1 but in 2
#c: count disagreeing : not in 2 but in 1
#d: count agreeing on belonging
nbNodes = len(allNodes)
nodesC1=list(set(allNodes).difference(set(cl)))
nodesC1Known=list(set(nodesC1).difference(set(clKnown)))
a =len(nodesC1Known)/nbNodes
knownC1=list(set(clKnown).difference(set(cl)))
b = len(knownC1)/nbNodes
c1Known=list(set(cl).difference(set(clKnown)))
c = len(c1Known)/nbNodes
c1AndKnown=list(set(cl).intersection(set(clKnown)))
d = len(c1AndKnown)/nbNodes
if __partial_entropy_a_proba(a)+__partial_entropy_a_proba(d)>__partial_entropy_a_proba(b)+__partial_entropy_a_proba(c):
entropyKnown=sp.stats.entropy([len(clKnown)/nbNodes,1-len(clKnown)/nbNodes],base=logBase)
conditionalEntropy = sp.stats.entropy([a,b,c,d],base=logBase) - entropyKnown
#print("normal",entropyKnown,sp.stats.entropy([a,b,c,d],base=logBase))
else:
conditionalEntropy = sp.stats.entropy([len(cl)/nbNodes,1-len(cl)/nbNodes],base=logBase)
#print("abcd",a,b,c,d,conditionalEntropy,cl,clKnown)
return conditionalEntropy #*nbNodes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.