Short Comparison of Julia Optimization Frameworks

Introduction This is a short comparison of the mathematical optimization facilities of the Julia language, where I compare JuMP.jl, Optim.jl, and Optimization.jl libraries. using JuMP using Optim using Optimization using OptimizationOptimJL using OptimizationNLopt using BenchmarkTools import Ipopt import NLopt # Booth function. The three frameworks require different specifications. booth(x1, x2) = (x1 + 2x2 - 7)^2 + (2x1 + x2 -5)^2 booth_vector(x) = (x[1] + 2x[2] - 7)^2 + (2x[1] + x[2] -5)^2 booth_parameters(x, p) = (x[1] + 2x[2] - 7)^2 + (2x[1] + x[2] -5)^2; JuMP....

05.08.2022

dplyr Cheatsheet to DataFrames.jl Page 2

Continuing Where We Left This post shows how to translate the second page of the dplyr cheatsheet to DataFrames.jl and Julia commnads. using RDatasets, RCall, DataFrames, StatsBase, Statistics R"library(tidyverse)"; Setting up the data using RCall mpg = dataset("ggplot2", "mpg"); Vectorized Functions lag, lead julia> R""" mutate(mpg, leadyear = lead(year)) %>% select(year, leadyear) %>% tail """ RObject{VecSxp} # A tibble: 6 x 2 year leadyear <int> <int> 1 1999 2008 2 2008 2008 3 2008 1999 4 1999 1999 5 1999 2008 6 2008 NA In Julia:...

13.11.2021

dplyr Cheatsheet to DataFrames.jl Page 1

Introduction With the release of v1.0 of the DataFrames.jl package, it would seem appropriate to introduce a rather comprehensive cheatsheet of it. One that is of special use to people who come from tidyverse (arguably, the best data transformation syntax there is for combined expressiveness and brevity). The order of topics is the same as dplyr cheatsheet. using RDatasets, RCall, DataFrames, StatsBase, InteractiveErrors R"library(dplyr)"; Setting up the data using RCall data = dataset("datasets", "iris") @rput data; Summarize Cases summarize julia> R"summarize(data, avSL = mean(SepalLength), avSW = mean(SepalWidth))" RObject{VecSxp} avSL avSW 1 5....

02.11.2021

Julia Frustrations and Fixes Part III: Do-While Loops

Simple Iterations The goal is to solve the below expression iteratively for f(x): $$ f(x) = β\left(f(x)+x\right) $$ Of course, we know what the answer is already, for comparison: β = 0.8 f(x) = 1/(1-β)*β*x x = 0.1:0.1:10; The original way Using a while loop can be ugly, since there isn’t a do-while syntax in Julia. One needs to specify a true case first and check convergence later: fcomp, iter = let v_ = zeros(length(x)), i = 0 while true v = β*(v_+x) i=i+1 maximum(abs....

10.07.2021

Julia Frustrations and Fixes Part II: Clearing Variables

Main Issue Variables kept from previous runs of a script can be the culprit behind all sorts of bugs when developing from the REPL. Consider this simple case: Simple example Let’s say I define y somewhere in the code: y = 50 50 Now I define another function that really is supposed to just sum two values, but I forgot to also change the name of the second variable in the function call:...

09.07.2021

Julia Frustrations and Fixes Part I: REPL Errors

Main issue An issue with the REPL workflow is that When sending a script (or any chunks) to the REPL, lines that produce error simply output that error and the REPL simply continues to execute the following lines. This can be quite problematic since we may not know why something isn’t working. Consider this example: Error output y = 5 y = y^x # ERROR: UndefVarError: x not defined ERROR: UndefVarError: x not defined map(x->x, 1:100) 100-element Vector{Int64}: 1 2 3 4 5 6 7 8 9 10 ⋮ 92 93 94 95 96 97 98 99 100 z = y 5 Interactive errors The way to solve this issue is to use the InteractiveErrors package, which halts the REPL until further action is taken:...

07.07.2021