positive_infinity()

44 views
Skip to first unread message

Juan

unread,
Nov 7, 2016, 8:08:26 AM11/7/16
to Stan users mailing list
Hello.
The manual speaks about positive_infinity() but no example is provided.
Could anybody explain how to use it properly.

Thanks.

Daniel Lee

unread,
Nov 7, 2016, 9:11:41 AM11/7/16
to stan-users mailing list
positive_infinity() is a function. It returns the value of \infty.

It really doesn't have much purpose. One place you can use it is in a variable declaration. Suppose you have scale variable, sigma, that's lower bounded by 0. This is how I'd write it:
parameters {
  real<lower = 0> sigma;
}

You could write this, which isn't recommended, but you could still do this:
parameters {
  real<lower = 0, upper = positive_infinity()> sigma;
}

Since Stan is a language, I'm sure there are many other use cases that I haven't thought about.



Daniel



--
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 post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pi

unread,
Nov 7, 2016, 3:24:00 PM11/7/16
to stan-...@googlegroups.com
OK, thanks.
Then it's just a constant containing a number?
Why does Stan use positive_infinity()  and not just positive_infinity without the parenthesis?

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/EjrXpZ08EI8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.

Daniel Lee

unread,
Nov 7, 2016, 3:32:18 PM11/7/16
to stan-users mailing list
positive_infinity is a function. You need to evaluate the function to get the value out of it.

Pi

unread,
Nov 7, 2016, 4:17:44 PM11/7/16
to stan-...@googlegroups.com
I guess it's like  pi() or e().
Why are they defined as functions, and not just a constant containing a number?

Bob Carpenter

unread,
Nov 8, 2016, 10:09:43 AM11/8/16
to stan-...@googlegroups.com
Because users like to declare variables named
pi and e and they'd otherwise be illegal or
they'd mask the built-in values.

The generated C++ will be compiled so as
not to involve a function call at run time. It's
a wonderful language that way (but it's part of
why the compile times are so long with optimization).

- Bob
Reply all
Reply to author
Forward
0 new messages