On Tue, 31 Jan 2023, Olasehinde Timmy wrote:
> Dear profs.,
>
> Please, I would like to know how to perform a grid search in order to find
> an optimal value for a threshold—for example, the threshold value to choose
> for the inflation rate in an asymmetric model.
A grid search is relatively easy to perform via the "for" variant of
the loop command. However, if you want to find the extremum of a
one-variable function in a specified range, the golden ratio method is
generally faster and more accurate. Here's an example script where the
function to be maximised is f(x) = (1-x) * sqrt(x)
<hansl>
function scalar f(scalar x)
return (1-x) * sqrt(x)
end function
### grid search for a maximum between 0 and 1
mx = -$huge
best = 0
loop for (x = 0; x<=1; x += 0.01)
y = f(x)
if y > mx
mx = y
best = x
endif
endloop
print best mx
### golden ratio method
matrix m = {0, 0, 1}
mx = GSSmax(&m, f(m[1]))
best = m[1]
print best mx
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti@univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------_______________________________________________
Gretl-users mailing list -- gretl-users@gretlml.univpm.it
To unsubscribe send an email to gretl-users-leave@gretlml.univpm.it
Website: https://gretlml.univpm.it/postorius/lists/gretl-users.gretlml.univpm.it/