Skip to content

Directed laplacian#741

Merged
hagberg merged 22 commits intonetworkx:masterfrom
aweinstein:directed_laplacian
Jan 6, 2013
Merged

Directed laplacian#741
hagberg merged 22 commits intonetworkx:masterfrom
aweinstein:directed_laplacian

Conversation

@aweinstein
Copy link
Copy Markdown
Contributor

I added a function to get the laplacian of a directed graph. It is based on Ben Edwards' code.

Code based on
https://bitbucket.org/bedwards/networkx-community/src/370bd69fc02f/networkx/algorithms/community/

I refactored Ben Edwards code to one function. This matchs the format of the
other functions in the file and allows to import numpy inside the function.
@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jul 22, 2012

This looks good and could use some tests.

I see you have modified what @bjedwards to use NumPy eigensolvers instead of the power method.
That is probably a good move for small graphs but for larger graphs we'll want sparse matrix representations. I think that is where we were headed with that code. Ben do you recall what our plans were?

The bigger picture is that we will want to provide sparse matrix versions for all of the functions in networkx/linalg - but that is a bigger project and should be a new issue.

@aweinstein
Copy link
Copy Markdown
Contributor Author

I tried to keep Ben's code as intact as possible.

Another option is to use the power method implemented in the Pagerank algorithm. Or may be we can have a parameter that determine what algorithm (power method, eig, eigs) we use to compute the Perron vector.

@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jul 22, 2012

Let's put your version in (with some tests) and then open another issue to create a sparse matrix version.

@bjedwards
Copy link
Copy Markdown
Member

I think the plan was to provide a power method version, a numpy version, and a sparse matrix version, then import based on what is available.

I think part of the consensus was if you are doing spectral graph theory, you like have numpy or scipy installed. So we could potentially make these modules require numpy and not provide a power method version.

Moreover, I don't think numpy is as big of a dependency hassle as it used to be, so I actually wouldn't be opposed to just making it a requirement for networkx, but that is a horse of a different color.

@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jul 22, 2012

On Sun, Jul 22, 2012 at 4:06 PM, Ben Edwards
reply@reply.github.com
wrote:

I think the plan was to provide a power method version, a numpy version, and a sparse matrix version, then import based on what is available.

I think part of the consensus was if you are doing spectral graph theory, you like have numpy or scipy installed. So we could potentially make these modules require numpy and not provide a power method version.

Moreover, I don't think numpy is as big of a dependency hassle as it used to be, so I actually wouldn't be opposed to just making it a requirement for networkx, but that is a horse of a different color.

I don't mind part of networkx depending on numpy and scipy (as it does
now). For the spectral graph theory part of networkx it is required.
One thing we might consider doing is not importing the linear algebra
tools automatically, i.e. require from networkx import linalg (or
whatever name). That could make the dependency handling simpler.

One idea that occurred to me is to make all of the linalg functions
return scipy sparse matrices and then just call .todense() to get a
full matrix. What are the performance implications of that?

Anyway - I don't want to get too far off track. I think with some
tests and docs Alejandro's pull request is good.

@aweinstein
Copy link
Copy Markdown
Contributor Author

@hagberg I added some tests for the directed laplacian.

bwreilly pushed a commit to bwreilly/networkx that referenced this pull request Jul 26, 2012
Addresses networkx#741

There may still be more that need fixing since

1) NumPy and some other optional packages do not yet work with Python3.3 so those tests weren't checked

2) Finding these errors by running the tests is nondeterministic itself (e.g. passes 4 times and fails on the 5th).  And inspecting all of the tests by hand is error-prone too.
@jtorrents
Copy link
Copy Markdown
Member

Test results for commit 96c0bd1 merged into master
Platform: linux2

Not available for testing:

@aweinstein
Copy link
Copy Markdown
Contributor Author

