Skip to content

Make performance linear #1

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

Closed
idontgetoutmuch opened this issue Jan 3, 2017 · 4 comments
Closed

Make performance linear #1

idontgetoutmuch opened this issue Jan 3, 2017 · 4 comments
Assignees

Comments

@idontgetoutmuch
Copy link

idontgetoutmuch commented Jan 3, 2017

Since I just did this, I thought I would share it with you.

transformed parameters {
  vector[N] log_p;
  {
    vector[N+1] log_p_e;
    vector[N+1] log_p_l;
    log_p_e[1] = 0;
    log_p_l[1] = 0;
    for (i in 1:N) {
      log_p_e[i + 1] = log_p_e[i] + normal_lpdf(D[i] | mu1, sigma1);
      log_p_l[i + 1] = log_p_l[i] + normal_lpdf(D[i] | mu2, sigma2);
    }
    log_p = rep_vector(-log(N) + log_p_l[N + 1], N) + head(log_p_e, N) - head(log_p_l, N);
  }
}
@gmodena gmodena self-assigned this Mar 19, 2017
@gmodena
Copy link
Owner

gmodena commented Mar 19, 2017

Hi @idontgetoutmuch,
thanks for the contribution. I incorporated your suggestion in the model, and updated the article.

@josswright
Copy link

I've been trying to wrap my head around this. I'm not sure I've quite understood it.

My main interest is whether this could be generalised to an arbitrary number of changepoints.

@idontgetoutmuch
Copy link
Author

I am not sure what your model is but you could certainly have two changepoints but I suspect performance will take a hit. I am not sure how to model an arbitrary number of changepoints. I've used a hidden markov model successfully to model a process moving between a finite set of states. Stan can then be used to infer the transition and observation matrices (functions) but I don't know if that is what you want. I suggest asking on https://discourse.mc-stan.org. There are some very knowledgeable and helpful folks there :)

@josswright
Copy link

Thank you! I've just put up a post there.

It was the specifics of the dynamic programming approach that I was wondering about. As I haven't quite got my head around what the code snippet in the first post is doing, I wasn't sure whether it would be possible to extend that approach to, say, two or three changepoints.

I've got the default "slow" method from the Stan user guide just about working, but given the slowdown associated with multiple changepoints in the first place, I was really hoping that I might be able to take advantage of a similar dynamic programming trick.

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

No branches or pull requests

3 participants