This repository contains the R package for the Robust Gauss-Newton (RGN) algorithm, which is designed for solving optimization problems with a sum of least squares objective function.
This R implementation is developed by David McInerney and Michael Leonard, and is based on original RGN Fortran code developed by Youwei Qin, Dmitri Kavetski and George Kuczera (https://github.com/eachonly/Robust-Gauss-Newton-Algorithm/).
When using RGN please cite the following articles:
Qin Y, Kavetski D, Kuczera G (2018) A robust Gauss-Newton algorithm for the optimization of hydrological models: From standard Gauss-Newton to robust Gauss-Newton. Water Resources Research, 54. https://doi.org/10.1029/2017WR022488
Qin Y, Kavetski D, Kuczera G (2018) A robust Gauss-Newton algorithm for the optimization of hydrological models: Benchmarking against industry-standard algorithms. Water Resources Research, 54. https://doi.org/10.1029/2017WR022489
You can install the development version of RGN from GitHub with:
# install.packages("devtools")
::install_github("ClimateAnalytics/RGN") devtools
The first example is optimisation of a 2D Rosenbrock function:
library(RGN)
# Example 1: Rosenbrock
=function(x) c(1.0-x[1],10.0*(x[2]-x[1]**2))
simFunc_rosenbrock= rgn(simFunc=simFunc_rosenbrock,
rgnOut par=c(-1.0, 0.0), lower=c(-1.5, -1.0), upper=c( 1.5, 3.0),
simTarget=c(0,0))
$par #optimal parameters
rgnOut#> [1] 1 1
$value #optimal objective function value
rgnOut#> [1] 0
The second example is calibration of the 5 parameter hydrological model HYMOD:
library(RGN)
# Example 2: Hymod
data("BassRiver") # load Bass River hydrological data
= rgn(simFunc=simFunc_hymod,
rgnOut par=c(400.,0.5,0.1,0.2,0.1),
lower=c(1.,0.1,0.05,0.000001,0.000001),
upper=c(1000.,2.,0.95,0.99999,0.99999),
simTarget=BassRiverData$Runoff.mm.day[365:length(BassRiverData$Date)],
stateVal=c(100.0,30.0,27.0,25.0,30.0,0.0,0.0,0.0), # initial states for hymod
nWarmUp=365, # warmup period
rain=BassRiverData$Rain.mm, # precip input
pet=BassRiverData$ET.mm) # PET input
$par #optimal parameters
rgnOut#> [1] 146.7563960 0.3635988 0.1895957 0.9999900 0.7430698
$value #optimal objective function value
rgnOut#> [1] 6840.165