Skip to content

[MRG+2] Making Spectral Embedding Deterministic#4249

Closed
Hasil-Sharma wants to merge 1 commit intoscikit-learn:masterfrom
Hasil-Sharma:my-feature
Closed

[MRG+2] Making Spectral Embedding Deterministic#4249
Hasil-Sharma wants to merge 1 commit intoscikit-learn:masterfrom
Hasil-Sharma:my-feature

Conversation

@Hasil-Sharma
Copy link
Copy Markdown
Contributor

fixes #4236

@Hasil-Sharma Hasil-Sharma changed the title Making Spectral Embedding Deterministic #4236 Making Spectral Embedding Deterministic Feb 15, 2015
@raghavrv
Copy link
Copy Markdown
Member

Thanks for the PR...

3 minor points :

  • Could you squash all commits to 1?
  • Please use WIP / MRG as tags in front of PR title...
  • In the PR description, add "fixes Make spectral_embedding deterministic #4236" to automatically close the issue after this gets merged in

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

axis = 1 --> axis=1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

alternatively you could run flake8 to check for such issues :)

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0%) to 95.04% when pulling b5f91f2 on Hasil-Sharma:my-feature into 5f95154 on scikit-learn:master.

@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing my PR.
I'll do all that you have stated above and would send a new PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This argument is not needed...

@raghavrv
Copy link
Copy Markdown
Member

No no please don't send a new pr... do the following :

  • Just reset your work - git reset HEAD~<NO_OF_COMMITS_MADE_BY_U>
  • Make the changes
  • Recommit
  • Force push to the same branch - git push -u -f my-feature:my-feature

It will get updated here... :)

@Hasil-Sharma Hasil-Sharma changed the title Making Spectral Embedding Deterministic [WIP]Making Spectral Embedding Deterministic Feb 15, 2015
@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

@ragv : Thanks for assisting me so patiently, I have done all that you had mentioned in one of your comments. Please tell if it looks good and if there is anything else that I should do ?

@raghavrv
Copy link
Copy Markdown
Member

You seemed to have reset a few commits that was not made for this PR and added it to a single commit "Making spec..."

Please do a git rebase master to fix that...

@raghavrv
Copy link
Copy Markdown
Member

after the rebase simply do a force push...

@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

Yes, between the commits I had done I have merged the master branch with my-feature to update the my-feature branch. Would git rebase master resolve the issue ?

@raghavrv
Copy link
Copy Markdown
Member

yea :)

@raghavrv
Copy link
Copy Markdown
Member

or wait...

@raghavrv
Copy link
Copy Markdown
Member

do:

  • git rebase -i HEAD~<COMMIT_COUNT_FOR_THIS_PR+1(for merge commit)>
  • delete the line that has the merge commit
  • save and close the file
  • now do a git rebase master

And in general do a git rebase master to update your branch

@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

@ragv : Thanks for assisting me, I think PR is now as it is should be ?

@raghavrv
Copy link
Copy Markdown
Member

LGTM 👍

@raghavrv
Copy link
Copy Markdown
Member

Also can you add test for eigen_sign_flip ? ( to be added to test_spectral_embedding.py )

@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

Thanks :)

Yeah, how should I go about about ?

Creating a random n-array on my own and saving it's correct answer and later checking if random n-array is same as correct answer or simply checking that sign of largest absolute value in array in positive or some way else ?

@raghavrv
Copy link
Copy Markdown
Member

How about both ;)

  • Take an unflipped ( 5 x 5 would be sufficient I think )
  • Check if that array, before flipped, does not have +ve sign for the largest abs val
  • Do flip
  • Check with hardcoded value
  • Check if now, all largest abs are +ve

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you pl. convert this to a comment? ( Related to #4250 )

( also do the same for the test for eigen_sign_flip )

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.

@ragv : This is what I have done, please tell if it would be enough ?

  1. Finding the indexes of maximum absolute value in all the vectors.
  2. Flipping the vector signs by running _eigen_sign_flip
  3. Finding the indexes of maximum value in all the vectors.
  4. Asserting that indexes in step 1 and step 3 are same by using assert_array_equal

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes this is sufficient, I guess

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Feb 17, 2015

@Hasil-Sharma once you have addressed the comments please rename the PR title from [WIP] to [MRG] to make it explicit that this is ready for final review.

@raghavrv
Copy link
Copy Markdown
Member

I'll change [WIP] to [MRG]

Yea sure! :)

BTW could I trouble you with two a few more minor fixes to your code ? :p

@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

Pray tell me minor fixes I should make :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

combine both lines to get
data = np.random.RandomState(36).randn(5, 5)

or if you feel like, could you instead refactor all these out ( since they are repeated across multiple tests ) to the top like
rng = np.random.RandomState(0)
and use rng everywhere inside the tests instead? ( preferably in a separate commit )...
like rng.randn(5, 5) etc... Ignore this... This could perhaps be done in a separate PR...

@raghavrv
Copy link
Copy Markdown
Member

After the above 4 fixes please change from [WIP] to [MRG+1] ! Thanks for working on this!

@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

@ragv : All changes done, and changing [WIP] to [MRG+1] Thanks for guiding me all the way through :)

@Hasil-Sharma Hasil-Sharma changed the title [WIP]Making Spectral Embedding Deterministic [MRG+1]Making Spectral Embedding Deterministic Feb 24, 2015
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would rename this to _deterministic_vector_sign_flip (the _ to keep it a private utility function). This function does not need to work only with eigen vectors of a matrix but any vectors so there is no need to put 'eigen' in the name or docstring.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

@amueller
Copy link
Copy Markdown
Member

After renaming and removing references to this being eigenvectors, +1 for merge.

@Hasil-Sharma
Copy link
Copy Markdown
Contributor Author

All changes done :)

@amueller
Copy link
Copy Markdown
Member

LGTM

@amueller amueller changed the title [MRG+1]Making Spectral Embedding Deterministic [MRG+2] Making Spectral Embedding Deterministic Feb 25, 2015
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I will do the changes myself when merging but FYI PEP8 requires 2 blank lines to separate top level blocks and white spaces around binary operators.

@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented Feb 26, 2015

Merged by rebase, thanks for your contribution @Hasil-Sharma!

@ogrisel ogrisel closed this Feb 26, 2015
@amueller
Copy link
Copy Markdown
Member

Hum, for some reason, adding SpectralEmbedding to the test still fails:
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tests/test_common.py#L107
Maybe that should have been part of the PR.

@raghavrv
Copy link
Copy Markdown
Member

I think this happens since, for the particular input setup, the graph is not fully connected as it warns accordingly... using affinity="rbf" fixes this up... Could you confirm if that fix is correct?

@amueller
Copy link
Copy Markdown
Member

but shouldn't it still be deterministic?

@raghavrv
Copy link
Copy Markdown
Member

I am sorry I do not understand how it works, but from the warning message -

Graph is not fully connected, spectral embedding may not work as expected.

does that mean it can be expected to be non deterministic for input setups which gives a not-fully-connected adj. matrix?

@amueller
Copy link
Copy Markdown
Member

ok but then we should investigate why that is.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make spectral_embedding deterministic

5 participants