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

Journey Through `tyecon`: Predictions on Recipe Nutritions

Introduction In this second part of the “journey through tyecon” series, I want to showcase the package’s facilities in simplifying tasks common to the predictive modelling part of data analysis. I will be using the Food.com dataset as before. Setup and Data Import library(tidyverse) library(tidyselect) library(magrittr) library(vroom) library(tyecon) library(rsample) library(yardstick) library(glmnet) library(earth) library(pls) knitr::opts_chunk$set(fig.path = "") knitr::opts_chunk$set(dev = 'svg') theme_set(theme_light()) set.seed(123) recipes <- vroom("~/Workspace/foodrecipes/RAW_recipes.csv") interacts <- vroom("~/Workspace/foodrecipes/RAW_interactions.csv") Nutrition values, except for calories, are all percent of daily value, a daily quota filled by the amount of the percentage by the consumption of the specific food....

02.07.2022

Journey Through `tyecon`: Exploring Food.com Tags

Introduction I’ve been working on my R package, tyecon for some time now. I think it can be a useful tool in performing day to day data analysis tasks. The idea is very simple: More higher order macros. There’s no reason to focus on the handful of existing ones, like the magrittr pipes or the dplyr syntax. We have a language here that supports lazy evaluation and first class functions. This is all we need to make programming life easier....

01.06.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

Upcoming Blog Posts

Frustrations and Fixes for Julia Series Cumbersome globals, bug-inducing as well (Ricatti solver issue) Terrible pipe operator weird choice of having map take function first then data, even though map is a data function itself. This causes issues with the pipe operator idea as well. Column-major vs row-major Need good internet for adding packages (can’t use it effectively when outside of town) Poor but understandable reshaping of vectors of vectors into matrices (especially for multidimensional arrays) Unnamed vectors, no annotations possible returning multiple values from map in consistent way....