Skip to content

Commit

Permalink
renaming constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Sep 21, 2010
1 parent 34cde04 commit 20c249b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Friday July 23rd 2010
"""

__all__ = ["agreement","constraint","coreness","util"]
__all__ = ["agreement","structural_holes","coreness","util"]
18 changes: 2 additions & 16 deletions constraint.py → structural_holes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _neighborsIndexes(graph,node,includeOutLinks,includeInLinks):

return map(lambda x : graph.nodes().index(x),neighbors)

def getConstraints(G,includeOutLinks=True,includeInLinks=False,wholeNetwork=True):
def structural_holes(G,includeOutLinks=True,includeInLinks=False,wholeNetwork=True):
"""
Calculate each node's contraint / structural holes value, as described by Ronal Burt
Expand Down Expand Up @@ -148,18 +148,4 @@ def getConstraints(G,includeOutLinks=True,includeInLinks=False,wholeNetwork=True

constraint["C-Index"] = constraint["C-Size"] + constraint["C-Density"] + constraint["C-Hierarchy"]
constraints[node] = constraint
return constraints

def writeConstraints(constraints,file):
"""
Writes constraints to file in CSV format
file: a file object or a filepath
"""
file = nx.utils._get_fh(file, mode='w')

writer = csv.writer(file)
writer.writerow(["Node","Constraint","C-Size","C-Density","C-Hierarchy"])
for i in constraints:
writer.writerow([i,constraints[i]["C-Index"],constraints[i]["C-Size"],constraints[i]["C-Density"],constraints[i]["C-Hierarchy"]])
file.close()
return constraints
4 changes: 2 additions & 2 deletions unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import unittest
import networkx as nx
import agreement
import constraint
import structural_holes
import coreness
import brokerage
import triadic_census
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_constraint(self):
for type,graph in self.graphs.iteritems():
for params,shouldBe in runs.iteritems():
msg = "Incorrect calculation of constraint for graph type: " + type + " with parameters: " + str(params)
constraints = constraint.getConstraints(graph,*params)
constraints = structural_holes.structural_holes(graph,*params)
# currently only checking cIndex
cIndexes = dict((n,c["C-Index"]) for n,c in constraints.iteritems())
for k,v in cIndexes.iteritems():
Expand Down

0 comments on commit 20c249b

Please sign in to comment.