help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a-b+b != a


From: stn021
Subject: Re: a-b+b != a
Date: Tue, 5 Sep 2017 00:00:25 +0200

Hi all,


thank you for all the input. I guess it might be a good idea to
explain in more detail what the question was about in the first place.


I want to match observed dependent and independent variables with a
non-linear model. So far I found it helpful to test a new version of
the model against a recent one in order to see if it performs better.


For that I create a new version of the program and add some new
feature to it. Then the first step is to set the parameters of the new
model so that it does the same as the previous one and the check if
the results are exactly the same. That way I can check that I did not
mess anything up.

In this case I had the idea to add variable weights that can change
from one iteration to the next. (Normally weights are fixed at the
start of the program and do not change later.)


The obvious first check of the correctness of the code is to set all
the weights to value "one". Then the results should be exactly
identical to the previous version. Only then does it make sense to
change the weights and see if the new model perfoms better than the
previous one.

Comparison gets difficult if the new program produces seemingly
randomly different results because small errors accumulate
differently. Then I cannot be sure if a slightly "better" result is
just coincidence of if the new model is really better.


The errors for a single iteration were in the range around 1e-16. So I
quickly got the idea that the issue of the different results could be
resolved by rounding, say 9 or 12 digits. But that only led to yet
another set of results.

I had forgotten to consider the fact that floating point arithmetic is
basically binary, not decimal. So rounding with 1e+9 or 1e+12 did not
really help. But rounding with 2^20 or more works just fine. Both
models give the same result.

Now I round with 2^45 ( newval = round(2^45*oldval)/2^45 ), that is
approximately 3.5e13 or 13.5 decimal digits. Any more and the
different results are back.

Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]