Page 1 of 1
problems with small numbers
Posted: Mon Dec 01, 2014 1:54 pm
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!
Re: problems with small numbers
Posted: Tue Dec 02, 2014 8:10 am
by Administrator
You can try double precision Vensim. The test model I generated runs and generates 1.19461e-012.
Re: problems with small numbers
Posted: Tue Dec 02, 2014 10:26 am
by janpwolff
OK and how do I turn double precision on? I am using Vensim DSS 5.10e
Re: problems with small numbers
Posted: Tue Dec 02, 2014 11:14 am
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.
Re: problems with small numbers
Posted: Wed Dec 03, 2014 3:26 pm
by tomfid
You can install both versions, and use them interchangeably as needed.
Re: problems with small numbers
Posted: Wed Dec 03, 2014 3:34 pm
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))
Re: problems with small numbers
Posted: Thu Dec 04, 2014 5:25 pm
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