@jtorrents I removed the print statement that caused the python 3.2 failure. (See 92709b4. The print shouldn't be there in the first place).

@jtorrents
Copy link
Copy Markdown
Member

Test results for commit 92709b4 merged into master
Platform: linux2

  • python2.6: OK
  • python2.7: OK
  • python3.2: OK

@jtorrents
Copy link
Copy Markdown
Member

Alejandro,

Thanks for the quick response. I'm adapting an IPython script for testing
NetworkX pull requests, while testing yours noticed the error and wanted to
test that the gist part works. It's very neat and will be very useful.

I'm preparing a pull request with the adapted script.

2012/8/7 Alejandro Weinstein notifications@github.com

@jtorrents https://github.com/jtorrents I removed the print statement
that caused the python 3.2 failure in 92709b492709b4(the
print shouldn't be there in the first place).


Reply to this email directly or view it on GitHubhttps://github.com//pull/741#issuecomment-7557509.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the decorator `require' from networkx/utils/decorators.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Midnighter Done in ede03b2. I also added a not_implemented_for decorator.

The require decorator can also be added to the other functions in laplacianmatrix.py. Is it OK to do it in this PR, or is it better to modify this in another one?

@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jan 4, 2013

NetworkX: Test results for pull request #741 (aweinstein 'directed_laplacian' branch)
✳️ This pull request can be merged cleanly (commit ede03b2 into NetworkX master ef11bff)
Platform: linux2

  • python2.6: ✳️ OK (SKIP=59) Ran 1532 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: ✳️ OK (SKIP=None) Ran 1723 tests
  • python3.2: ✳️ OK (SKIP=6) Ran 1702 tests (libraries not available: ogr, pygraphviz, pydot)
  • python3.3: ✳️ OK (SKIP=37) Ran 1596 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)

@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jan 5, 2013

I can't seem to figure out how to merge this correctly (which is likely my inexperience with git). @aweinstein can you look at it? I'd like to include this code for the networkx-1.8 release.

Fix missing SkipTest import in utils tests
@aweinstein
Copy link
Copy Markdown
Contributor Author

@hagberg I can help, but I don't know exactly how.

Is it enough if I figure it out how to merge this into my master branch?

@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jan 5, 2013

I think if you can rebase your changes on the latest master then it would work.

@aweinstein
Copy link
Copy Markdown
Contributor Author

@hagberg I did the rebase and fixed some conflicts. Please let me know if this fixed the problem.

@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jan 6, 2013

Looks good, thanks! I'll review it and do the merge if it all is OK.

@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jan 6, 2013

NetworkX: Test results for pull request #741 (aweinstein 'directed_laplacian' branch)
✳️ This pull request can be merged cleanly (commit 4f6b5ae into NetworkX master fd11407)
Platform: linux2

  • python2.6: ✳️ OK (SKIP=60) Ran 1533 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: ✳️ OK (SKIP=None) Ran 1724 tests
  • python3.2: ✳️ OK (SKIP=6) Ran 1703 tests (libraries not available: ogr, pygraphviz, pydot)
  • python3.3: ✳️ OK (SKIP=37) Ran 1597 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)

hagberg added a commit that referenced this pull request Jan 6, 2013
@hagberg hagberg merged commit 38e47ff into networkx:master Jan 6, 2013
@hagberg
Copy link
Copy Markdown
Member

hagberg commented Jan 6, 2013

I added some updates in #811 to address some formatting and naming issues.

@aweinstein aweinstein deleted the directed_laplacian branch January 6, 2013 19:22
@antoniopugliese
Copy link
Copy Markdown

Question:

Shouldn't the directed_laplacian_matrix function be a normalized_directed_laplacian_matrix function?
This function uses the normalized formula
L = I - (\Phi^{1/2} P \Phi^{-1/2} + \Phi^{-1/2} P^T \Phi^{1/2} ) / 2

For a directed_laplacian_matrix the combinatorial (non normalized) formula should be used
L = \Phi - (\Phi P + P^T \Phi) / 2

What do you people think about this modification? I am also new to Github, so sorry if there is another way to have you notice this.

@jfinkels
Copy link
Copy Markdown
Contributor

Hi @antoniopugliese, thanks for contributing. Can you please create a new issue containing your question so that we can track its resolution separately from this pull request? (Feel free to reference this pull request when you create the issue.)

@aweinstein
Copy link
Copy Markdown
Contributor Author

@antoniopugliese @jfinkels We used the definition given in the paper

Fan Chung (2005). Laplacians and the Cheeger inequality for directed graphs. Annals of Combinatorics, 9(1), 2005 (available here http://www.math.ucsd.edu/~fan/wp/dichee.pdf).

This paper just call it "Laplacian". I would call a function returning L = \Phi - (\Phi P + P^T \Phi) / 2 directed_combinatorial_laplacian_matrix.

@antoniopugliese
Copy link
Copy Markdown

@aweinstein @jfinkels
The paper just calls it "Laplacian", but as you can see the formula has a "L" in math cursive, which is used for the normalized Laplacian. Also, in the documentation of the function is reported that the function returns a normalized matrix.

I like the directed_combinatorial_laplacian_matrix name. I used this name in the issue I just created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

7 participants