Hello,
I am having problems with floating point errors that arise when doing calculations that produce very small numbers. Example:
EXP( utility dmnl[Bus])/(EXP(utility dmnl[Car])+EXP(utility dmnl[Rail])+EXP(utility dmnl[Bus]))
The values for utility dmnl are computed correctly as:
car: -118,66
rail: -120,39
bus: -145,95
If I do the same calculation in MS Excel, I get 0,00000000012% as a result, which seems to be too small for Vensim. How can I work around that?
Any advice is much appreciated!
problems with small numbers
-
- Super Administrator
- Posts: 4605
- Joined: Wed Mar 05, 2003 3:10 am
Re: problems with small numbers
You can try double precision Vensim. The test model I generated runs and generates 1.19461e-012.
- Attachments
-
- demo.mdl
- (1.45 KiB) Downloaded 275 times
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: problems with small numbers
OK and how do I turn double precision on? I am using Vensim DSS 5.10e
-
- Super Administrator
- Posts: 4605
- Joined: Wed Mar 05, 2003 3:10 am
Re: problems with small numbers
You will need to re-install. During installation, there is an option to install double precision instead of the standard single point version.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: problems with small numbers
You can install both versions, and use them interchangeably as needed.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: problems with small numbers
The problem here is that e^a overflows in single precision for a > 30 or 40, as I recall. A simple solution, not requiring double precision, is to normalize your utilities to more tractable values. For example, you might subtract the mean or max utility from each of the individual values. For example:
Mode : bus, car, rail
utility[mode] = -145, -118, -120
max util = VMAX(utility[mode!])
share[mode] = EXP(utility[mode]-max util)/SUM(EXP(utility[mode!]-max util))
Mode : bus, car, rail
utility[mode] = -145, -118, -120
max util = VMAX(utility[mode!])
share[mode] = EXP(utility[mode]-max util)/SUM(EXP(utility[mode!]-max util))
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: problems with small numbers
This seems quite related to numerical problems in estimating LOGIT - models (e.g. logistic regression) and LOGSUMS so maybe some of the links to be found in the following answers on stackoverflow may be of help also:
Avoiding numerical overflow with a logistic loss function
Avoiding numerical overflow with a logistic loss function