exp() versus e** in utility function

10 views
Skip to first unread message

Bart Jourquin

unread,
Sep 1, 2022, 8:34:29 AMSep 1
to Biogeme
Dear Biogeme users,

This may be a stupid question, but I would like to understand why the results of the model is different between the following two utility functions for which B and DECAY must be estimated:

1) Using e (from math import e)
V1 = ..... + B1 * qty1 * e**(length1 * DECAY1)

2) Using exp (from biogeme.expressions)
V1 = ..... + B1 * qty1 * exp(length1 * DECAY1)

Regards,

Bart

Bierlaire Michel

unread,
Sep 1, 2022, 8:44:26 AMSep 1
to bart.j...@gmail.com, Bierlaire Michel, Biogeme
How different?

In the calculation of derivatives, the operator ** is more complex numerically than the operator exp. Numerical errors may accumulate, and provide different results.

Here is an example:

With beta=0:

p1 = e**beta
p1.getValueAndDerivatives(prepareIds=True)
(1.0, array([0.99999997]), array([[0.99999994]]), array([[0.99999994]]))

p2 = exp(beta)
p2.getValueAndDerivatives(prepareIds=True)
(1.0, array([1.]), array([[1.]]), array([[1.]]))

With beta=5:

p1 = e**beta
p1.getValueAndDerivatives(prepareIds=True)
(148.41313656762816,
array([148.41313206]),
array([[148.41312755]]),
array([[22026.45776805]]))

p2 = exp(beta)
p2.getValueAndDerivatives(prepareIds=True)
(148.4131591025766,
array([148.4131591]),
array([[148.4131591]]),
array([[22026.46579481]]))
> --
> You received this message because you are subscribed to the Google Groups "Biogeme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to biogeme+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/biogeme/73f80d83-522a-4cda-8dce-fe9588851917n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages