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

Make performance linear #1

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 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 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

@josswright josswright commented Mar 11, 2020

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

@idontgetoutmuch idontgetoutmuch commented Mar 11, 2020

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

@josswright josswright commented Mar 11, 2020

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.