GithubHelp home page GithubHelp logo

netrw's People

Contributors

aaleta avatar coryglover avatar hartle avatar jkbren avatar lfo-po avatar netsiphd avatar nwlandry avatar samwestby avatar sdmccabe avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

netrw's Issues

Enforcing determinism when using PRNGs?

It's not a big deal for now but ultimately we'll want to be able to set seeds for the rewiring algorithms. I see a few possibilities for this:

  1. Use the standard library's random, and set the seed using random.seed($SEED). I don't like this because it mutates global state.
  2. Use numpy's Generator object. This is probably preferable but a bit heavy (and tricky for users).
  3. Add a parameter for passing a random seed at initialization, store a random.Random as an attribute, and call that to generate random numbers.
  4. Do the same, with a np.random.Generator.

I think #3 could look like the following:

class BaseRewirer:
	<...>
	def __init__(seed: Optional[int] = None):
		self.rand = random.Random(seed)
		
	<...>
	def rewire(self, G, **kwargs):
		# selecting a random edge
		rand_edge = rand.choice(list(G.edges))
	<...>

The challenge with using np.random.Generator is that numpy randomness wants to return arrays, which we don't always want (e.g., when sampling edges).

Problems with the Karrer algorithm

I believe that there are a couple of issues with the algorithm:

  • It is unclear if the method is for directed or undirected networks. For instance, imagine that the network is undirected and the link (0,1) exists. The set potential_edges will contain the edge (1,0). Then, one may destroy (0,1) and create (1,0), wasting one rewiring. Or one may destroy (0,2) and add (1,0) when (0,1) already exists. If the method is meant for undirected networks one way to fix this would be to use permutations rather than itertools product.

  • The method should "go through each edge in the original network in turn and with probability alpha we remove it and replace it". The current implementation only checks one link. If the function is called |E| number of times, it is not guaranteed that each time a different edge will be checked.

What tests are appropriate?

In conversations, there are a few constraints that are possible to test:

  1. Enforcing return types (if you pass a DiGraph, you shouldn't get Graph back).
  2. Enforcing equal numbers of nodes and edges after rewiring.
  3. Does the algorithm handle the empty graph and the complete graph correctly?

In general, these algorithms are going to be highly nondeterministic, which presents a challenge for testing them. But ideally we can come up with some things that cover most rewirers (even if we have to have exceptions).

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.