On Tue, 29 Dec 2015, Allin Cottrell wrote:
In current git I've modified fdjac2 to use a step size as in your
script
(when Richardson is selected). We need to do more testing on this in case it
goes nasty under some conditions
It would seem that the results are somewhat sensitive to the amount of
nonlinearity of the problem: I ran an old script I had which uses matrix
inversion (notoriously differentiable almost everywhere but highly
nonlinear --- especially in the nieighbourhood of singularity).
<hansl>
set echo off
set messages off
function matrix vec22inv(matrix x)
n = round(sqrt(rows(x)))
A = mshape(x,n,n)
return vec(inv(A))'
end function
function matrix grad(matrix x)
n = round(sqrt(rows(x)))
iA = inv(mshape(x,n,n))
return -iA' ** iA
end function
n = 12
k = 1.0e4
a = vec(ones(n,n) - I(n)/k)
ia = vec22inv(a)
ag = grad(a)
printf "\n"
loop i=0..2 --quiet
set fdjac_quality $i
set stopwatch
ng$i = fdjac(a, "vec22inv(a)")
tt = $stopwatch
scalar aae = meanc(abs(vec(ag - ng$i)))
scalar mae = maxc(abs(vec(ag - ng$i)))
scalar are = meanc(abs(1 - vec(ag ./ ng$i)))
scalar mre = maxc(abs(1 - vec(ag ./ ng$i)))
printf "quality = $i\n"
printf "\tAverage and max absolute error = %g, %g\n", aae, mae
printf "\tAverage and max relative error = %g, %g\n", are, mre
printf "\t(cpu time = %g)\n", tt
endloop
</hansl>
This is what I get before and after the patch:
<before>
quality = 0
Average and max absolute error = 53.1382, 11477.9
Average and max relative error = 2.27644e-05, 0.00013658
(cpu time = 0.02)
quality = 1
Average and max absolute error = 0.0163915, 6.19778
Average and max relative error = 7.58353e-09, 1.68055e-07
(cpu time = 0.04)
quality = 2
Average and max absolute error = 0.00128204, 0.149397
Average and max relative error = 1.11463e-09, 2.15128e-07
(cpu time = 0.09)
</before>
<after>
quality = 0
Average and max absolute error = 53.1382, 11477.9
Average and max relative error = 2.27644e-05, 0.00013658
(cpu time = 0.02)
quality = 1
Average and max absolute error = 0.0163915, 6.19778
Average and max relative error = 7.58353e-09, 1.68055e-07
(cpu time = 0.08)
quality = 2
Average and max absolute error = 298.462, 128846
Average and max relative error = 0.000128065, 0.00153573
(cpu time = 0.07)
</after>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------