-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: fix vonmises fit for bad guess of location parameter #18190
Conversation
It doesn't matter much here because terms with
If you can show that the partial derivative of the LL w.r.t.
Update: |
For instance, in the test problem, We can confirm this: from scipy import stats
data = [-0.92923506, -0.32498224, 0.13054989, -0.97252014, 2.79658071,
-0.89110948, 1.22520295, 1.44398065, 2.49163859, 1.50315096,
3.05437696, -2.73126329, -3.06272048, 1.64647173, 1.94509247,
-1.14328023, 0.8499056, 2.36714682, -1.6823179, -0.88359996]
loc = -0.5 * np.pi
stats.vonmises.nnlf((1, loc, 1), data) # 43.06642193588772
stats.vonmises.nnlf((.1, loc, 1), data) # 36.96656945662016
stats.vonmises.nnlf((1e-300, loc, 1), data) # 36.75754132818691 Indeed, the negative log-likelihood (NLLF, erroneously denoted You can apply this reasoning whenever It looks like So rather than a Please check me on all this! Too many sign changes. |
* main: (52 commits) ENH: stats.vonmises.fit: treat case in which location likelihood equation has no solution(scipy#18190) MAINT: stats.kendalltau: avoid overflow (scipy#18193) DOC: Optimize: Fix for side bar rendering on top of Hessian (scipy#18189) MAINT: optimize.linprog: fix bound checks for integrality > 1 (scipy#18160) MAINT: Windows distutils cdist/pdist shims (scipy#18169) BUG: interpolate: add x-y length validation for `make_smoothing_spline`. (scipy#18188) ENH: Added `_sf` method for anglit distribution (scipy#17832) (scipy#18178) DOC: Fixed missing curly bracket in scipy.css DOC: Improving wording and docs for legacy directive DOC: Move legacy directive to not be first in the file DOC: Legacy directive custom styling DOC: Add optional argument to Legacy directive DOC: Ignore legacy directive in refguide_check DOC: Documenting the usage of the legacy directive DOC: Add legacy directive for documentation MAINT: stats.ecdf: store number at risk just before events (scipy#18187) DOC: cite pip issue about multiple `--config-settings` (scipy#18174) DOC: update links for ARPACK to point to ARPACK-NG (scipy#18173) MAINT: stats.logistic.fit: simplify MAINT: optimize.root_scalar: return gracefully when callable returns NaN (scipy#18172) ...
@dschmitz89 As mentioned in another ticket, a few small notes about 1/ The MLE tries to solve 2/ One can shown 3/ The code avoids |
@fancidev : The bounds for the root finding problem are a nice finding. PR very much welcome :). Just be aware that for values larger than the current right end of the bracket, About the As the distribution infrastructure is being overhauled at the moment, I would like to leave that as it is at the moment. The new infrastructure might make it easier to dispatch to another distribution if it arises as a special case of one distribution. |
@dschmitz89 Let me make a PR for the bounds. I’ll leave the I’ll attempt a separate PR to close gh-18166 as it seems able to fix with a simple fix. |
Reference issue
Follow up of #18128
What does this implement/fix?
For a very bad guess of the location parameter, the maximum likelihood equation of the concentration parameter$\kappa$ does not have a solution. In that case, the maximum likelihood estimate is $\kappa=0$ . No formal proof (see below) but intuitively, if the location does not fit at all, it is better to assume a uniform distribution on the cirlce. This PR catches the Rootfinding error and returns the tiniest floating point value.
Additional information
With the data of the test case and
loc=pi/2
, thekappa
equation does not have a root. See below.Generate the plot
Proof
In #18128 it was mentioned that the partial derivative will of the log likelihood will tell if the MLE is the left end of the parameter range (0) or the right end ($\infty$ ). This result is not unambiguous though as the derivative still depends on $\kappa$ . Or I might be doing a mistake here?
The partial derivative:
$$
\begin{equation}
\frac{\partial logp}{\partial\kappa}(x_1, ..., ,x_n| \mu, \kappa) = \sum_{i=1}^N \underbrace{\cos(x_i-\mu)}{\in [-1, 1]} - \underbrace{\frac{I_0'(\kappa)}{I_0(\kappa)}}{\in [0, 1]}
\end{equation}
$$