MyNixOS website logo
Description

Mixed Variable Optimization.

Mixed variable optimization for non-linear functions. Can optimize function whose inputs are a combination of continuous, ordered, and unordered variables.

mixopt

codecov R-CMD-check

An R package for mixed variable nonlinear optimization

The goal of mixopt is to optimize nonlinear functions that have mixed variable inputs. Both local and global optimization are available.

Installation

You can install the development version of mixopt from GitHub with:

# install.packages("devtools")
devtools::install_github("CollinErickson/mixopt")

Examples

Load the package with the following:

library(mixopt)

Example: coordinate descent for local minimization

Suppose you have a function, called f2, that takes in two arguments. The first is a continuous numeric value between 2 and 8. The second is a discrete factor that can on the values ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, or ‘f’.

The six lines shown below are how the function varies when varying the first parameter while leaving the second at one of the levels, as indicated in the legend.

To run coordinate descent on this function, we will use mixopt_coorddesc and need to specify the possible values for the inputs. To specify a continuous variable from 2 to 8, we use mopar_cts(2,8). To specify our discrete variable, we can use mopar_unordered("a", "b", "c", "d", "e", "f"). For this function, unordered means that there is no ordering over the six factor options.

We call the function as follows. Note that we have to put our parameter ranges/values in a list and pass it in to par, and the function gets passed in to the argument fn.

# Run the optimizer
out <- mixopt_coorddesc(
  par=list(
    mopar_cts(2,8),
    mopar_unordered(letters[1:6])
  ),
  fn=f2,
  verbose=0
)

# Print the result
# par is the parameter values
# val is the function value at the minimum
out
#> $par
#> $par[[1]]
#> [1] 5.5
#> 
#> $par[[2]]
#> [1] "d"
#> 
#> 
#> $val
#> [1] 1
#> 
#> $counts
#> function gradient 
#>       26       NA 
#> 
#> $runtime
#> Time difference of 0.002993107 secs

The output from the optimizer tells the value, the parameter values, the number of function evaluations made, and the time it took.

The large dot shows where the optimizer ends when using mixopt_coorddesc. On this problem, it is very likely to get stuck in a local minimum on the right side since it is doing coordinate descent. We could get better results using a global optimization method.

Metadata

Version

0.1.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows