> What's happening is this: the "start time" and the "duration" are effectively quantized with units of weeks. They are defined as continuous variables, but whether the value of the start time is 2.1 or 2.9 or 2.99 makes no difference: all of these define the start time to be in "week 2". This makes it easy for the system to get trapped in a local likelihood maximum and unable to find the global one.
In general, that approach shouldn't work. The assumption built into
Stan's algorithms is that the log density function is continuously
differentiable. By hacking in discrete variables the way you do, you break
that property.
The only thing that'll work well in Stan is marginalizing out the
discrete parameter. As we discussed when you're in town, this can be
combinatorially prohibitive. If it is, then you're just out of luck with
the model as formulated in Stan. Andrew or others may have ways to reformulate
to get the same effect, but I don't have any ideas.
Perhaps --- I'd ask them. I have a hard time imagining Michael
would've recommended this kind of discontinuous approach since
he's been arguing we take out the means to do it from the language
altogether (conditioning on parameters).
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I don't remember ever talking about discrete parameters or associated mixtures. We were talking about time series with multiple time components identified by priors. For example,f(t) = A1 sin(t / T1) + A2 sin(t / T2) + A3 sin(t / T3);T1 ~ normal(0, 20 minutes);T2 ~ normal(1 hour, 5 minutes);T3 ~ normal(1 day, 2 hours);In particular you were talking about boxcar-like effects that could turn on or off for different periods, which could be modeled with a continuous start time (perhaps guided towards certain times of the day by priors) and a continuous duration (identified into time scales by priors like above).
But at no point were we talking about trying to turn the components on or off -- you just assume that they always there and if the data don't need them then they'll be pushed towards zero and have minimum effect on the fit.
Hmm, there are a couple of ways I can thinking of hacking this (or maybe "solving" rather than "hacking" if we can consider these changes as representing a true underlying model):1. Continuous-time parameter, continuous-time data: Allow these weekly effects to start and end midweek. For example, suppose that the "start time" is 2.39, which corresponds, say, to 8:14pm on Tuesday. Then the change would start at that time. With fake data, you could actually do this by picking the start time from some distribution and then starting things at whatever continuous time comes out. With real data, if things actually only start at the beginning of each week, you might still be able to fit this model because the slop and uncertainty would allow a continuous fit. Sure, it wouldn't be quite correct, but you already have enough noise that you're not always identifying the start and end _weeks_, so would it really be so horrible to allow continuous times?
2. Continuous-time parameter, discrete-time data: Again allow a continuous time for the start and end parameters. But now match them to discrete weekly start and end via an S-curve. For example, let's label the discrete points as integers. Then if the continuous start parameter is x, the discrete starting point could be the integer closest to x + epsilon, where epsilon is a distribution such as a logistic or normal with center 0 and scale sigma, and sigma has some value such as 0.5 or 1: this corresponds to an ordered logit or probit. The idea is that sigma will be small enough that the start time parameter roughly localizes the actual start time, but large enough that the transition from one integer to the next is smooth, so there's no near-discontinuity that would jar the HMC. You could implement this model with latent epsilon but I think it would probably work better to use the normal and logistic cdfs. (In theory these go off to infinity but I'd just truncate to the nearest 3 or 4 discrete possibilities for the likelihood.) Once you've fit the model, you can then, in the generated quantities block, use simple Bayes calculation to get inference for the epsilons and thus identify the actual starting and end points more precisely.
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
I don't see why a mixture would be needed. Why not just model it all directly?
On Dec 2, 2016, at 1:26 PM, Andrew Gelman <gel...@stat.columbia.edu> wrote:Why not just let duration be a continuous parameter?
On Dec 9, 2016, at 7:56 PM, Phil Price <pnp...@creekcats.com> wrote:
In my implementation, which I have posted, duration is a continuous parameter (so is start time and end time). This is your #1. This is already the way I do it. I'm not sure how many different ways I can say it.Let me try it this way: Your solution #1 does not work.As for #2...as I understand it, in order for this to work we need a function so steep that the smallest "continuous" change, at computer's precision, corresponds to an integer change in the parameter. Right?That does seem like it might give the behavior I want, if it works at all. But then why not make this part of the language? It seems just incredibly kluldgy and fragile and machine-dependent and lots of other bad things.I guess I should try it. I have to say, I'm pretty demoralized. It might be possible to trick Stan into fitting this model, but a lot of the appeal was the ability to write a model that expresses what I think is actually happening, and then fit it. If, instead, I'm going to have to find some delicately balanced model to trick Stan into fitting a type of model it's designed not to be able to fit, I sort of don't see the point.
--
On Dec 9, 2016, at 7:08 PM, Andrew Gelman <gel...@stat.columbia.edu> wrote:PYes, I understand your general concern. I think the way Bob or Michael might put it is that purely discrete problems are essentially uncomputable because of the combinatorial explosion. So this leaves you with a few options:1. Set up the problem exactly as you did, accept the combinatorial explosion, and aim to get a reasonable solution, or some set of reasonable solutions. This is an approximate-Bayes problem, and it represents an important general class of approximate-Bayes problems, and it's the sort of thing that Stan _should_ be able to do, but Stan can't yet do it. So far with Stan we've focused on full Bayes, with approx algorithms as an afterthought. But the machine learning world is the opposite: they're mainly focused on approximate algorithms. Those sorts of programs can require a bit of tuning, but this can be worth it if you can get good solutions. Currently the machine learning programs seem to be focused on specific models. It would be an interesting thing for someone to build out Stan to be able to attack this sort of problem.
2. Back to my solution #1, which does not work. Does it fail even if you simulate fake data with continuous parameters? (As I wrote, "For example, suppose that the "start time" is 2.39, which corresponds, say, to 8:14pm on Tuesday. Then the change would start at that time. With fake data, you could actually do this by picking the start time from some distribution and then starting things at whatever continuous time comes out.") I guess I'm still missing something here. Yes, I understand that you are coding all these as continuous, but it also sounds like you're creating your data in such a way that the underlying parameters are discrete. If you could have things start at 8:14pm on Tuesday, then wouldn't you be able to recover such things?
In this case, in the continuous world Stan doesn’t force me to exhaustively sample all of continuous parameter space (something that can’t be done anyway, obviously!); by design, it spends most of its time in the high-probability regions of parameter space, and nearly none of its time where the probability is very very low. I would like to have the same capability in discrete space: hop around between discrete states, and spend most of its time where the probability is high
On Dec 10, 2016, at 3:06 PM, Phillip Price <pnp...@creekcats.com> wrote:On Dec 9, 2016, at 7:08 PM, Andrew Gelman <gel...@stat.columbia.edu> wrote:PYes, I understand your general concern. I think the way Bob or Michael might put it is that purely discrete problems are essentially uncomputable because of the combinatorial explosion. So this leaves you with a few options:1. Set up the problem exactly as you did, accept the combinatorial explosion, and aim to get a reasonable solution, or some set of reasonable solutions. This is an approximate-Bayes problem, and it represents an important general class of approximate-Bayes problems, and it's the sort of thing that Stan _should_ be able to do, but Stan can't yet do it. So far with Stan we've focused on full Bayes, with approx algorithms as an afterthought. But the machine learning world is the opposite: they're mainly focused on approximate algorithms. Those sorts of programs can require a bit of tuning, but this can be worth it if you can get good solutions. Currently the machine learning programs seem to be focused on specific models. It would be an interesting thing for someone to build out Stan to be able to attack this sort of problem.I understand about the combinatorial explosion, but this is still a slightly unsatisfying situation. When a human looks at a time series that, starting on the 9th week, shows a 2-hour spike every Tuesday afternoon for the next 8 weeks, it’s easy to see what is happening. A computer can analyze chess moves a zillion times faster than me, so how come it’s paralyzed by the combinatorial explosion in this case and I’m not? The answer, of course, is I’m not laboriously working through every single possibility. But why not?
Or think about some sort of modified traveling salesman problem, where I have some sort of noisy information on the total distance the salesman drove — maybe I know how much gas he used in his car. Let’s say he visits the 20 biggest cities in the U.S. and my estimate is that he drove 10% farther than the shortest possible route, plus or minus 8%, but no shorter than the shortest possible route of course. 99.99999% of possible routes are going to be a lot longer than that and will have probability very close to zero. Is exhaustively exploring all of the routes really the best we can do? Clearly not.
I understand Stan is built for a certain kind of model, and is just not the right tools for these kinds of jobs. But, as with your “R sucks” blog post, the fact that Stan is great at what it does seems to amplify my frustration when it won’t do this other thing I want it to do.In this case, in the continuous world Stan doesn’t force me to exhaustively sample all of continuous parameter space (something that can’t be done anyway, obviously!); by design, it spends most of its time in the high-probability regions of parameter space, and nearly none of its time where the probability is very very low. I would like to have the same capability in discrete space: hop around between discrete states, and spend most of its time where the probability is high.
2. Back to my solution #1, which does not work. Does it fail even if you simulate fake data with continuous parameters? (As I wrote, "For example, suppose that the "start time" is 2.39, which corresponds, say, to 8:14pm on Tuesday. Then the change would start at that time. With fake data, you could actually do this by picking the start time from some distribution and then starting things at whatever continuous time comes out.") I guess I'm still missing something here. Yes, I understand that you are coding all these as continuous, but it also sounds like you're creating your data in such a way that the underlying parameters are discrete. If you could have things start at 8:14pm on Tuesday, then wouldn't you be able to recover such things?Good question…I was thinking about this yesterday while exercising — it really is true that mulling things over while “not working” can be the best way to work — and I think this approach will work, just not as I implemented it. As with some of those morphing issues we never quite worked out, there might be a way to make this work as a fully continuous problem. After all, the actual electric load in the building really is a continuous function of time, even though it only gets measured every 15 minutes.This is going to be somewhat complicated, though, or at least I think so….Complicated to conceptualize and program, not necessarily to fit. The issue is that there really are these discrete events, some of which recur daily and some weekly, and some only for limited duration, and they can overlap. But yeah, I can have weekly-recurring event 1 start at some time t1_0 and end at t1_1, and so on for other events, and since those times won’t match up to the meter times I’ll just do some interpolation at the ends… it all sounds workable, although I will have to be careful in order to define a fully specified model.
