problems with small numbers

Use this forum to post Vensim related questions.
Post Reply
janpwolff
Junior Member
Posts: 2
Joined: Mon Dec 01, 2014 1:44 pm
Vensim version: DSS

problems with small numbers

Post by janpwolff »

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!
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: problems with small numbers

Post by Administrator »

You can try double precision Vensim. The test model I generated runs and generates 1.19461e-012.
Attachments
demo.mdl
(1.45 KiB) Downloaded 272 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
janpwolff
Junior Member
Posts: 2
Joined: Mon Dec 01, 2014 1:44 pm
Vensim version: DSS

Re: problems with small numbers

Post by janpwolff »

OK and how do I turn double precision on? I am using Vensim DSS 5.10e
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: problems with small numbers

Post by Administrator »

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
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: problems with small numbers

Post by tomfid »

You can install both versions, and use them interchangeably as needed.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: problems with small numbers

Post by tomfid »

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))
gwr
Senior Member
Posts: 209
Joined: Sun Oct 04, 2009 8:40 pm
Vensim version: DSS

Re: problems with small numbers

Post by gwr »

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