Skip to content

Loglikelihood fix#57

Open
osh wants to merge 2 commits into
pykalman:mainfrom
osh:loglikelihood-fix
Open

Loglikelihood fix#57
osh wants to merge 2 commits into
pykalman:mainfrom
osh:loglikelihood-fix

Conversation

@osh

@osh osh commented Sep 27, 2016

Copy link
Copy Markdown

adding a new accessor for likelihoods on top of davmre's fix -

@tingiskhan

Copy link
Copy Markdown
Contributor

@fkiraly This was the issue (which is a PR) I mentioned in our discussion in skpro!

@fkiraly

fkiraly commented Jul 9, 2025

Copy link
Copy Markdown
Collaborator

I see - @tingiskhan, should we merge this?

@tingiskhan

Copy link
Copy Markdown
Contributor

I see - @tingiskhan, should we merge this?

I could test if this is still and issue first!

@tingiskhan

tingiskhan commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

I can confirm that the below script works, so I think we can close this issue now.

The problem I had was that I couldn't setup my own optimization problem since the log-likelihood evaluation would fail, but it seems as though that has been remedied.

import pykalman as pk
from scipy.optimize import minimize
from scipy.special import expit as sigmoid
import numpy as np


def fun(params, y_):
    phi = sigmoid(params[0])
    sigma = np.exp(params[1])

    f = pk.KalmanFilter(
        transition_matrices=phi,
        transition_covariance=sigma,
        observation_offsets=0.1 ** 2.0
    )

    return -f.loglikelihood(y_)


f = pk.KalmanFilter(
    transition_matrices=0.98,
    transition_covariance=0.05 ** 2.0,
    observation_covariance=0.1 ** 2.0
)

_, y = f.sample(500)

y[[10, 25, 100], 0] = np.nan
x0 = np.array([0.5, 0.1 ** 2.0])
res = minimize(fun, x0=x0, args=(y,))

print(res)
print(sigmoid(res.x[0]), np.exp(res.x[1] / 2.0))

@fkiraly

fkiraly commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

should we add a test perhaps?

@tingiskhan

Copy link
Copy Markdown
Contributor

should we add a test perhaps?

Makes sense, I could convert this to a case.

@tingiskhan

tingiskhan commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

should we add a test perhaps?

I now see that there are tests that explicitly call loglikelihood, so I think that additional tests might be superfluous?

@fkiraly

fkiraly commented Dec 31, 2025

Copy link
Copy Markdown
Collaborator

@tingiskhan, @osh, what do we do about this PR?

@tingiskhan

Copy link
Copy Markdown
Contributor

We could add the snippet I sent in an earlier post as a test? Could fix this today I think

@fkiraly

fkiraly commented Jan 1, 2026

Copy link
Copy Markdown
Collaborator

@tingiskhan, that would be great!

fkiraly pushed a commit that referenced this pull request Jan 18, 2026
Adds test discussed in #57.
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.

4 participants