Code Monkey home page Code Monkey logo

onmi's People

Contributors

yquetzal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

onmi's Issues

When using operator '-' and '&' to calculate difference set or intersection,it will cause an error

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.