Skip to contents

R package that provides unconstrained nonlinear optimization through a modern C++17 reimplementation of the classic Fortran-based ucminf algorithm. It is a drop-in replacement for ucminf::ucminf().

The reimplementation of the C++ library offers multi-language support: Python and Julia bindings are available. ## Features

  • Drop-in replacement for the original ucminf::ucminf() function.
  • Modern C++17 implementation, enabling easier extension and integration.
  • Multi-language support – use the same algorithm in R, Python, and Julia.
  • Efficient and robust – retains the numerical properties of the original Fortran code.
  • Easy installation – no Fortran compiler required.

Installation

Install the latest development version from GitHub:

# Install directly from GitHub
devtools::install_github("alrobles/ucminfcpp")

Basic Example

The example below optimises Rosenbrock’s Banana Function and confirms that ucminfcpp and ucminf produce identical results.

# Rosenbrock's Banana Function
banana <- function(x) {
  100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2
}

# Initial point
starting_point <- c(-1.2, 1)

# Optimization with ucminfcpp
result_cpp <- ucminfcpp::ucminf(starting_point, banana)
cat("ucminfcpp result:\n")
print(result_cpp$par)

# Optimization with ucminf
result_fortran <- ucminf::ucminf(starting_point, banana)
cat("ucminf result:\n")
print(result_fortran$par)

# Check similarity
identical_result <- all.equal(result_cpp$par, result_fortran$par)
cat("Are the results the same? ", identical_result, "\n")

Overview

ucminfcpp provides the ucminf() function for general-purpose unconstrained nonlinear optimization. The algorithm is a quasi-Newton method with BFGS updating of the inverse Hessian and a soft line search with adaptive trust-region radius monitoring.

It is designed as a drop-in replacement for the original Fortran-based ucminf ucminf::ucminf() function. The original algorithm was written in Fortran by Hans Bruun Nielsen.

Complete Credit

This reimplementation is based on the original repository ucminf.

The implementation and techniques are derived from the original Fortran-based algorithm described by: Nielsen, H. B. (2000) UCMINF - An Algorithm For Unconstrained, Nonlinear Optimization, Report IMM-REP-2000-19, Department of Mathematical Modelling, Technical University of Denmark.

  • You can consult this document here,

  • The original Fortran source code is archived here.

Dr. Nielsen passed away in 2015; the code was later modified for integration with R packages. The structure of ucminf in R draws from the FortranCallsR package by Diethelm Wuertz. Dr. Wuertz passed away in 2016