Code Monkey home page Code Monkey logo

Comments (5)

kpelechrinis avatar kpelechrinis commented on May 19, 2024 1

@tomermilo actually the following version does not give any problem (essentially it is what you also mentioned I think) and I was able to run the example provided:

==============================================
def custom_exponential_graph(base_graph=None, scale=100, min_num_edges=0, m=9, n=None):
# Generate a random preferential attachment power law graph as a starting point.
# By the way this graph is constructed, it is expected to have 1 connected component.
# Every node is added along with m=8 edges, so the min degree is m=8.
if(base_graph):
graph = base_graph.copy()
else:
assert(n is not None), "Argument n (number of nodes) must be provided when no base graph is given."
graph = networkx.barabasi_albert_graph(n=n, m=m)

# To get a graph with power-law-esque properties but without the fixed minimum degree,
# We modify the graph by probabilistically dropping some edges from each node. 
for node in graph:
    neighbors = list(graph[node].keys())
    quarantineEdgeNum = int( max(min(numpy.random.exponential(scale=scale, size=1), len(neighbors)), min_num_edges) )
    quarantineKeepNeighbors = numpy.random.choice(neighbors, size=quarantineEdgeNum, replace=False)
    for neighbor in neighbors:
        if(neighbor not in quarantineKeepNeighbors):
            graph.remove_edge(node, neighbor)

return graph

from seirsplus.

kpelechrinis avatar kpelechrinis commented on May 19, 2024

I did the same and it solved this problem, but then I had a runtime error

RuntimeError: dictionary changed size during iteration

at the line 1177:

for neighbor in neighbors:

Any thoughts?

from seirsplus.

tomermilo avatar tomermilo commented on May 19, 2024

@kpelechrinis can you send your new custom_exponential_graph function?

from seirsplus.

tomermilo avatar tomermilo commented on May 19, 2024

This is how I fixed it as well. Good luck

from seirsplus.

ryansmcgee avatar ryansmcgee commented on May 19, 2024

The change to list(dict.keys()) has been made throughout the package to make this keys lookup work in both Python 2 and 3. Thank you for flagging this issue.

from seirsplus.

Related Issues (20)

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.