Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG+2] DOC correct docstring for sample_gaussian #6957

Merged
merged 3 commits into from
Oct 26, 2016

Conversation

kwohlfahrt
Copy link

Reference Issue

None.

What does this implement/fix? Explain your changes.

Docstring for sklearn.mixture.sample_gaussian did not match function behaviour. Caused some trouble trying to implement a compatible version for a different distribution. Corrects this for future reference.

@tguillemot
Copy link
Contributor

@kwohlfahrt Thanks.
Indeed there is a problem with the doc of the function, but as the GMM class is deprecated, those function will be remove at version 0.20.
I have forgotten to put a deprecation warning to say to use make_blob instead.
Can you add the deprecation warning with your solution ?

@kwohlfahrt
Copy link
Author

Ah. It looks to me like the replacement does not allow for different covariances, is that correct?

@tguillemot
Copy link
Contributor

Indeed you right. I thought that make_blob could have any kind of covariances.
In fact, what you should use is numpy.multivariate_normal which is exactly the sample_gaussian function.

@tguillemot
Copy link
Contributor

LGTM.
Can you change your title to [MRG+1] ?
@agramfort Can you have a look ?

@kwohlfahrt kwohlfahrt changed the title [MRG] DOC correct docstring for sample_gaussian [MRG+1] DOC correct docstring for sample_gaussian Jul 5, 2016
@@ -64,7 +64,8 @@ def log_multivariate_normal_density(X, means, covars, covariance_type='diag'):
return log_multivariate_normal_density_dict[covariance_type](
X, means, covars)


@deprecated("The class function sample_gaussian is deprecated and "
"will be removed in 0.20. Use numpy.multivariate_normal instead.")
Copy link
Member

Choose a reason for hiding this comment

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

if you deprecate a function you need to remove it from everywhere. is this used somewhere? otherwsie the test suite will throw a lot of deprecation warnings

Copy link
Author

Choose a reason for hiding this comment

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

Looking at the logs, there is only one test which uses it, test_sample_gaussian.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you do git grep sample_gaussian, you'll see that the class _GMM uses it.
So we need to create a _sample_gaussian function.

@tguillemot
Copy link
Contributor

@agramfort Sorry I've forgot that.
What I suggest is to create a private function with the name _sample_gaussian and create another public function call sample_gaussian which calls it. We have done a similar thing with the GMM class.

It will solve any problems until we remove completely the old GMM classes.

@agramfort
Copy link
Member

agramfort commented Jul 6, 2016 via email

@tguillemot
Copy link
Contributor

Looking at the logs, there is only one test which uses it, test_sample_gaussian

With git grep sample_gaussian, it appears that the _GMM class uses sample_gaussian in sample.
So we need to create a _sample_gaussian function.

@kwohlfahrt
Copy link
Author

OK. Should the tests that test sample_gaussian directly be moved to the new function as well?

@agramfort
Copy link
Member

Yes

On Thu, Jul 7, 2016 at 7:14 PM +0200, "Kai" [email protected] wrote:

OK. Should the tests that test sample_gaussian directly be moved to the new function as well?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@@ -64,7 +64,8 @@ def log_multivariate_normal_density(X, means, covars, covariance_type='diag'):
return log_multivariate_normal_density_dict[covariance_type](
X, means, covars)


@deprecated("The function sample_gaussian is deprecated and "
"will be removed in 0.20. Use numpy.multivariate_normal instead.")
Copy link
Member

Choose a reason for hiding this comment

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

I suppose it's numpy.random.multivariate_normal

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed it's numpy.random.multivariate_normal.

@agramfort
Copy link
Member

CIs are not happy

@tguillemot
Copy link
Contributor

You have three other things to change in test_gmm.py:

  • add the import from sklearn.mixture.gmm import _sample_gaussian
  • remove all the mixture. before sample_gaussian
  • change the comment l26 #Test sample generation from mixture.sample_gaussian... to ... gmm._sample_gaussian...
  • remove the import l59 from sklearn.mixture import sample_gaussian

@tguillemot
Copy link
Contributor

tguillemot commented Jul 12, 2016

I think the appveyor failure is unrelated but to be sure can you do git commit --amend; git push -f.

@@ -64,7 +64,9 @@ def log_multivariate_normal_density(X, means, covars, covariance_type='diag'):
return log_multivariate_normal_density_dict[covariance_type](
X, means, covars)


@deprecated("The function sample_gaussian is deprecated and "
Copy link
Member

Choose a reason for hiding this comment

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

Please add the version they were deprecated in to the message (was deprecated in 0.18)

@amueller amueller changed the title [MRG+1] DOC correct docstring for sample_gaussian [MRG+2] DOC correct docstring for sample_gaussian Jul 28, 2016
@amueller
Copy link
Member

amueller commented Jul 28, 2016

LGTM apart from adding the deprecation version. This was not superseded by #7012, was it?

@tguillemot
Copy link
Contributor

@amueller No as @kwohlfahrt was working on it I didn't want to remove his work.
@kwohlfahrt Can you fix the comments ?

Docstring did not match function behaviour. Caused some trouble trying to implement a compatible version for a different distribution.
Kai Wohlfahrt added 2 commits October 3, 2016 16:04
This avoids triggering the deprecation warning. sample_gaussian is just a thin
wrapper.
_sample_gaussian is not publicly exported in mixture, so use gmm module.
@kwohlfahrt
Copy link
Author

Hi all, sorry I dropped this for so long. Rebased and fixed the tests, so if you still want to merge go ahead!

@amueller
Copy link
Member

amueller commented Oct 5, 2016

lgtm. @tguillemot ?

@amueller
Copy link
Member

@tguillemot good to merge?

@tguillemot
Copy link
Contributor

LGTM. Sorry for the delay.

@TomDLT TomDLT merged commit 379f54b into scikit-learn:master Oct 26, 2016
@TomDLT
Copy link
Member

TomDLT commented Oct 26, 2016

Thanks @kwohlfahrt

sergeyf pushed a commit to sergeyf/scikit-learn that referenced this pull request Feb 28, 2017
* DOC correct docstring for sample_gaussian

Docstring did not match function behaviour. Caused some trouble trying to implement a compatible version for a different distribution.

* MAINT Use _sample_gaussian internally

This avoids triggering the deprecation warning. sample_gaussian is just a thin
wrapper.

* Fix _sample_gaussian test path

_sample_gaussian is not publicly exported in mixture, so use gmm module.
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
* DOC correct docstring for sample_gaussian

Docstring did not match function behaviour. Caused some trouble trying to implement a compatible version for a different distribution.

* MAINT Use _sample_gaussian internally

This avoids triggering the deprecation warning. sample_gaussian is just a thin
wrapper.

* Fix _sample_gaussian test path

_sample_gaussian is not publicly exported in mixture, so use gmm module.
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
* DOC correct docstring for sample_gaussian

Docstring did not match function behaviour. Caused some trouble trying to implement a compatible version for a different distribution.

* MAINT Use _sample_gaussian internally

This avoids triggering the deprecation warning. sample_gaussian is just a thin
wrapper.

* Fix _sample_gaussian test path

_sample_gaussian is not publicly exported in mixture, so use gmm module.
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
* DOC correct docstring for sample_gaussian

Docstring did not match function behaviour. Caused some trouble trying to implement a compatible version for a different distribution.

* MAINT Use _sample_gaussian internally

This avoids triggering the deprecation warning. sample_gaussian is just a thin
wrapper.

* Fix _sample_gaussian test path

_sample_gaussian is not publicly exported in mixture, so use gmm module.
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.

None yet

5 participants