pygsp icon indicating copy to clipboard operation
pygsp copied to clipboard

Add a graph learning module

Open nperraud opened this issue 5 years ago • 20 comments

Add a small module to learn the graph from the signals.

From the user side, he can simply use the class LearnGraph.

nperraud avatar Aug 19 '19 12:08 nperraud

@kalofolb It would be great if you have a look at the code and the doc. Ideally you could make a small tutorial, similarly to https://github.com/epfl-lts2/pygsp/tree/master/doc/tutorials @mdeff The code is based on this branch https://github.com/epfl-lts2/pygsp/tree/naspert-nn_refactor It should be merged after the other one.

nperraud avatar Aug 19 '19 12:08 nperraud

Coverage Status

Coverage increased (+0.7%) to 88.409% when pulling 27ed937a3eefe6138d20de93360ae2d41d8cd258 on learngraphnew into 49ff67918d7d7b723cfa58d1bee017809627bd6b on master.

coveralls avatar Aug 19 '19 13:08 coveralls

@nperraud, what is the status of this PR? Did @kalofolb check?

Some comments:

  • It would be great to have an example or tutorial about this.
  • Can we find a more precise and less generic name than pygsp.graphs.LearnGraph? (Also, don't use a verb for class names.)
  • What is nn.py and nn-test.py in the root directory? That surely doesn't belong there.
  • I will move pygsp/_nearest_neighbor.py into the pygsp.graphs package in #43.
  • Don't add
    if __name__ == '__main__':
        unittest.main()
    
    in test modules. You can partially run the test suite, at various degrees of granularity, as follows:
    $ python -m unittest pygsp.tests.test_docstrings.suite_reference
    $ python -m unittest pygsp.tests.test_graphs.TestImportExport
    $ python -m unittest pygsp.tests.test_graphs.TestImportExport.test_save_load
    

mdeff avatar Nov 09 '19 23:11 mdeff

Did not hear from @kalofolb , I should probably do it myself.

  • I will do a tutorial, but this should not prevent you for merging this PR
  • I removed the nn.py and nn-test.py files.
  • I removed
    if __name__ == '__main__':
        unittest.main()
    
  • I am not sure for the name... We could use LearnedGraph? But it is still a verb... Any idea?

nperraud avatar Nov 10 '19 08:11 nperraud

Thanks! Yeah, we can do the tutorial in a separate PR.

My problem with the name is that LearnGraph is too generic. There are many ways to infer a graph from a set of features, like NearestNeighborsGraph. In my opinion, the name should give some information about how it does it, again like NearestNeighborsGraph.

mdeff avatar Nov 10 '19 09:11 mdeff

Here the method is based on smoothness, but I am not sure that this does help for the name. Another way might be that the classe LearnedGraph would take an argument to switch between learning methods. I would not consider a NNGraph as a learned graph.

nperraud avatar Nov 10 '19 09:11 nperraud

Better to keep one class per method (the separation is clear and the parameters would be messy otherwise).

Well, NNGraph also builds a graph from a set of features. The difference is in the assumptions the methods make about the features.

What about something like graphs.LearnFromSmoothSignals? Not sure about learn or infer, nor signals or features or data. (Alternative methods would go as graphs.Learn*.)

BTW, graphs.NNGraph should probably be renamed graphs.NearestNeighbors. Will do in #43.

mdeff avatar Nov 10 '19 09:11 mdeff

I think it should be LearnedFromSmoothSignals following your idea to not put verbs in class. I think we should keep the word Learned. I am OK with it, but it is not great... Shall I rename the file LearnGraph.py to LearnedGraph.py in the spirit that we put all future LearnedGraph there?

nperraud avatar Nov 10 '19 10:11 nperraud

Let's think a bit more about the name. If we'll group them, you can name the module graphs/learned.py.

mdeff avatar Nov 10 '19 10:11 mdeff

Did not hear from @kalofolb , I should probably do it myself.

Hi guys, I will do the tutorial! Using new account, didn't take check the old one and missed the conversation.

About the name: if we call it "LearnFromSmoothSignals" it doesn't separate between my method and the one of Dong etal. The separation comes from the regularisation of the degrees vector, so there could be a parameter "method" or "model" with choices between "l2_degrees" or "log_degrees" or similar. But as @mdeff said, then we have different sets of parameters... So how do we name mine versus he one of Dong etal? LearnFromSmoothSignalsLog vs LearnFromSmoothSignalsL2?

kalofolias avatar Nov 11 '19 12:11 kalofolias

Good to hear from you @kalofolias! Thanks for the tutorial.

Do you like LearnedFromSmoothSignals as a name? Any other idea? Are there settings where we'd prefer Dong et al. over this one? If not, we might as well not wonder about the difference. Will it be implemented? If not, we can think about differentiating the methods when it'll be.

mdeff avatar Nov 11 '19 13:11 mdeff

Yeah, I think it's an ok name... I can't think of a better one myself. The settings where Dong et al performs better are spotty, but I might implement it for completeness and comparison reasons later.

kalofolias avatar Nov 11 '19 19:11 kalofolias

I have renamed the graph... But the import is a bit dirty in the __init__.py. To make it clean, I would need to make a subfolder I think. @mdeff I think that you wanted to eventually remove the folder for the nngraphs. Let me know what you want me to do. Also, do you want me to make the code more pep8?

nperraud avatar Nov 15 '19 16:11 nperraud

Hi guys, First tutorial is ready! I need permissions with this account to push. I also made some improvements to the code by @nperraud and fixed a bug (the distances in matrix Z have to be squared!).

kalofolias avatar Nov 17 '19 23:11 kalofolias

I cannot give you access... @mdeff , does he really need permission? If yes, can you add him?

nperraud avatar Nov 19 '19 14:11 nperraud

Thanks for your patience. @kalofolias, you should have received an invitation. Upon accepting, you should be able to push your changes to this branch. Thanks for the tutorial!

mdeff avatar Jan 17 '20 14:01 mdeff

Just found a small bug. @kalofolias , please pull

nperraud avatar May 14 '20 20:05 nperraud

oh actually you found it as well sorry

nperraud avatar May 14 '20 20:05 nperraud

Is @kalofolias actively using this? Can we push his improvements and tutorial while we have it in our mind? Thanks :)

mdeff avatar May 14 '20 21:05 mdeff

@nperraud: why wasn't this bug caught by the unit tests? Can we add some to avoid further issues?

mdeff avatar May 14 '20 21:05 mdeff